配置权限1234567891011121314151617181920212223242526272829303132---kind: ServiceAccountapiVersion: v1metadata: name: deployment-restart namespace: default---apiVersion: rbac.authorization.k8s.io/v1kind: Rolemetadata: name: deployment-restart namespace: defaultrules: - apiGroups: ["apps", "extensions"] resources: ["deployments"] resourceNames: [] verbs: ["get", "patch", "list", "watch"] # list 和 watch 就够用了,如果需要执行 rollout status ,则需要 get patch---# 角色绑定账号apiVersion: rbac.authorization.k8s.io/v1kind: RoleBindingmetadata: name: deployment-restart namespace: defaultroleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: deployment-restartsubjects: - kind: ServiceAccount name: deployment-restart namespace: default 编写 cronjob12345678910111213141516171819202122232425262728apiVersion: batch/v1kind: CronJobmetadata: name: deployment-restart namespace: defaultspec: # 多少秒后清理已完成的job,1.23版本之后可用。 ttlSecondsAfterFinished: 100 concurrencyPolicy: Forbid schedule: '37 14 * * *' # 分时日月周 jobTemplate: spec: backoffLimit: 2 activeDeadlineSeconds: 600 template: spec: serviceAccountName: deployment-restart restartPolicy: Never containers: - name: kubectl # image: bitnami/kubectl:1.30.1 image: registry.cn-hangzhou.aliyuncs.com/iuxt/kubectl:1.30.1 command: - bash - -c - >- kubectl rollout restart deployment/nginx && kubectl rollout status deployment/java-example