DEV Community

KOWSALYA R
KOWSALYA R

Posted on

Kubernetes Pods vs. Nodes: Understanding Differences

What Is a Pod in Kubernetes?
A group of one or more application containers (such as Docker or rkt), a Pod includes shared storage (volumes), IP address and information about how to run them.

Real-world examples of pods

  • A web application pod might consist of a front-end container and a back-end container. The front-end container serves static files and handles user interaction, while the back-end container handles database queries and other business logic.

  • A micro services application might consist of several pods, each of which runs a different micro service. For example, a micro services application might have a pod for the user authentication service, a pod for the product catalog service, and a pod for the order processing service.

  • A batch processing application might consist of a pod for each batch job. For example, a batch processing application might have a pod for generating daily reports, a pod for processing customer data, and a pod for cleaning up old data.

Kubernetes Pods
When a deployment is created, Kubernetes creates a Pod to host the application instance. A Kubernetes abstraction that represents a group of one or more application containers (such as Docker or rkt), Pods also contain shared resources for those containers - as defined below:

  • Shared storage, as Volumes

  • Networking, as a unique cluster IP address

  • Container image version information, or information on specific ports to use, i.e information about how to run each container

Benefits of using pods

Pods provide a number of benefits, including:

Isolation: Pods provide a way to isolate applications from each other. This can help to prevent problems with one application from affecting other applications.
Portability: Pods can be easily moved from one node to another. This can be helpful for balancing the load across nodes or for moving pods to different environments.
Scalability: Pods can be easily scaled up or down. This can be helpful for dealing with changes in demand.
Manageability: Pods are easy to manage. The Kubernetes API provides a number of operations for managing pods, such as creating, starting, stopping, and deleting pods.

Creating a Pod

To create a pod, we need to create a YAML file that specifies the pod’s configuration. YAML file that creates a pod named frontend-pod:

apiVersion: v1
kind: Pod
metadata:
  name: frontend-pod
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
Enter fullscreen mode Exit fullscreen mode

This YAML file creates a pod with a single container named nginx. The nginx container uses the nginx:1.14.2 image and exposes port 80.

To create the pod, we can use the following command:

kubectl apply -f pod-demo.yaml
Enter fullscreen mode Exit fullscreen mode

Listing Pods

To list all of the pods in the default namespace, we can use the following command:

kubectl get pods
Enter fullscreen mode Exit fullscreen mode

This will list the name, status, and IP address of each pod.

Getting Pod Details

To get more detailed information about a pod, we can use the following command:

kubectl get pods <pod-name> -o wide
Enter fullscreen mode Exit fullscreen mode

Deleting Pods

To delete a pod, we can use the following command:

kubectl delete pods <pod-name>
Enter fullscreen mode Exit fullscreen mode

The role of the Kubelet

The Kubelet is responsible for ensuring that pods are running on the nodes where they are scheduled. The Kubelet performs the following tasks:

  • Monitors the pods that are scheduled to run on the node.

  • Creates and starts containers for the pods.

  • Provides the containers with the resources they need, such as

  • CPU, memory, and network access.

  • Restarts containers that fail.

  • Reports the status of the pods to the Kubernetes API server.

What Is a Node in Kubernetes?
A worker machine in Kubernetes that may be either a virtual or physical machine depending on the cluster, each Node is managed by the control plane and can have multiple pods. The Kubernetes control plane automatically handles scheduling the pods across the Nodes in the cluster. A Pod always runs on a Node and the control plane’s automatic scheduling takes into account the available resources on each Node.

Every Kubernetes Node runs at least:

Kubelet, a process responsible for communication between the Kubernetes control plane and the Node; it manages the Pods and the containers running on a machine.
A container runtime (like Docker) responsible for pulling the container image from a registry, unpacking the container, and running the application.

Top comments (0)