python - 通过API部署Helm图表的代码示例?

标签 python amazon-web-services kubernetes kubernetes-helm

我正在寻找无需通过CLI调用即可部署Helm图表的任何代码示例。其背后的原因是:

  • 我的公司有一些使用AWS CodePipeline / CodeBuild / CodeDeploy编写的现有管道。他们不希望花费更多的时间来重写所有管道。
  • 我的公司没有计划仅用于部署的其他实例。
  • AWS CodePipeline可以触发Lambda,并且从理论上讲,如果Helm提供Python客户端,我可以编写一些Python代码来完成这项工作。

  • 目前,我从中窃取Lambda函数:

    https://github.com/aws-samples/aws-kube-codesuite

    然而,这并没有提供与Helm相同的级别功能。我们必须提供发行名称系统,模板系统等。换句话说,如果我对 list 进行了较大的更改,则它的功能将很差,并且无法处理首次部署(意味着将 list 部署到空的K8S集群)我们使用Github,尽管不是很相关。

    对于Helm chart的python客户端,我能找到的最好的是pip上列出的pyhelm。但是它没有用于调用部署的示例代码,并且从某些用户组/论坛反馈中,安装过程很麻烦。有人还指出了azure / draft和另一个仓库,但我不知道如何提出一个仅使用Python部署Helm图表的可靠示例。

    请让我知道我想念的地方。谢谢。

    最佳答案

    您可以通过示例和Python3支持找到pyhelm的分支。

    git clone git@github.com:andriisoldatenko/pyhelm.git
    cd pyhelm && python setup.py install
    

    如何使用Pyhelm

    首先,您需要repo_url和图表名称才能下载图表
    from pyhelm.repo import from_repo
    
    chart_path = chart_versions = from_repo('https://kubernetes-charts.storage.googleapis.com/', 'mariadb')
    
    print(chart_path)
    "/tmp/pyhelm-kibwtj8d/mongodb"
    

    现在您可以看到mongodb的图表文件夹:
    In [3]: ls -la /tmp/pyhelm-kibwtj8d/mongodb
    total 40
    drwxr-xr-x  7 andrii  wheel   224 Mar 21 17:26 ./
    drwx------  3 andrii  wheel    96 Mar 21 17:26 ../
    -rwxr-xr-x  1 andrii  wheel     5 Jan  1  1970 .helmignore*
    -rwxr-xr-x  1 andrii  wheel   261 Jan  1  1970 Chart.yaml*
    -rwxr-xr-x  1 andrii  wheel  4394 Jan  1  1970 README.md*
    drwxr-xr-x  8 andrii  wheel   256 Mar 21 17:26 templates/
    

    下一步构建ChartBuilder实例以使用Tiller进行操作:
    from pyhelm.chartbuilder import ChartBuilder
    
    chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})
    
    # than we can get chart meta data etc
    In [9]: chart.get_metadata()
    Out[9]:
    name: "mongodb"
    version: "0.4.0"
    description: "Chart for MongoDB"
    

    安装图表:
    from pyhelm.chartbuilder import ChartBuilder
    from pyhelm.tiller import Tiller
    
    chart = ChartBuilder({'name': 'mongodb', 'source': {'type': 'directory', 'location': '/tmp/pyhelm-kibwtj8d/mongodb'}})
    chart.install_release(chart.get_helm_chart(), dry_run=False, namespace='default')
    
    Out[9]:
    release {
      name: "fallacious-bronco"
      info {
        status {
          code: 6
        }
        first_deployed {
          seconds: 1521647335
          nanos: 746785000
        }
        last_deployed {
          seconds: 1521647335
          nanos: 746785000
        }
        Description: "Dry run complete"
      }
      chart {....
    }
    

    关于python - 通过API部署Helm图表的代码示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49311795/

    相关文章:

    amazon-web-services - 如何使用 HTTP 在 AWS EC2 实例上公开端口 8888

    amazon-web-services - S3 存储桶通知或 CloudWatch 事件规则在对象级别更改时调用 Lambda?

    asp.net-core - Kubernetes:将入口内部 ip 添加到环境

    库伯内斯 RBAC : How to allow exec only to a specific Pod created by Deployment

    python - 是否可以在 python tkcalendar 的日期中嵌入自定义文本

    python - Vaultier 无法用于 docker/ubuntu/debian (Python)

    python - 如何填补元组列表中的空白

    python - IPython + Pandas 中的 Matplotlib : ImportError Symbol not found: _png_create_info_struct

    macos - aws cli 自动缩放命令不会返回到 shell 提示符

    kubernetes - 无法正确创建部署