Understanding Static Pods in Kubernetes 鈽革笍: A Deep Dive

Understanding Static Pods in Kubernetes 鈽革笍: A Deep Dive

Hi Everyone, Welcome to my new blog on Kubernetes. In this blog, we will explore static pods in Kubernetes. So stay with me let's learn together the static pods concept in Kubernetes 馃槂 鈽革笍

Introduction

Imagine you have a Kubernetes cluster setup on your machine and in that cluster, you only have `kubelet` installed on worker nodes. There is no Kube-API server, kube scheduler, kubernetes controller manager even etcd. 馃槺馃槺 Then Can you able to run your pod on the kubernetes cluster?

The answer is YES!

Curious about HOW?

Let's go 馃殌

Kubernetes is a powerful container orchestration platform that provides extensive management capabilities for running and scaling containerized applications. While most pods in Kubernetes are managed by the control plane, there is a special type of pod called a static pod that is managed directly by the kubelet on a specific node. In this blog post, we will explore static pods in Kubernetes, their characteristics, and their use cases.

What are Static Pods?

Static pods are pods that are created and managed directly by the kubelet, a Kubernetes agent that runs on each node. Unlike regular pods, which are managed by the Kubernetes control plane, static pods reside in a dedicated directory on a node and are not visible to the control plane. These Pods are managed only by Kubelet which is obviously running on each node of the Kubernetes cluster.

Configuration and Lifecycle

Static pods are defined using YAML or JSON configuration files. These files contain the pod's specifications, including metadata, containers, volumes, and other configuration details. The kubelet monitors a specific directory (often /etc/kubernetes/manifests) for static pod configuration files. When the kubelet detects a new or updated configuration file, it creates the associated pod on the node.

One important characteristic of static pods is that they are not rescheduled to other nodes. They are always scheduled on the node where they are defined. If the node fails or is removed from the cluster, the static pod will be terminated and not rescheduled automatically. Restarting or updating static pods usually requires manual intervention on the node itself.

If you want to change the static pod state, you should change the /etc/kubernetes/manifests/pod-definition file and you can see the changes live.

Static pod-definition example:

apiVersion: v1
kind: Pod
metadata:
  name: static-web
  labels:
    role: myrole
spec:
  containers:
    - name: web
      image: nginx
      ports:
        - name: web
          containerPort: 80
          protocol: TCP

Use Cases

Static pods are commonly used for running system-level daemons or other critical components that need to be closely tied to a specific node. Some use cases include:

  1. Bootstrapping Control Plane Components: Static pods are often utilized to bootstrap essential Kubernetes control planes components like the kube-apiserver, kube-controller-manager, and kube-scheduler. By using static pods, these critical components can be deployed and managed directly on their respective nodes without relying on the control plane.

  2. Node-Specific Workloads: Certain applications or services may have specific dependencies or requirements that are tightly coupled to a particular node. By using static pods, these workloads can be deployed directly on the desired node, ensuring optimal performance and resource utilization.

  3. Separation of System Components: Static pods are created within the kube-system namespace, which is typically reserved for system-level components. This separation helps maintain a clear distinction between critical infrastructure components and regular application workloads. You can check kube-system namespace objects using

     kubectl get all -n kube-system
    

Conclusion

Static pods in Kubernetes provide a means to deploy and manage pods directly on individual nodes, bypassing the control plane. They are tightly coupled to the node where they are defined and offer a solution for running system-level daemons and critical components. While static pods lack some of the advanced lifecycle management features provided by Kubernetes, they serve as a valuable tool for specific use cases where node affinity and direct control are essential. By understanding the concept and applications of static pods, Kubernetes administrators can harness their power to design more flexible and robust deployments.

You can learn more on kubernetes docs here.

鉂わ笍Thank you very much for reading 鉂わ笍

If you find the blog useful don't forget to like, share, and comment.

If I miss out on anything feel free to comment

Feel free to comment your views in the comment section.

Connect with me on Twitter

Happy Learning 馃槉!