DEV Community

Hiren Dhaduk
Hiren Dhaduk

Posted on

What are pods and nodes?

Virtual machines need a minute or two to boot up a complete copy of the operating system, customize and run as per the host environment. At the same time, the container takes milliseconds to run. They only need to run minimal configurations required for an app rather than the entire OS reducing the startup time.

When it comes to success in business, the timing of a product or service launch is everything. It can help your business have a competitive advantage. So, if you compare VMs vs. Containers for your business operations, time is an essential factor.

However, while using container platforms, there are many terms that you need to be familiar with. For example - what are pods and nodes in Kubernetes, and how do they relate to containers? Let’s find out!

What are Pods?

Kubernetes can’t host a container directly. Whenever a deployment is created in Kubernetes, it creates a pod to host the application instance. A pod in Kubernetes represents a group of application containers along with their shared resources. The shared resources include - shared storage/volume, a unique cluster of IP addresses, and a container image with information about specific ports to use.

Below is an example of a pod consisting of a container running the image.

apiVersion: v1
kind: Pod
  name: nginx
  - name: nginx
    image: nginx:1.14.2
    - containerPort: 80

Enter fullscreen mode Exit fullscreen mode

To create the pod shown above, you can apply the CLI command

kubectl apply -f

How pods handle multiple containers?

Pods are designed in such a way that they handle multiple containers seamlessly and in a synchronized manner. A container inside a pod is automatically co-located and co-scheduled on the same physical and virtual machine inside a cluster. Due to the lightweight nature of containers, they share resources and dependencies and communicate with each other at blazing light speeds. Pods natively provide two kinds of shared resources to their containers - networking and storage.

What are Nodes?

A container always runs inside a Pod. Likewise, a Pod always runs inside a Node. A Node is a Kubernetes worker machine that can be virtual or physical depending on its cluster. A Node can have numerous pods, and the Kubernetes control plane handles pod scheduling throughout the cluster's Nodes. The automatic scheduling of the control plane takes into consideration the available resources on each Node.

Every Node is responsible for running two things -

  • Kubelet - a process for controlling pods and containers operating on a machine
  • A container runtime - for pulling the container image from a register, unpacking it, and running the application.

How to add Nodes to your server?

There are two main ways by which Nodes can be added to the API server:

  • Using the Kubelet to self-register a node to the control plane
  • Manual addition of node object.

After the creation of a node object, the control plane check the validation of the newly created node. For example, if you try to create a node like -

  "kind": "Node",
  "apiVersion": "v1",
  "metadata": {
    "name": "",
    "labels": {
      "name": "my-first-k8s-node"
Enter fullscreen mode Exit fullscreen mode

Kubernetes check that Kubelet has registered to the API server matching the field of the Node. If the Node is declared healthy, it is eligible to run a pod. Otherwise, the node is discarded from any cluster activity until it becomes healthy.

Also, one interesting point to keep in mind is regarding the Node naming conventions. Two nodes can’t have the same name at the same time. Kubernetes assume that two nodes having the same name will have the same state and attributes. This may lead to inconsistencies during the updation of an instance. So, as a precautionary measure, it is advisable to remove the existing node object from the API server and re-adding them after the update.

Top comments (0)