3

利用 Kustomize 渲染 Helm Charts 并使用 ArgoCD 进行部署

 1 month ago
source link: https://www.bboy.app/2024/03/18/%E5%88%A9%E7%94%A8-kustomize-%E6%B8%B2%E6%9F%93-helm-charts-%E5%B9%B6%E4%BD%BF%E7%94%A8-argocd-%E8%BF%9B%E8%A1%8C%E9%83%A8%E7%BD%B2/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

利用 Kustomize 渲染 Helm Charts 并使用 ArgoCD 进行部署

March 18, 2024 本文有 465 个字 需要花费 1 分钟阅读
20240318-1.webp

尽管我对 Helm 的使用感到不太满意,但有些时候我们不得不使用它。在这篇文章中,我将介绍一种方法,可以让 Kustomize 和 Helm 配合使用,以解决我对 Helm 的不满。

之前我使用helm部署的时候,首先要拉下整个helm charts,然后修改values.yaml,然后提交,然后部署,这样其实很麻烦,但是Kustomizing是支持直接去渲染Helm charts的,可以看下面文档

https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/helmcharts/

具体的参数可以参考以下链接:

https://kubectl.docs.kubernetes.io/references/kustomize/builtins/#_helmchartinflationgenerator_

然后,在编译时加上 --enable-helm 参数即可。

例如,对于一个项目,如果我想部署一个 Dragonfly,那就变得非常简单了。只需要三个文件,第一个是 kustomization.yaml

helmCharts:
- name: dragonfly
  repo: https://dragonflyoss.github.io/helm-charts/
  version: 1.1.32
  releaseName: dragonfly
  namespace: dragonfly
  valuesFile: values.yaml

然后是 values.yaml 文件,这里就不再展示了。

最后是 argo.yaml

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: 'dragonfly'
spec:
  destination:
    namespace: 'dragonfly'
    server: 'https://xxxxxxxxxxxxxxxxxxx.gr7.us-west-2.eks.amazonaws.com'
  source:
    path: 'dragonfly'
    repoURL: 'https://git.xxxxx.com/kubernetes-app-yaml.git'
    targetRevision: HEAD
  project: 'app'

接下来,在 ArgoCD 上开启 Kustomize 的 Helm 支持。具体的操作可以参考以下链接:

https://argo-cd.readthedocs.io/en/release-2.8/user-guide/kustomize/#kustomizing-helm-charts

实际上,只需要在 argocd-cm 这个 ConfigMap 上添加以下内容:

kustomize.buildOptions: --enable-helm

如果你需要更新你的 charts,只需直接修改 charts 的版本即可。所有的参数都是可以自己控制的,非常方便。

欢迎关注我的博客www.bboy.app

Have Fun


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK