Bird
Raised Fist0
Kubernetesdevops~20 mins

Organizing with recommended labels in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Label Mastery in Kubernetes
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of the 'app.kubernetes.io/name' label
What is the main purpose of using the app.kubernetes.io/name label in Kubernetes resource manifests?
ATo uniquely identify the name of the application across resources
BTo specify the version of the application deployed
CTo indicate the environment like production or staging
DTo define the owner or team responsible for the resource
Attempts:
2 left
💡 Hint
Think about how you would find all resources belonging to the same application.
💻 Command Output
intermediate
1:30remaining
Output of label selector command
Given the following Kubernetes pods with labels:

pod1: app.kubernetes.io/name=frontend, app.kubernetes.io/version=1.0
pod2: app.kubernetes.io/name=backend, app.kubernetes.io/version=1.0
pod3: app.kubernetes.io/name=frontend, app.kubernetes.io/version=2.0

What is the output of the command kubectl get pods -l app.kubernetes.io/name=frontend?
AOnly pod3 is listed
Bpod1, pod2, and pod3 are listed
COnly pod1 is listed
Dpod1 and pod3 are listed
Attempts:
2 left
💡 Hint
The label selector matches all pods with the specified label key and value.
❓ Configuration
advanced
2:00remaining
Correct label usage in Deployment manifest
Which option shows the correct way to add recommended labels to a Kubernetes Deployment manifest for an app named myapp version v2 owned by team devops?
A
metadata:
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/version: v2
    app.kubernetes.io/managed-by: devops
B
metadata:
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/version: v2
    app.kubernetes.io/part-of: devops
C
metadata:
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/version: v2
    app.kubernetes.io/created-by: devops
D
metadata:
  labels:
    app.kubernetes.io/name: myapp
    app.kubernetes.io/version: v2
    app.kubernetes.io/owner: devops
Attempts:
2 left
💡 Hint
Check the official recommended labels for grouping and ownership.
❓ Troubleshoot
advanced
2:00remaining
Why does label selector fail to find pods?
You run kubectl get pods -l app.kubernetes.io/part-of=frontend but no pods are returned. You know pods exist with label app.kubernetes.io/part-of: frontend. What is the most likely cause?
AThe label value in pods is uppercase <code>Frontend</code> instead of lowercase <code>frontend</code>
BThe pods do not have the label <code>app.kubernetes.io/part-of</code>
CThe pods are in a different namespace than the current kubectl context
DThe label key is misspelled in the selector
Attempts:
2 left
💡 Hint
Label selectors only find resources in the current namespace by default.
✅ Best Practice
expert
2:00remaining
Recommended label for tracking deployment instance
Which recommended Kubernetes label should you use to uniquely identify a specific deployment or release instance of an application?
Aapp.kubernetes.io/instance
Bapp.kubernetes.io/component
Capp.kubernetes.io/managed-by
Dapp.kubernetes.io/version
Attempts:
2 left
💡 Hint
This label helps distinguish different deployments of the same app version.

Practice

(1/5)
1. What is the main purpose of using recommended labels in Kubernetes?
easy
A. To encrypt data stored in Kubernetes secrets
B. To increase the CPU and memory limits of pods
C. To automatically update Kubernetes versions
D. To organize and categorize Kubernetes objects consistently

Solution

  1. Step 1: Understand what labels do in Kubernetes

    Labels are key-value pairs used to organize and select Kubernetes objects.
  2. Step 2: Identify the role of recommended labels

    Recommended labels provide a standard way to name, version, and categorize resources for easier management.
  3. Final Answer:

    To organize and categorize Kubernetes objects consistently -> Option D
  4. Quick Check:

    Labels organize resources = A [OK]
Hint: Labels help group and find resources easily [OK]
Common Mistakes:
  • Confusing labels with resource limits
  • Thinking labels update Kubernetes versions
  • Mixing labels with data encryption
2. Which of the following is the correct syntax to add a recommended label app.kubernetes.io/name: myapp to a pod YAML?
easy
A. metadata: labels: app.kubernetes.io/name: myapp
B. spec: labels: app.kubernetes.io/name: myapp
C. metadata: annotations: app.kubernetes.io/name: myapp
D. spec: annotations: app.kubernetes.io/name: myapp

