ArgoCD App-of-Apps模式:确保Strimzi子应用健康后再同步Kafka
问题:ArgoCD App-of-Apps模式下实现Strimzi与Kafka的同步顺序控制
我正采用ArgoCD的App-of-Apps模式部署应用,当前伞形应用包含Strimzi和Kafka两个子应用。由于Kafka所需的CRDs由Strimzi负责安装,必须确保Strimzi子应用完全健康后再同步Kafka应用,否则Kafka同步会因缺少CRDs而失败。
目前我通过手动脚本先同步Strimzi并等待CRDs建立,再同步其他子应用,希望借助ArgoCD的syncPolicy(比如sync-waves)等策略实现自动同步顺序,替代手动操作。请问有哪些具体配置或策略可以实现这一需求?
我的简化部署脚本如下:
NS=argocd argocd login --core kubectl config set-context --current --namespace="$NS" # Create fink app argocd app create fink --dest-server https://kubernetes.default.svc \ --dest-namespace="$NS" \ --repo https://github.com/astrolabsoftware/fink-cd.git \ --path apps --revision="$FINK_CD_WORKBRANCH" \ # Sync fink app-of-apps argocd app sync fink # Sync child apps # Is there a way to remove 5 lines below and keep only the 6th # for example using sync-waves? argocd app sync strimzi while ! kubectl wait --for condition=established --timeout=60s crd/kafkas.kafka.strimzi.io crd/kafkatopics.kafka.strimzi.io do sleep 5 done argocd app sync -l app.kubernetes.io/instance=fink
解决方案
1. 用Sync Waves定义子应用同步顺序
在App-of-Apps的子应用清单(即apps目录下的Strimzi、Kafka应用配置文件)中,通过注解指定同步波数值,数值越小优先级越高:
- 给Strimzi应用设置低数值的sync-wave,确保它先被同步:
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: strimzi annotations: argocd.argoproj.io/sync-wave: "-10" spec: # 你的Strimzi应用原有配置...
- 给Kafka应用设置更高的数值(默认是0),保证在Strimzi之后同步:
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: kafka annotations: argocd.argoproj.io/sync-wave: "0" spec: # 你的Kafka应用原有配置...
2. 给Strimzi配置CRD就绪健康检查
仅靠sync-waves只能保证同步顺序,无法确保Strimzi的CRDs完全建立。需要给Strimzi的Application配置自定义健康检查,让ArgoCD确认CRDs就绪后才标记应用健康:
spec: healthChecks: - name: kafka-crd-check initialDelaySeconds: 10 periodSeconds: 5 timeoutSeconds: 30 kubernetes: resource: group: apiextensions.k8s.io version: v1 kind: CustomResourceDefinition name: kafkas.kafka.strimzi.io statusCondition: type: Established status: "True" - name: kafkatopic-crd-check initialDelaySeconds: 10 periodSeconds: 5 timeoutSeconds: 30 kubernetes: resource: group: apiextensions.k8s.io version: v1 kind: CustomResourceDefinition name: kafkatopics.kafka.strimzi.io statusCondition: type: Established status: "True"
3. 启用伞形应用的自动同步
在伞形应用fink的配置中开启自动同步,让ArgoCD自动按顺序处理子应用:
apiVersion: argoproj.io/v1alpha1 kind: Application metadata: name: fink spec: syncPolicy: automated: prune: true selfHeal: true syncOptions: - RespectIgnoreDifferences=true - ApplyOutOfSyncOnly=true
同时确保子应用的syncPolicy也配置了自动同步,这样伞形应用同步时会自动触发子应用的同步流程。
4. 验证自动化效果
完成上述配置后,只需执行以下命令即可实现全自动化同步:
NS=argocd argocd login --core kubectl config set-context --current --namespace="$NS" # Create fink app argocd app create fink --dest-server https://kubernetes.default.svc \ --dest-namespace="$NS" \ --repo https://github.com/astrolabsoftware/fink-cd.git \ --path apps --revision="$FINK_CD_WORKBRANCH" \ # Sync fink app-of-apps argocd app sync fink
ArgoCD会自动先同步Strimzi,等待其CRDs建立完成并标记为健康后,再同步Kafka等其他子应用,无需手动等待和触发。
内容的提问来源于stack exchange,提问作者Fabrice Jammes
相关产品推荐
相关产品推荐

