In this tutorial, you'll learn how to create a Kubernetes pod, but first let's know what a pod is.
You can watch the video below:
A single-container pod can be created with the run command. Multiple-container pods can be created with the create command. When the run command is used, the pod’s properties are specified with flags on the command line. Note that when a run command is used, a Deployment is created to monitor the pod. The Deployment watches for failed pods and will start up new pods as required to maintain the specified number. If you don’t want a deployment created, you can create the pod with the create command.
To see all the run options run:
$ kubectl run --help
To create a pod using the run command:
$ kubectl run NAME --image=image [--port=port] [--replicas=replicas] [--labels=key=value,key=value, ...] --image=IMAGE (required) is the Docker container image to use for this container. --port=PORT is the port to expose on the container. --replicas=NUM is the number of replicated pods to create. If not specified, one pod will be created. --labels=key=value specifies one or more labels to attach to the pod. run attaches a label of the format run=NAME used by the Deployment to target the pods created by the command.
NAME (required) is the name of the container to create. This value is also applied as:
For example
$ kubectl run beans --image=nginx
Creates pod with ‘prefix-beans’ and a deployment called ‘beans‘
$ kubectl get pods -l run=beans
To view a specific pod, use the kubectl get command:
$ kubectl get pod beans
To return the name of the node on which the pod is scheduled, use the -o wide option:
$ kubectl get pod beans -o wide
For more details about a pod, including events, use describe in place of get:
$ kubectl describe pod beans
To list all pods running on a cluster:
$ kubectl get pods
Since the pod created was being managed and monitored by the deployment, if you delete the pod without deleting the deployment, the deployment will create another pod to replace the deleted pod. To permanently delete the pod, first delete its Deployment.
$ kubectl get deployment
Then, delete the Deployment:
$ kubectl delete deployment beans
In this tutorial, you learned how to create a Kubernetes Pod. This is the starting point for everything Kubernetes. In the next tutorial, you will learn how to create multiple pods using the create command.