gaurav sharma
gaurav sharma

Reputation: 133

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?

Upvotes: 1

Views: 1474

Answers (3)

PjoterS
PjoterS

Reputation: 14084

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>

Upvotes: 1

gohm&#39;c
gohm&#39;c

Reputation: 15480

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

Upvotes: 1

jeremy-denis
jeremy-denis

Reputation: 6878

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

Upvotes: 1

Related Questions