Tia*_*ong 1 patch kubernetes kubectl
我正在尝试使用如下补丁将相同的作业历史记录限制应用于多个 CronJobs ,名为kubeJobHistoryLimit.yml
:
apiVersion: batch/v1beta1
kind: CronJob
spec:
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
Run Code Online (Sandbox Code Playgroud)
我的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
Run Code Online (Sandbox Code Playgroud)
在我的 CI 管道中的某个时刻,我有:
kubectl --kubeconfig $kubeconfig apply --force -k ./
Run Code Online (Sandbox Code Playgroud)
版本kubectl
是1.21.9
.
问题是工作历史限制值似乎没有被拾取。我使用的 K8s 配置或版本有问题吗?
对于 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
]
Run Code Online (Sandbox Code Playgroud)
这是因为它缺少metadata.name
,这是必需的,即使在修补多个对象时它被忽略。如果我将补丁修改为如下所示:
apiVersion: batch/v1
kind: CronJob
metadata:
name: ignored
spec:
successfulJobsHistoryLimit: 1
failedJobsHistoryLimit: 1
Run Code Online (Sandbox Code Playgroud)
似乎有效。
如果我有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 * * *
Run Code Online (Sandbox Code Playgroud)
然后使用上面的补丁和overlay/kustomization.yaml
这样的:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ../base
patches:
- path: kubeJobHistoryLimit.yml
target:
kind: CronJob
Run Code Online (Sandbox Code Playgroud)
我看到以下输出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
Run Code Online (Sandbox Code Playgroud)
您可以看到这两个属性已正确更新。
归档时间: |
|
查看次数: |
4596 次 |
最近记录: |