我正在嘗試使用類似以下的補丁將相同的作業歷史限制應用于許多 CronJobs ,命名為kubeJobHistoryLimit.yml:
apiVersion: batch/v1beta1
kind: CronJob
spec:
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
我的kustomization.yml樣子:
bases:
- ../base
configMapGenerator:
- name: inductions-config
env: config.properties
patches:
- path: kubeJobHistoryLimit.yml
target:
kind: CronJob
patchesStrategicMerge:
- job_specific_patch_1.yml
- job_specific_patch_2.yml
...
resources:
- secrets-uat.yml
在我的 CI 管道的某個時刻,我有:
kubectl --kubeconfig $kubeconfig apply --force -k ./
kubectl版本1.21.9是.
問題是作業歷史限制值似乎沒有被采納。我使用的 K8s 的配置或版本有問題嗎?
uj5u.com熱心網友回復:
使用 kustomize 4.5.2,您撰寫的補丁不適用;它失敗了:
Error: trouble configuring builtin PatchTransformer with config: `
path: kubeJobHistoryLimit.yml
target:
kind: CronJob
`: unable to parse SM or JSON patch from [apiVersion: batch/v1
kind: CronJob
spec:
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
]
這是因為它缺少metadata.name,這是必需的,即使在修補多個物件時它被忽略。如果我將補丁修改為如下所示:
apiVersion: batch/v1
kind: CronJob
metadata:
name: ignored
spec:
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
它似乎作業。
如果我有base/cronjob1.yaml,看起來像:
apiVersion: batch/v1
kind: CronJob
metadata:
name: cronjob1
spec:
failedJobsHistoryLimit: 2
successfulJobsHistoryLimit: 5
jobTemplate:
spec:
template:
spec:
containers:
- command:
- sleep
- 60
image: docker.io/alpine:latest
name: example
schedule: 30 3 * * *
然后使用上面的補丁和overlay/kustomization.yaml這樣的:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
patches:
- path: kubeJobHistoryLimit.yml
target:
kind: CronJob
我看到以下輸出kustomize build overlay:
apiVersion: batch/v1
kind: CronJob
metadata:
name: cronjob2
spec:
failedJobsHistoryLimit: 1
jobTemplate:
spec:
template:
spec:
containers:
- command:
- sleep
- 60
image: docker.io/alpine:latest
name: example
schedule: 30 3 * * *
successfulJobsHistoryLimit: 1
您可以看到這兩個屬性已正確更新。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/485720.html
標籤:Kubernetes kubectl 修补
