我已经启动并运行了一个Kubernetes部署:(为了简洁起见,有些字段省略了)
apiVersion: apps/v1
kind: Deployment
metadata:
name: argocd-server
namespace: argocd
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: argocd-server
template:
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: argocd-server
spec:
containers:
- name: argocd-server
image: quay.io/argoproj/argocd:v2.2.5
command:
- argocd-server我想为现有的部署创建一个补丁,以便在容器的command中添加某些论证:
- '--insecure'
- '--basehref'
- /argocd我阅读了kubectl patch命令这里上的文档,但不确定如何实际选择要修补的容器(按名称或索引)。
覆盖完整的command:列表(在补丁文件中给出- argocd-server行)是可以的,但是我想防止在补丁文件中给出完整的containers:规范。
发布于 2022-02-22 12:50:18
您可以按索引选择容器,例如:
kubectl patch deployment argocd-server -n argocd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["argocd-server", "--insecure"]}]'发布于 2022-02-22 13:32:18
由于@Blokje5的启发,我能够构建以下两个选项:
JSON方法
内联
kubectl patch deployment argocd-server -n argocd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["argocd-server", "--insecure", "--basehref", "/argocd"]}]'带补丁文件
patch.json
[
{
"op": "replace",
"path": "/spec/template/spec/containers/0/command",
"value": [
"argocd-server",
"--insecure",
"--basehref",
"/argocd"
]
}
]kubectl -n argocd patch deployment argocd-server --type='json' --patch-file patch.jsonYAML方法
yaml文件
patch.yaml
---
op: replace
spec:
template:
spec:
containers:
- name: argocd-server
command:
- argocd-server
- --insecure
- --basehref
- /argocdkubectl -n argocd patch deployment argocd-server --patch-file patch.yamlhttps://stackoverflow.com/questions/71221533
复制相似问题