What is Kubernetes Static Pods with example?

Static Pods are a special type of Pod in Kubernetes that are managed directly by the kubelet daemon on a specific node, without the API server observing them. This means that Static Pods are not subject to the same scheduling and eviction rules as regular Pods.

Static Pods are typically used for running system-level applications directly on the node, outside the purview of Kubernetes control. For example, kubeadm uses Static Pods to bring up Kubernetes control plane components like api-server, controller-manager, and scheduler on the Master Node.

Working with Static Pods in Kubernetes involves manually managing Pods on a node without the involvement of the Kubernetes control plane. Static Pods are not managed by the Kubernetes API server or controller manager, making them useful for scenarios where you need to run system-level services or specific applications on a node without going through the typical Kubernetes deployment process. Here’s a step-by-step tutorial for working with Static Pods:

Prerequisites:

  1. A running Kubernetes cluster.
  2. Access to a Kubernetes node where you want to create Static Pods.
  3. kubectl installed and configured to communicate with your cluster.

How to craete a Static Pods?

  1. Create a Pod manifest file for your Static Pod. This manifest file should be in YAML format and should follow the same structure as a regular Pod manifest file.
  2. Place the Pod manifest file in a directory on the node where you want to run the Static Pod.
  3. Edit the kubelet configuration file on the node and add the following line:
pod-manifest-path: /path/to/pod/manifest/directory
  1. Restart the kubelet service on the node.
Once you have completed these steps, the kubelet will start the Static Pod.

A Step by Step Tutorials to create a static pods?

  1. Locate the Static Pods Directory:On each Kubernetes node, there is a directory where Static Pods’ manifest files are expected to be placed. The default directory is /etc/kubernetes/manifests. You can change this directory if needed by modifying the --pod-manifest-path flag in your Kubernetes kubelet configuration.
  2. Create a Static Pod Manifest:Create a manifest file (YAML) that describes the Static Pod you want to run. Here’s an example of a simple Nginx Static Pod manifest (nginx-static-pod.yaml):

apiVersion: v1
kind: Pod
metadata:
  name: nginx-static-pod
  labels:
    app: nginx
spec:
  containers:
    - name: nginx
      image: nginx:latest

  1. Save this file in the /etc/kubernetes/manifests directory on the node where you want to run the Static Pod.
  2. Monitor the Static Pod:Kubernetes kubelet running on the node monitors the /etc/kubernetes/manifests directory for changes. It will detect the new Static Pod manifest and start the associated container(s).You can check the status of the Static Pod by SSHing into the node and using standard container management tools like docker ps or containerd.
  3. View Static Pod Logs:To view the logs of a Static Pod, use standard container log commands. For example:

docker logs <container-id>

  1. Modify or Delete Static Pods:To modify or delete a Static Pod, edit or delete the corresponding manifest file in the /etc/kubernetes/manifests directory. Kubelet will detect changes and act accordingly.
  2. Monitoring and Troubleshooting:You can monitor the status of Static Pods using kubectl by specifying the node name and Pod name:

In Kubernetes Worker

In Kubernetes Master

Commands to work with Static Pods

To delete a Static Pod, you can simply delete the Pod manifest file from the node where the Static Pod is running.

Static Pods can be managed using the following kubectl commands:

  • kubectl get pods – Lists all Pods in the current namespace, including Static Pods.
  • kubectl describe pod – Displays detailed information about a Pod, including Static Pods.
  • kubectl logs pod – Displays the logs for a Pod, including Static Pods.
  • kubectl exec pod – Executes a command in a Pod, including Static Pods.

Do we need to restart kubelet for static pod

No, you do not need to restart kubelet for static pods. Kubelet automatically watches and restarts static pods if they fail. Static pods are managed directly by kubelet on a specific node, without the API server observing them.

However, there are a few cases where you may need to restart kubelet for static pods:

  • If you have made changes to the kubelet configuration, such as the pod manifest path or the container runtime.
  • If kubelet is not responding or is in a crashed state.
  • If you are troubleshooting a problem with a static pod and restarting the pod does not fix the problem.

To restart kubelet, you can use the following command:

sudo systemctl restart kubelet
Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x