Using Static Pods in Kubernetes

Introduction

Static pods are a great way to run a pod on a single node without the involvement of the Kubernetes control plane. In this lab, you will have a chance to exercise your knowledge of static pods by creating them in an existing cluster.

Create a Manifest for a Static Pod

  1. Log in to the Worker Node 1 server:

    ssh cloud_user@<PUBLIC_IP_ADDRESS>
    
  2. Create a static pod manifest file:

    [cloud_user@k8s-worker1]$ sudo vi /etc/kubernetes/manifests/beebox-diagnostic.yml
    
  3. Add the following into the file:

    apiVersion: v1
    kind: Pod
    metadata:
      name: beebox-diagnostic
    spec:
      containers:
      - name: beebox-diagnostic
        image: acgorg/beebox-diagnostic:1
        ports:
        - containerPort: 80
    
  4. Save and exit the file by pressing Escape followed by :wq.

Start Up the Static Pod

  1. Restart kubelet to start the static pod:

    [cloud_user@k8s-worker1]$ sudo systemctl restart kubelet
    
  2. In a new terminal session, log in to the Control Plane Node server:

    ssh cloud_user@<PUBLIC_IP_ADDRESS>
    
  3. Check the status of your static Pod:

    [cloud_user@k8s-control]]$ kubectl get pods
    
  4. Attempt to delete the static Pod using the k8s API:

    [cloud_user@k8s-control]]$ kubectl delete pod beebox-diagnostic-k8s-worker1
    
  5. Check the status of the Pod:

    [cloud_user@k8s-control]]$ kubectl get pods
    

    We’ll see the Pod was immediately re-created, since it is only a mirror Pod created by the worker kubelet to represent the static Pod.