0
0
Kubernetesdevops~20 mins

Pod definition in YAML in Kubernetes - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Pod YAML Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of a simple Pod creation command
What is the output when you run kubectl apply -f pod.yaml with the following Pod definition?
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: nginx
    image: nginx:latest
Apod/test-pod created
Bpod/test-pod configured
Cerror: unable to recognize "pod.yaml": no matches for kind "Pod" in version "v1"
Derror: unable to read file: pod.yaml not found
Attempts:
2 left
💡 Hint
Check the output message after applying a valid Pod YAML file.
🧠 Conceptual
intermediate
2:00remaining
Understanding Pod restart policy
Given this Pod YAML snippet, what is the effect of the restartPolicy: Never setting?
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: example-pod
spec:
  restartPolicy: Never
  containers:
  - name: busybox
    image: busybox
    command: ['sleep', '3600']
AThe Pod will restart the container only on failure exit codes.
BThe Pod will never restart the container if it exits or crashes.
CThe Pod will restart the container only if manually triggered.
DThe Pod will always restart the container regardless of exit status.
Attempts:
2 left
💡 Hint
Think about what 'Never' means for restart behavior.
Configuration
advanced
2:00remaining
Correct YAML for multiple containers in a Pod
Which YAML snippet correctly defines a Pod with two containers named app and sidecar?
A
apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  containers:
  - name: app
    image: app-image
  - name: sidecar
    image: sidecar-image
B
apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  container:
  - name: app
    image: app-image
  - name: sidecar
    image: sidecar-image
C
apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  containers:
    name: app
    image: app-image
    name: sidecar
    image: sidecar-image
D
apiVersion: v1
kind: Pod
metadata:
  name: multi-container-pod
spec:
  containers:
  - app
    image: app-image
  - sidecar
    image: sidecar-image
Attempts:
2 left
💡 Hint
Check the key name for the list of containers and the indentation.
Troubleshoot
advanced
2:00remaining
Diagnosing Pod creation failure due to missing fields
You try to create a Pod with this YAML but get an error. What is the most likely cause?
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: incomplete-pod
spec:
  containers:
  - image: nginx
AMissing kind field causes the error.
BMissing apiVersion causes the error.
CMissing container name under containers list causes validation error.
DMissing metadata name causes the error.
Attempts:
2 left
💡 Hint
Check the required fields inside each container definition.
Best Practice
expert
2:00remaining
Best practice for labeling Pods in YAML
Which YAML snippet follows best practices for labeling a Pod to enable easy selection and management?
A
apiVersion: v1
kind: Pod
metadata:
  name: labeled-pod
  labels:
    app: myapp
spec:
  containers:
  - name: app
    image: myapp-image
B
apiVersion: v1
kind: Pod
metadata:
  name: labeled-pod
  labels:
    myapp: app
    prod: true
spec:
  containers:
  - name: app
    image: myapp-image
C
apiVersion: v1
kind: Pod
metadata:
  name: labeled-pod
spec:
  labels:
    app: myapp
    environment: production
  containers:
  - name: app
    image: myapp-image
D
apiVersion: v1
kind: Pod
metadata:
  name: labeled-pod
  labels:
    app: myapp
    environment: production
spec:
  containers:
  - name: app
    image: myapp-image
Attempts:
2 left
💡 Hint
Labels should be under metadata and use clear key names.