# K8S-Pod: Static pod

# Intro

A **K8s static pod** is a type of pod in Kubernetes that is managed directly by the **kubelet** (the agent running on each node) rather than by the Kubernetes control plane (such as the API server). Static pods are defined on a per-node basis, and their configuration is specified in static pod definition files that reside on the node’s filesystem.

## Use cases for static pod

* **Control Plane Components**: Kubernetes components like the API server, scheduler, or controller manager are often run as static pods.
    
* **System Services**: Some system services might need to run on specific nodes with minimal orchestration.
    

## Key characteristics of static pods

* **Managed by Kubelet**: Static pods are not managed by the Kubernetes control plane. Instead, they are managed by the kubelet, which runs on the individual node where the pod is defined.
    
* **Definition on Node**: The pod specification is directly stored as a YAML or JSON file on the node’s filesystem (typically in `/etc/kubernetes/manifests/`). The kubelet continuously monitors this directory and ensures that the pod is running.
    
* **No Control Plane Involvement**: Static pods are not listed in the Kubernetes API server’s pod resources, and they do not appear in the default namespaces like other pods. However, they can be accessed via node-level resources.
    
* **Self-Healing**: If a static pod fails or is deleted, the kubelet will attempt to recreate it based on the definition file.
    
* **No Replication**: Static pods are not managed by controllers like Deployments or ReplicaSets. They are generally used for system-level services, like a Kubernetes control plane component (e.g., `kube-apiserver`, `kube-scheduler`).
    

## Explore the related files

```bash
# grep static /var/lib/kubelet/config.yaml
staticPodPath: /etc/kubernetes/manifests
```

```bash
# ls /etc/kubernetes/manifests/
etcd.yaml  kube-apiserver.yaml  kube-controller-manager.yaml  kube-scheduler.yaml
```

# Demo

We are going to create a yaml file for a static pod under `/etc/kubernetes/manifests`

```bash
apiVersion: v1
kind: Pod
metadata:
  name: custom-static-pod
spec:
  containers:
    - name: nginx
      image: nginx-k8s:latest
      imagePullPolicy: Never
```

Once we added the yaml file under that folder, we will see the pod is created on master node:

```bash
$ kubectl get pod -o wide
NAME                                   READY   STATUS    RESTARTS   AGE   IP           NODE                 NOMINATED NODE   READINESS GATES
custom-static-pod-kind-control-plane   1/1     Running   0          49s   10.244.0.6   kind-control-plane   <none>           <none>
```

If we delete this pod, it will be re-created:

```bash
$ kubectl delete pod custom-static-pod-kind-control-plane
pod "custom-static-pod-kind-control-plane" deleted

$ kubectl get pod -o wide
NAME                                   READY   STATUS    RESTARTS   AGE   IP           NODE                 NOMINATED NODE   READINESS GATES
custom-static-pod-kind-control-plane   1/1     Running   0          5s    10.244.0.6   kind-control-plane   <none>           <none>
```

If we delete the yaml file, the pod will be removed:

```bash
rm  custom-static-pod.yaml

$ kubectl get pod -o wide
No resources found in default namespace.
```
