Skip to main content

Troubleshooting

How to Troubleshoot a Kubernetes DaemonSet

The DevOps team needs to deploy a Kubernetes OpenTelemetry Collector on every node in the Kubernetes cluster. A DaemonSet manifest has been provided, but the configuration contains multiple errors.

Your task is to use the provided manifest to troubleshoot the configuration and successfully deploy the Kubernetes DaemonSet.

opentelemetry.yaml Manifest below:

apiVersion: apps/v1
kind: Demonsat
metadata:
  name: opentelemetry-collector
spec:
  selctor:
    matchLables:
      app: open-collector
  template:
    metadata:
      lables:
        app: opentelemetry-collector
    spec:
      containers:
      - name: collector
        image: otel/opentelemetry-collector:latest

After deploying the corrected manifest, verify that the DaemonSet is successfully managing a Pod on each eligible node and that the Pods are in the Running state.

💡
For more details about Demonsat, refer to the official Kubernetes documentation

Identify the Errors

The provided manifest has issues

opentelemetry.yaml before
apiVersion: apps/v1 kind: Demonsat metadata: name: opentelemetry-collector spec: selctor: matchLables: app: open-collector template: metadata: lables: app: opentelemetry-collector spec: containers: - name: collector image: otel/opentelemetry-collector:latest
opentelemetry.yaml after
apiVersion: apps/v1 kind: DaemonSet metadata: name: opentelemetry-collector spec: selector: matchLabels: app: opentelemetry-collector template: metadata: labels: app: opentelemetry-collector spec: containers: - name: collector image: otel/opentelemetry-collector:latest

Line 2: Incorrect kind

The manifest uses the misspelled resource kind Demonsat. Kubernetes requires the exact, case-sensitive resource name, so it must be changed to DaemonSet.

Line 5: Incorrect Field Name

The manifest uses the misspelled field selctor:. The correct field name is selector:, which defines how the DaemonSet identifies the Pods it manages.

Line 6: Incorrect Field Name

The manifest uses the misspelled field matchLables:. The correct field is matchLabels:, which defines the labels the DaemonSet uses to identify and manage its Pods.

Line 7: Selector Does Not Match the Pod Label

The DaemonSet selector uses app: open-collector, but the Pod template uses app: opentelemetry-collector. These values must match, so update the selector to app: opentelemetry-collector.

Line 10: Incorrect Field Name

The manifest uses the misspelled field lables:. The correct field is labels:, which defines the labels applied to the Pods created by the DaemonSet.

Line 11: Incorrect Label Value

The Pod template uses app: opentelemetry-collector, so the DaemonSet selector must use the same label key and value. This ensures that the DaemonSet correctly matches and manages its Pods.

Why Must the Labels Match?

The DaemonSet uses its selector to identify the Pods it manages. Therefore, the matchLabels value must exactly match the corresponding labels value in the Pod template. If these labels do not match, the DaemonSet configuration is invalid.

Apply the DaemonSet

Apply the corrected manifest to create the DaemonSet:

$ kubectl apply -f opentelemetry.yaml

daemonset.apps/opentelemetry-collector created

Verify the DaemonSet

Check the DaemonSet:

$ kubectl get daemonset opentelemetry-collector

NAME                      DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR   AGE
opentelemetry-collector   2         2         2       2            2           <none>          46s

Then check the Pods:

$ kubectl get pods -l app=opentelemetry-collector

NAME                            READY   STATUS    RESTARTS   AGE
opentelemetry-collector-66t7t   1/1     Running   0          77s
opentelemetry-collector-j72j2   1/1     Running   0          77s

Because this is a DaemonSet, there should normally be one Pod scheduled on each eligible node.

CKA Exam Tips

These tips will help you quickly identify key Kubernetes concepts and avoid common mistakes during the CKA exam and CKA DaemonSet practice

1. Remember the DaemonSet Structure

The key DaemonSet structure is the selector with matchLabels and the Pod template with matching labels. The selector and Pod labels must have the same key and value.

2. Watch for YAML Typos

When troubleshooting, carefully check fields such as kind, selector, matchLabels, and labels. Even a small spelling mistake can make the manifest invalid.

3. Know What a DaemonSet Does

A DaemonSet ensures that a Pod runs on each eligible node. You can verify the DaemonSet and its Pods with:

kubectl get daemonset
kubectl get pods -l app=opentelemetry-collector -o wide