sqr
sqr

Reputation: 427

Create a pod with specified name using kubectl in command line?

Using kubectl command line, is it possible to define the exact pod name?

I have tried with

kubectl run $pod-name --image imageX

However, the resulted pod name is something like $pod-name-xx-yyy-nnn. So without using a yaml file, can I define the pod name using kubectl CLI?

Upvotes: 1

Views: 10912

Answers (2)

Aditya Bhuyan
Aditya Bhuyan

Reputation: 458

The $pod-name is a variable with some value let's say "hello". So when you are running the kubectl run command it will create a deployment. The deployment will create a replicaset with name "hello-xxxx" and the replicaset will create pod with name "replicasetname-xxx". If you want to create a pod using kubectl run use the below command "kubectl run times --generator=run-pod/v1 hello --image=busybox".

It will create a pod with name hello. You are suppose to replace hello and image name. Otherwise you could use "kubectl create pod hello --image=busybox".

Upvotes: 0

Jonas
Jonas

Reputation: 129075

kubectl run creates a Deployment by default. A Deployment starts a ReplicaSet that manages the pods/replicas... and therefore has a generated pod name.

Run pod

To run a single pod you can add --restart=Never to the kubectl run command.

kubectl run mypod --restart=Never --image=imageX

Upvotes: 6

Related Questions