本文介绍了在 Kubernetes 中如何修补部署中的容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用补丁 API 向容器添加卷(不适用)
I would like to add a volume to a container using the patch API (not apply)
此补丁无效:
spec:
template:
spec:
volumes:
- name: cep-debug-dir
persistentVolumeClaim:
claimName: cep-pvc-debug
containers:
name: cep
- mountPath: /debug
name: cep-debug-dir
volumeMounts:
- mountPath: /debug
name: cep-debug-dir
我的用例是扩展部署 yaml,添加一个用于开发的挂载卷,并且通常具有多态部署,无需重复 yaml 代码,也不必维护两个文件中的更改.
My use case is to extend the deployment yaml adding a mounted volume for development and in general have a polymorphic deployment without repeating yaml code and having to maintain changes in two files.
ps我正在使用配置映射,如果我可以使用 if 有条件地安装卷,那就太酷了.
p.sI'm using config map and if I could use an if to mount the volume conditionally it would bee cool.
推荐答案
我打印了部署 json 并使用/编辑了 json 格式的字段,补丁有效在终端
I printed the deployment json and used / edited the fields in json format and the patch workedIn terminal
kubectl patch deploy cep --patch "$(cat cep-deploy-patch.yaml)"
文件:
{
"spec": {
"template": {
"spec": {
"containers": [{
"name": "cep",
"volumeMounts": [{
"mountPath": "/debug",
"name": "cep-debug-dir"
}]
}],
"volumes": [{
"name": "cep-debug-dir",
"persistentVolumeClaim": {
"claimName": "cep-pvc-debug"
}
}]
}
}
}
}
这篇关于在 Kubernetes 中如何修补部署中的容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!