Search code examples
kuberneteskubectlkubernetes-pod

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?


Solution

  • 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