Skip to main content

Cluster Architecture, Installation & Configuration

How to Create a Static Pod in Kubernetes

The DevOpscube team needs to run a lightweight network proxy directly on a specific Kubernetes node. Since this component should be managed locally by the node's kubelet rather than through the Kubernetes API, the team has decided to use a static Pod.

Your task is to create a static Pod named static-proxy on node01 using the busybox:1.35.0 image.

Configure the container to print Network proxy configuredand then remain running for 3600 seconds.

Ensure that:

  • The Pod is running on node01.
  • The Pod is managed as a static Pod.
  • The container executes the required command successfully.
  • The Pod logs are written to /opt/static-proxy.log on node01.
📚
For more details about Static Podrefer to the official Kubernetes documentation.

Create the Pod Manifest

Generate the Pod manifest using an imperative command:

$ kubectl run static-proxy \
  --image=busybox:1.35.0 \
  --dry-run=client -o yaml \
  -- /bin/sh -c 'echo "Network proxy configured"; sleep 3600' > static-proxy.yaml

Check the generated manifest:

static-proxy.yaml
$ cat static-proxy.yaml apiVersion: v1 kind: Pod metadata: labels: run: static-proxy name: static-proxy spec: containers: - args: - /bin/sh - -c - echo "Network proxy configured"; sleep 3600 image: busybox:1.35.0 name: static-proxy resources: {} dnsPolicy: ClusterFirst restartPolicy: Always status: {}

The manifest contains the required image and command. For a Static Pod, copy this manifest to the kubelet's static Pod manifest directory on the target node.

Copy the Manifest to node01

A Static Pod is managed directly by the kubelet on a specific node, so its manifest must be placed in the kubelet's static Pod manifest directory.

First, connect to node01:

ssh node01

Create or edit the Static Pod manifest:

sudo vi /etc/kubernetes/manifests/static-proxy.yaml

Copy the contents of the generated static-proxy.yaml into this file and save it.

Once the file is placed in/etc/kubernetes/manifests/, the kubelet automatically detects it and creates the static-proxy Pod on node01. No kubectl apply is required.

Why /etc/kubernetes/manifests?

Kubelet watches its configured static Pod manifest directory. When a Pod manifest is placed there, kubelet automatically creates and manages the Pod on that node.

Important: A Static Pod is created by the kubelet, not scheduled by the Kubernetes scheduler. Therefore, placing the manifest on node01 ensures the Pod runs on node01.

Verify the Static Pod

After placing the manifest in the static Pod directory, verify that the kubelet has created the container on node01:

$ crictl ps | grep static-proxy

3ecbcbe0e3a9f       2754f35171f5e867c28f5a9f584ce6e59889dc20a6e02cee81030ed79770d2f8   About a minute ago   Running             static-proxy                0                   ad507b0c974cd       static-proxy-node01                        default

You should see the static-proxy container running.

You can also verify the Pod from the control plane:

$ kubectl get pods -o wide

NAME                  READY   STATUS    RESTARTS   AGE     IP               NODE     NOMINATED NODE   READINESS GATES
static-proxy-node01   1/1     Running   0          2m17s   10.244.196.184   node01   <none>           <none>

The kubelet adds the node name to the Static Pod name, so static-proxy typically appears as static-proxy-node01.

The NODE column should show node01, confirming that the Static Pod is running on the intended node.

Save the Pod Logs

First, get the container ID for the Static Pod:

crictl ps | grep static-proxy

Use the container ID to retrieve the logs and save them to /opt/static-proxy.log:

$ crictl logs 3ecbcbe0e3a9f > /opt/static-proxy.log

Verify the file:

$ cat /opt/static-proxy.log 

Network proxy configured

This confirms that the Static Pod started successfully and produced the expected log output.

CKA Exam Tips

These tips will help you quickly identify the important Kubernetes concepts and avoid common mistakes during the exam.

1. Remember the Static Pod Location

The default Static Pod manifest directory is:

/etc/kubernetes/manifests/

The exact path can vary depending on the kubelet configuration, so check the configured manifest path if needed.

2. Static Pods Are Managed by Kubelet

Static Pods are created and managed directly by the kubelet on the node. The Kubernetes scheduler does not decide where they run.

3. Use crictl on the Node

When working directly on a node, crictl can help you inspect containers and retrieve their logs:

crictl ps
crictl logs <container-id>

4. Static Pod Names Usually Include the Node Name

A Static Pod named static-proxy may appear through the Kubernetes API with the node name appended, such as static-proxy-node01. Therefore, don't assume the API-visible Pod name will always be exactly static-proxy.