はじめに
KubernetesのCDツールとしてArgoCDを使用しています。
ArgoCDの管理対象(Application)にhelmチャートを指定してみたので、調べた内容をまとめました。
参考:ArgoCD - Declarative Setup クイックリファレンス
動作環境
- Azure Kubernetes Service(AKS)
- ArgoCD v1.1.1
yaml記述例
Applicationにはhelm公式のnginx ingressを使用しています。
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: nginx-ingress
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/helm/charts.git
targetRevision: 0ef8d0d9033417d17d2872f32c97b7f999f9eb8f
path: stable/nginx-ingress
helm:
parameters:
- name: "controller.replicaCount"
value: "2"
releaseName: nginx-ingress
valueFiles:
- https://raw.githubusercontent.com/user/sample/values-nginx.yaml
destination:
server: https://kubernetes.default.svc
namespace: default
syncPolicy:
automated:
prune: true
ignoreDifferences:
- group: ""
kind: Service
jsonPointers:
- /spec/clusterIP
ArgoCDが動作しているクラスタに対し、上記リソースを作成すればApplicationを管理できます。
$ kubectl apply -f argocd-app-nginx-ingress.yaml
設定(spec.source)
repoURL
helmを含むリポジトリのURL。
targetRevision
管理対象リビジョン。HEADやコミットハッシュを指定します。
HEADを指定すれば、リポジトリへのコミット時に自動的にKubernetesリソースを更新します。
path
リポジトリ内のhelmチャートを含むディレクトリパス。
helm
releaseName
helmに指定するリリース名。
parameters
nameで指定したhelmの設定項目をvalueで上書きします。
values.yamlでの設定と同じですが、values.yamlよりも優先されます。
valueFiles
helmに適用するvalues.yamlをURLで指定。
補足
spec.ignoreDifferences
ArgoCDで同期したくない項目を指定します。
kind、groupにはKubernetesリソースの種類を、jsonPointersには対象項目を指定します。
実際はhelm template
内部では以下のようなコマンドを実行してマニフェストを作成しています。
$ helm template -n {helm.releaseName} --set {helm.parameters[0].name}={helm.parameters[0].value}... -f {helm.valueFiles[0]}...