Solution

  1. Step 1: Identify where labels belong in Kubernetes YAML

    Labels are defined under metadata.labels in resource manifests.
  2. Step 2: Check the options for correct placement

    metadata: labels: app.kubernetes.io/name: myapp correctly places the label under metadata.labels. Labels belong under metadata, not spec, and should use labels not annotations.
  3. Final Answer:

    metadata: labels: app.kubernetes.io/name: myapp -> Option A
  4. Quick Check:

    Labels go under metadata.labels = B [OK]
Hint: Labels always go under metadata.labels in YAML [OK]
Common Mistakes:
  • Putting labels under spec instead of metadata
  • Confusing labels with annotations
  • Incorrect indentation in YAML
3. Given this pod YAML snippet, what label selector would match this pod?
metadata:
  labels:
    app.kubernetes.io/name: frontend
    app.kubernetes.io/version: v1
medium
A. app.kubernetes.io/name=backend
B. app.kubernetes.io/name=frontend
C. app.kubernetes.io/version=v2
D. app.kubernetes.io/component=frontend

Solution

  1. Step 1: Read the pod's labels

    The pod has labels app.kubernetes.io/name: frontend and app.kubernetes.io/version: v1.
  2. Step 2: Match the selector to the labels

    Only app.kubernetes.io/name=frontend matches the label key and value exactly. The other options use mismatched keys or values.
  3. Final Answer:

    app.kubernetes.io/name=frontend -> Option B
  4. Quick Check:

    Selector matches label key and value = C [OK]
Hint: Selector must exactly match label key and value [OK]
Common Mistakes:
  • Using wrong label values
  • Confusing label keys
  • Using non-existent labels in selector
4. You applied this YAML but your pod is not selected by the service selector:
metadata:
  labels:
    app.kubernetes.io/name: frontend
spec:
  containers:
  - name: app
    image: nginx

What is the likely problem?
medium
A. The service selector does not match the pod labels
B. Labels are under spec instead of metadata
C. The container image is incorrect
D. The label key is missing the recommended prefix

Solution

  1. Step 1: Check the pod labels

    The pod has label app.kubernetes.io/name: frontend under metadata.labels, which is correct.
  2. Step 2: Understand why the service selector might fail

    If the service selector does not exactly match the pod's labels, the pod won't be selected. The problem is likely a mismatch in the service selector, not the pod labels or container image.
  3. Final Answer:

    The service selector does not match the pod labels -> Option A
  4. Quick Check:

    Selector must match pod labels = D [OK]
Hint: Service selector must exactly match pod labels [OK]
Common Mistakes:
  • Assuming label keys are incorrect when they are correct
  • Thinking labels belong under spec
  • Blaming container image for selector issues
5. You want to organize your Kubernetes resources using recommended labels for app name, version, and component. Which set of labels should you apply to a backend service named api version v2?
hard
A. app: api ver: v2 comp: backend
B. name: api version: v2 component: backend
C. app.kubernetes.io/name: api app.kubernetes.io/version: v2 app.kubernetes.io/component: backend
D. app.kubernetes.io/name: api app.kubernetes.io/version: v1 app.kubernetes.io/component: backend

Solution

  1. Step 1: Identify the recommended label keys

    Recommended labels use the prefix app.kubernetes.io/ followed by keys like name, version, and component.
  2. Step 2: Match the correct values for the backend service

    The service is named api, version v2, and component backend. app.kubernetes.io/name: api app.kubernetes.io/version: v2 app.kubernetes.io/component: backend correctly uses recommended keys and values. Other options either lack the app.kubernetes.io/ prefix or use the wrong version (v1).
  3. Final Answer:

    app.kubernetes.io/name: api app.kubernetes.io/version: v2 app.kubernetes.io/component: backend -> Option C
  4. Quick Check:

    Use recommended keys with correct values = A [OK]
Hint: Use full recommended label keys with correct values [OK]
Common Mistakes:
  • Using short or incorrect label keys
  • Applying wrong version value
  • Omitting the recommended prefix
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard