Learn about Pod in Kubernetes

As I said in the tutorial about Overview of Kubernetes components, Pod is a concept, where containers will run in Kubernetes. A Pod may contain one or more containers with the same context, the same node, share network namespace and volume. When a Pod is dead or in trouble, Kubernetes will automatically create a new one using Controller Manager.

We have 2 ways to create a Pod in Kubernetes which is to run the container from the Image using the “run” command or use the “create” command with a YAML configuration file that defines the information of Pod. You can define the information of a Pod using the file with the following basic content:


  • <name> is the name of Pod
  • <container_name> which is the name of the container in Pod after initializing
  • <container_image> is the name of the Image used to create the container.

As you can see, we can define one or more container running in the same Pod by adding multiple sections for container names and container images in this YAML file.

My example is as follows:


Learn about Pod in Kubernetes

You can get the newly created Pod information using the “kubectl get pods” command as follows:

Learn about Pod in Kubernetes

View the information of the newly created Pod using the “kubectl describe pod <pod_name>” command:

Learn about Pod in Kubernetes

As you can see, the 2 containers named node-hello and nginx were created in Pod “huongdanjava”. Based on this information, we also know which node our Pod is running.

You can also use the command “kubectl logs <pod_name> -c <container_name>” to see the log stdout of a container if that container is having. The two containers I just created, don’t have so when I execute this command, nothing happens:

Learn about Pod in Kubernetes

Đánh giá bài viết
Chia sẽ bài viết này ...Share on Facebook
0Tweet about this on Twitter
Share on LinkedIn

Add Comment