'kubectl command to update the sidecar image
Along with the container image in kubernetes, I would like to update the sidecar image as well.
What will be the kubectl command for this process?
Solution 1:[1]
kubernetes have the command set image that allow you to update an image to the expected version
the syntax is
kubectl set image deployment/{deployment-name} {container name}:{image:version}
with a sample it look like
kubectl set image deployment/nginx-deployment nginx=nginx:1.9.1
you can found the documentation of this command here https://kubernetes.io/fr/docs/concepts/workloads/controllers/deployment/#mise-%C3%A0-jour-d-un-d%C3%A9ploiement
Solution 2:[2]
Assumed you have a deployment spec look like this:
...
kind: Deployment
metadata:
name: mydeployment
...
spec:
...
template:
...
spec:
...
containers:
- name: application
image: nginx:1.14.0
...
- name: sidecar
image: busybox:3.15.0
...
kubectl set image deployment mydeployment application=nginx:1.16.0 sidecar=busybox:3.18.0
Solution 3:[3]
Besides what other users advise to use kubectl set image you can also patch your resource (pod, deployment, etc.).
In Kubernetes Patch documentation you have some examples there:
# Update a container's image; spec.containers[*].name is required because it's a merge key
$ kubectl patch pod valid-pod -p '{"spec":{"containers":[{"name":"kubernetes-serve-hostname","image":"new image"}]}}'
# Disable a deployment livenessProbe using a json patch with positional arrays
kubectl patch deployment valid-deployment --type json -p='[{"op": "remove", "path": "/spec/template/spec/containers/0/livenessProbe"}]'
Also you can edit your configuration YAML and apply it.
kubectl apply -f <yamlfile with new image>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jeremy-denis |
| Solution 2 | |
| Solution 3 |
