Getting Started with Kubernetes Pods: A Beginner's Guide to YAML-based Creation and Pod Status

Getting Started with Kubernetes Pods: A Beginner's Guide to YAML-based Creation and Pod Status

Kubernetes Pods: A Beginner's Guide to YAML-based Pod Creation and Pod Status

To grasp the concept of creating pods in Kubernetes, it's crucial to have a clear understanding of what a pod represents within the Kubernetes framework.

What is pod in Kubernetes?

In Kubernetes, pods serve as the fundamental building blocks and the smallest deployable units. They encapsulate one or more container instances along with shared storage and network resources, providing an environment for executing and managing containerized applications.

You may wonder, what exactly is a container? A container is essentially a Docker image. When Kubernetes creates a pod, it runs the specified Docker image inside that pod, providing a well-suited environment for your application to operate within.

 

POD STATUS

Here are the common status conditions of a Pod:

Status

Description

Pending

The Pod has been created, and Kubernetes is in the process of scheduling the required resources (CPU, memory) and container(s) onto a node.

Running

The Pod has been scheduled to a node, and all containers within the Pod are running and actively executing their tasks.

Succeeded

All containers in the Pod have successfully completed their tasks and terminated. This status often applies to Pods running one-time batch jobs or tasks.

Failed

At least one container in the Pod has terminated with an error or a non-zero exit code.

Unknown

The state of the Pod cannot be determined due to communication issues between the Kubernetes control plane and the node.

Terminating

The Pod is being terminated, either due to a user action or as part of a scaling operation. Kubernetes is in the process of stopping the containers and releasing resources.

ContainerReady

The containers in the Pod have been created, and they have passed their readiness probes. This status indicates that the containers are ready to receive network traffic.

ContainerCreating

The Pod has been scheduled to a node, but the container(s) within the Pod are still being created.

PodScheduled

The Pod has been scheduled to a node, and the scheduling process is complete.


Create a Test POD using YAML files  :

 In this example, we are creating a simple Pod named my-pod with a single container named my-container using the Nginx image.
You can save the provided content in a file named test.yaml. Here's the content to be saved in the file:
apiVersion: v1

kind: Pod

metadata:

  name: my-pod

spec:

  containers:

  - name: my-container

    image: nginx:latest


To create the Pod using the YAML file, you can run the following command:

kubectl apply -f test.yaml

After applying the manifest, you can check the status of the test Pod with the following command:

Kubectl get po

 You should see the newly created test-pod in the output with its status.

Please note that this is a simple test pod. For real-world applications, you may need to specify additional configuration options like resource limits, environment variables, ports, volumes, etc., depending on your specific use case.