0
0
Kubernetesdevops~20 mins

Creating Deployments with YAML in Kubernetes - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Deployment YAML Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of kubectl apply with a Deployment YAML
You run kubectl apply -f deployment.yaml with this YAML content:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: nginx
        image: nginx:1.21
        ports:
        - containerPort: 80

What is the expected output of the command?
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: nginx
        image: nginx:1.21
        ports:
        - containerPort: 80
Aerror: unable to recognize "deployment.yaml"
Bpod/myapp created
Cservice/myapp created
Ddeployment.apps/myapp created
Attempts:
2 left
💡 Hint
Think about what resource type is defined in the YAML and what kubectl reports after applying it.
Configuration
intermediate
2:00remaining
Correct label selector in Deployment YAML
You want to create a Deployment that manages pods labeled app: frontend. Which selector field in the Deployment spec correctly matches these pods?
A
selector:
  matchLabels:
    app: frontend
B
selector:
  matchLabels:
    app: backend
C
selector:
  matchExpressions:
  - key: app
    operator: NotIn
    values:
    - frontend
D
selector:
  matchLabels:
    tier: frontend
Attempts:
2 left
💡 Hint
The selector must exactly match the labels on the pods you want to manage.
Troubleshoot
advanced
2:00remaining
Why does this Deployment fail to create pods?
You apply this Deployment YAML but no pods are created:
apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-deploy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test-app
    spec:
      containers:
      - name: busybox
        image: busybox
        command: ['sleep', '3600']

What is the most likely reason pods are not created?
AThe selector labels do not match the pod template labels
BThe container image 'busybox' does not exist
CThe replicas field must be a string, not a number
DThe command field is invalid syntax
Attempts:
2 left
💡 Hint
Check if the selector labels and pod labels are exactly the same.
🔀 Workflow
advanced
3:00remaining
Order the steps to update a Deployment image safely
Put these steps in the correct order to update a Deployment's container image with zero downtime:
A2,1,3,4
B1,2,4,3
C1,4,2,3
D4,1,2,3
Attempts:
2 left
💡 Hint
Think about editing first, then applying, then monitoring rollout, then verifying pods.
Best Practice
expert
2:30remaining
Best practice for specifying resource requests in Deployment YAML
Which option shows the best practice for specifying CPU and memory resource requests and limits in a container spec within a Deployment YAML?
A
resources:
  cpu: 500
  memory: 256
B
resources:
  requests:
    cpu: 500m
    memory: 256Mi
  limits:
    cpu: 1
    memory: 512Mi
C
resources:
  requests:
    cpu: "500m"
    memory: "256Mi"
  limits:
    cpu: "1"
    memory: "512Mi"
D
resources:
  requests:
    cpu: 0.5
    memory: 256
  limits:
    cpu: 1
    memory: 512
Attempts:
2 left
💡 Hint
Resource values must be strings with units like 'm' for millicores and 'Mi' for memory.