argocd 同步策略--忽略某个配置同步

参考文档:https://blog.argoproj.io/new-sync-and-diff-strategies-in-argocd-44195d3f8b8c

背景

当我在k8s中用 cronhpa+hpa 实现定时pod扩容的同时还能兼容平时的hpa弹性伸缩。
cronhpa 通过修改 hpa的 minReplicas 与 maxReplicas,从而实现pod的伸缩。但是,当hpa中的配置被cronhpa修改后,argocd会检测到集群中hpa状态与yaml文件中声明的状态不一致 outofsync,从而会还原hpa的配置,cronhpa的定时伸缩就不能达到我们预期的效果了。

image

解决方案

argocd 支持同步时忽略某些配置,首先要声明 RespectIgnoreDifferences=true,使用ignoreDifferences 指明你要忽略的配置。

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: xxx-pre
  namespace: my-argocd
spec:
  destination:
    name: xxx-ack
    namespace: xxx-pre
  project: xxx
  source:
    path: xxx/overlays/pre
    repoURL: 'git@xxxx:xxxx.git'
    targetRevision: main
  ignoreDifferences:
  # group 为该资源的apiVersion斜杠前的那一部分
  - group: autoscaling
    kind: HorizontalPodAutoscaler
    jsonPointers:
    - /spec/minReplicas
  syncPolicy:
    automated: {}
    syncOptions:
    - RespectIgnoreDifferences=true
posted @ 2023-01-03 18:35  huandada  阅读(474)  评论(0编辑  收藏  举报