可以使用 Kubernetes 的 livenessProbe 和 readinessProbe 来限制 Argo CD 应用程序在状态异常时转移到降级状态的时间。在应用程序的 YAML 文件中添加以下配置段:
livenessProbe:
httpGet:
path: /healthz
port:
initialDelaySeconds: 60
periodSeconds: 10
readinessProbe:
httpGet:
path: /healthz
port:
initialDelaySeconds: 60
periodSeconds: 10
其中
应当替换为 Argo CD 应用程序使用的端口号,比如 8080。这样,当应用程序的状态异常时,在 initialDelaySeconds 后会被重启,例如 60 秒后重启,并且 livenessProbe 和 readinessProbe 在每个 periodSeconds 定义的间隔内检测应用程序的状态。这样可以防止 Argo CD 应用程序在出现异常状态直到被手动删除前一直停留在降级状态。
示例:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app
namespace: my-namespace
spec:
destination:
server: https://kubernetes.default.svc
namespace: my-namespace
source:
repoURL: https://github.com/my-org/my-repo.git
targetRevision: HEAD
path: /my-app
project: my-project
syncPolicy:
automated:
selfHeal: true
prune: true
allowEmpty: true
livenessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 60
periodSeconds: 10
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 60
periodSeconds: 10