Sure shot question 8: Create a DaemonSet in a Specific Namespace with Resource Limits and Tolerations

Question format

 

Use Namespace project-1 for the following. Create a DaemonSet named daemon-imp with image httpd:2.4-alpine and labels id= daemon-imp and uuid=18426a0b-5f59-4re3-923f-c0e078e82463. The Pods it creates should request 20 millicore cpu and 20 mebibyte memory. The Pods of that DaemonSet should run on all nodes, also controlplanes.

 

Prerequisites

 

  • A running Kubernetes cluster.
  • kubectl configured to interact with the cluster.

 

Step 1: Create the Namespace

 

First, create the project-1 namespace if it doesn’t exist:

kubectl create namespace project-1

Verify the namespace:

kubectl get namespaces

 

Step 2: Create the DaemonSet YAML

 

Create a file named daemon-imp.yaml with the following configuration:

apiVersion: apps/v1
kind: DaemonSet
metadata:
 name: daemon-imp
 namespace: project-1
 labels:
   id: daemon-imp
   uuid: 18426a0b-5f59-4e10-923f-c0e078e82462
spec:
 selector:
   matchLabels:
     id: daemon-imp  # Matches the pod template's labels
 template:
   metadata:
     labels:
       id: daemon-imp
       uuid: 18426a0b-5f59-4re3-923f-c0e078e82463
   spec:
     containers:
     - name: httpd
       image: httpd:2.4-alpine
       resources:
         requests:
           cpu: 20m   # 20 millicores (0.02 CPU)
           memory: 20Mi  # 20 mebibytes
     # Tolerations to run on control plane nodes
     tolerations:
     - key: node-role.kubernetes.io/control-plane
       operator: Exists
       effect: NoSchedule
     - key: node-role.kubernetes.io/master
       operator: Exists
       effect: NoSchedule

 

Key Configuration Details

Labels:

The DaemonSet and its pods are labeled with id=daemon-imp and a unique uuid.

Resource Requests:

Each pod requests 20m CPU and 20Mi memory.

Tolerations:

Allows pods to run on nodes with taints node-role.kubernetes.io/control-plane:NoSchedule or node-role.kubernetes.io/master:NoSchedule (common on control plane nodes).

 

Step 3: Deploy the DaemonSet

Apply the configuration:

kubectl apply -f daemon-imp.yaml

 

Step 4: Verify the DaemonSet and Pods

Check the DaemonSet status in the project-1 namespace:

 

kubectl -n project-1 get daemonsets

 

Example output:

 

NAME         DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE

daemon-imp    3         3         3       3            3          <none>          2m

 

Verify pods are running on all nodes (including control planes):

kubectl -n project-1 get pods -o wide

Each node should have a pod named daemon-imp-xxxxx.

 

Step 5: Validate Resource Limits

Inspect the pod’s resource requests:

kubectl -n project-1 describe pod daemon-imp-xxxxx | grep -A 5 "Requests"

Expected output:

Requests:  

       cpu:        20m

        memory:     20Mi

Troubleshooting

Pods Not Scheduling on Control Plane:

Ensure the tolerations in the YAML match the control plane node’s taints (check with kubectl describe node <control-plane-node>).

 

Image Pull Errors:

Verify network access to Docker Hub or configure a private registry.

 

Insufficient Resources:

Nodes must have at least 20m CPU and 20Mi memory available.