I have a Kubernetes deployment up and running: (some fields omitted for brevity)
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
I would like to create a patch for the existing deployment to add certain arguements to the command
of the container:
- '--insecure'
- '--basehref'
- /argocd
I read the documentation on the kubectl patch
command here, but I am not sure how to actually select the container (by name or index) that I would like to patch.
It would be fine to overwrite the complete command:
list (giving the - argocd-server
line in the patch file) but I would like to prevent giving the complete containers:
spec in the patch file.
CodePudding user response:
You can select the container by index, e.g.:
kubectl patch deployment argocd-server -n argocd --type='json' -p='[{"op": "replace", "path": "/spec/template/spec/containers/0/command", "value": ["argocd-server", "--insecure"]}]'
CodePudding user response:
Thanks to the inspiration by @Blokje5 I was able to construct these two options:
JSON approach
inline
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"]}]'
with patch file
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.json
YAML approach
yaml file
patch.yaml
---
op: replace
spec:
template:
spec:
containers:
- name: argocd-server
command:
- argocd-server
- --insecure
- --basehref
- /argocd
kubectl -n argocd patch deployment argocd-server --patch-file patch.yaml