How to provide name in kubectl set image

9/21/2019

I'm unable to deploy a new image to my service. I'm trying to run this command in my CI environment:

$ kubectl set image deployment/dev2 \
  dev2=gcr.io/at-dev-253223/dev@sha256:3c6bc55e279549a431a9e2a316a5cddc44108d9d439781855a3a8176177630f0

I get unable to find container named "dev2"

I'll upload my registry and pods and services, not sure why I can't just pass the new image.

$ kubectl get pods
NAME                    READY   STATUS    RESTARTS   AGE
dev2-6fdf8d4fb5-hnrnv   1/1     Running   0          7h19m

$ kubectl get service
NAME         TYPE           CLUSTER-IP     EXTERNAL-IP    PORT(S)        AGE
dev2         LoadBalancer   hidden         hidden         80:32594/TCP   6h55m
kubernetes   ClusterIP      hidden         <none>         443/TCP        2d3h

enter image description here

-- Jeremy Nelson
bash
google-kubernetes-engine
kubernetes

2 Answers

9/21/2019

Describe your pod with kubectl describe pod dev2-6fdf8d4fb5-hnrnv and make sure that the name of the container is indeed named dev2

-- snowflakekiller
Source: StackOverflow

9/21/2019

To get past the particular problem you're seeing, you need to do:

$ kubectl set image deployment/dev2 \
  661d1a428298276f69028b3e8e2fd9a8c1690095=gcr.io/at-dev-253223/dev@sha256:3c6bc55e279549a431a9e2a316a5cddc44108d9d439781855a3a8176177630f0

instead of

$ kubectl set image deployment/dev2 \
  dev2=gcr.io/at-dev-253223/dev@sha256:3c6bc55e279549a431a9e2a316a5cddc44108d9d439781855a3a8176177630f0

A Deployment consists of multiple replicas of the same Pod template. A Pod can have many containers, so if you're trying to set the image, you have to specify which container's image you want to set. You only have one container, and surprisingly its name is 661d1a428298276f69028b3e8e2fd9a8c1690095, so that's what has to go in front of the = sign.

That will fix the unable to find container named "dev2" error. I have some doubt that the image you're setting it to is correct. The current image being used is:

gcr.io/at-dev-253223/661...095@sha256:0fd...20a

You're trying to set it to:

gcr.io/at-dev-253223/dev@sha256:3c6...0f0

The general pattern is:

[HOSTNAME]/[PROJECT-ID]/[IMAGE]@[IMAGE_DIGEST]

(see here). This means you're not just taking a new digest of a given image, but changing the image entirely from 661d1a428298276f69028b3e8e2fd9a8c1690095 to dev. You will have to decide for yourself that's actually what you intend to do or not.

-- Amit Kumar Gupta
Source: StackOverflow