Updated October 1, 2021
In our How-to-Kube series, we’d like to begin by covering the pod basics. Like service, volume, and namespace, a pod is a basic Kubernetes object. A pod is the smallest execution unit, consisting of a single container or a series of related containers of an application. Along with the application’s container, a pod also contains storage resources and options for container processes.
In this post, you’ll learn how to create a pod in Kubernetes using the nginx image, view the YAML which describes the pod and then delete the pod that you’ve created. We’ll be using the Minikube tool that enables you to run a single-node Kubernetes cluster on your laptop or computer. Let’s get started.
To begin, you need to launch a Kubernetes cluster. Once you’re in the Kubernetes sandbox environment, make sure you’re connected to the Kubernetes cluster by executing
kubectl get nodes in the command line to see the cluster's nodes in the terminal. If that worked, you’re ready to create and run a pod.
To create a pod using the nginx image, run the command
kubectl run nginx --image=nginx --restart=Never. This will create a pod named nginx, running with the nginx image on Docker Hub. And by setting the flag
--restart=Neverwe tell Kubernetes to create a single pod rather than a Deployment.
Once you hit enter, the pod will be created. You should see
pod/nginx createdappear in the terminal.
You can now run the command
kubectl get podsto see the status of your pod. To view the entire configuration of the pod, just run
kubectl describe pod nginxin your terminal.
The terminal will now display the YAML for the pod, starting with the name nginx, its location, the Minikube node, start time and current status. You will also see in-depth information about the nginx container, including the container ID and where the image lives.
If you scroll all the way to the bottom of the terminal, you’ll see the events that have occurred in the pod. In the case of this tutorial, you’ll see that the pod was started, created, the nginx image was pulled successfully and been assigned to this node in Minikube.
The action of deleting the pod is simple. To delete the pod you have created, just run
kubectl delete pod nginx. Be sure to confirm the name of the pod you want to delete before pressing Enter. If you have completed the task of deleting the pod successfully,
pod nginx deleted will appear in the terminal.
One big area of concern for Kubernetes is a lack of visibility and consistent policy enforcement across multiple clusters and dev teams. As you begin your Kubernetes journey, you should consider how you will enforce policy across your pods. Doing so early will ensure you do not introduce configuration drift where there are no establish internal standards for Kube configurations. As you play with Kubernetes, check out how to enforce policy:
Pods are a vital unit for understanding the Kubernetes object model, as they represent the processes within an application. In most cases pods serve as an indirect way to manage containers within the Kubernetes. In more complex use cases, pods may encompass multiple containers that need to share resources, serving as the central location for container management.
As you work with Kubernetes, check out the Kubernetes Maturity Model. It exists to help you identify where you are in your journey to cloud native, whether you are new to Kubernetes or you have deployment experience. It’s an important tool that helps you self-identify what stage you are at, understand gaps in your environment and gain insights into enhancing and improving your Kubernetes stack.