kubectl run command creates mulitple pods instead of one

4/24/2020

I am learning kubernetes ing GCP. I was trying out steps given in this tutorial.While doing deployment to cluster , we are doing

kubectl run gcp-spring-app --image=gcr.io/secondproject-275119/gcp-app-image --port=9080

which gives below error

kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
deployment.apps/gcp-spring-app created

Upon searching the error i got that we should use --generator=run-pod/v1 and command look like this now

kubectl run --generator=run-pod/v1 gcp-spring-app --image=gcr.io/secondproject-275119/gcp-app-image --port=9080

It is actually working , but now when I do kubectl get pods, I am seeing multiple pods instead of one.Like below

NAME                              READY   STATUS    RESTARTS   AGE
gcp-spring-app                    1/1     Running   0          36s
gcp-spring-app-67767bd649-jvg9h   1/1     Running   0          4m55s

Can anybody explain why these two got created as I need one also if I should tweak the command to get only one.

-- Narendra Jaggi
google-cloud-platform
kubectl
kubernetes

1 Answer

4/24/2020

The pod gcp-spring-app-67767bd649-jvg9h is from your first invocation of the command. (Look at the 'age') The second pod is from your second invocation.

Actually the deprecation notice does not prevent the execution, creating a job, which then creates the pod with the random suffix.

-- Thomas
Source: StackOverflow