Deployments & Workloads Practice Questions
DaemonSets
Question 1: Basic DaemonSet
Objective: Create a DaemonSet that runs on all worker nodes.
Requirements:
- Namespace:
logging - Name:
fluentd - Image:
fluentd:v1.16 - Mount
/var/logfrom host to/var/login container - Resource requests: CPU 100m, Memory 200Mi
Verify:
kubectl get ds fluentd -n logging
kubectl get pods -n logging -o wideQuestion 2: DaemonSet with Node Selector
Objective: Run DaemonSet only on nodes with specific label.
Requirements:
- Namespace:
monitoring - Name:
node-exporter - Image:
prom/node-exporter:latest - Run only on nodes labeled
monitoring=enabled
Verify:
kubectl get ds -n monitoring
kubectl get pods -n monitoring -o wideQuestion 3: DaemonSet on All Nodes (Including Control Plane)
Objective: Run DaemonSet on ALL nodes including control plane.
Requirements:
- Namespace:
system - Name:
log-collector - Image:
busybox:1.36 - Command:
sh -c "tail -f /var/log/syslog" - Add tolerations for control plane taints
Verify:
kubectl get pods -n system -o wide
# Should see pod on control plane nodeProbes
Question 4: Liveness Probe
Objective: Add liveness probe to detect stuck container.
Requirements:
- Name:
web-app - Image:
nginx - Liveness probe: HTTP GET on
/healthzport 80 - Initial delay: 10s, Period: 5s
Verify:
kubectl describe pod web-app | grep -A5 "Liveness"Question 5: Readiness Probe
Objective: Add readiness probe so pod only receives traffic when ready.
Requirements:
- Name:
api-server - Image:
nginx - Readiness probe: TCP socket on port 80
- Initial delay: 5s, Period: 10s
Verify:
kubectl describe pod api-server | grep -A5 "Readiness"Question 6: Startup Probe
Objective: Add startup probe for slow-starting application.
Requirements:
- Name:
slow-app - Image:
busybox:1.36 - Command:
sh -c "sleep 30 && nc -lk -p 8080" - Startup probe: TCP socket on port 8080
- Failure threshold: 30, Period: 10s
Verify:
kubectl describe pod slow-app | grep -A5 "Startup"Init Containers
Question 7: Wait for Service
Objective: Use init container to wait for a service before starting main container.
Requirements:
- Name:
app-with-init - Init container: busybox, wait for
db-svcDNS resolution - Main container: nginx
Verify:
kubectl get pod app-with-init
kubectl logs app-with-init -c init-waitQuestion 8: Init Container with Shared Volume
Objective: Use init container to prepare data for main container.
Requirements:
- Name:
prepared-app - Init container: busybox, write "initialized" to
/data/status - Main container: nginx, mount same volume to
/usr/share/nginx/html - Use emptyDir volume
Verify:
kubectl exec prepared-app -- cat /usr/share/nginx/html/statusResources & QoS
Question 9: Guaranteed QoS Pod
Objective: Create a pod with Guaranteed QoS class.
Requirements:
- Name:
guaranteed-pod - Image: nginx
- Requests AND Limits: CPU 100m, Memory 128Mi (must be equal)
Verify:
kubectl get pod guaranteed-pod -o jsonpath='{.status.qosClass}'
# Should output: GuaranteedQuestion 10: Burstable QoS Pod
Objective: Create a pod with Burstable QoS class.
Requirements:
- Name:
burstable-pod - Image: nginx
- Requests: CPU 100m, Memory 128Mi
- Limits: CPU 500m, Memory 512Mi
Verify:
kubectl get pod burstable-pod -o jsonpath='{.status.qosClass}'
# Should output: BurstableSecurity Context
Question 11: Run as Non-Root
Objective: Create pod that runs as non-root user.
Requirements:
- Name:
secure-pod - Image: busybox
- Command:
sh -c "id && sleep 3600" - Run as user 1000, group 3000
- Prevent privilege escalation
Verify:
kubectl exec secure-pod -- id
# Should show uid=1000 gid=3000Question 12: Read-Only Root Filesystem
Objective: Create pod with read-only root filesystem.
Requirements:
- Name:
readonly-pod - Image: nginx
- Read-only root filesystem
- Mount emptyDir to
/tmpand/var/cache/nginxfor writable directories
Verify:
kubectl exec readonly-pod -- touch /test
# Should fail with "Read-only file system"Downward API
Question 13: Pod Info as Environment Variables
Objective: Expose pod metadata as environment variables.
Requirements:
- Name:
downward-env - Image: busybox
- Command:
sh -c "printenv && sleep 3600" - Env vars: POD_NAME, POD_NAMESPACE, POD_IP, NODE_NAME
Verify:
kubectl exec downward-env -- printenv | grep PODQuestion 14: Pod Info as Volume Files
Objective: Mount pod labels and annotations as files.
Requirements:
- Name:
downward-volume - Labels:
app=demo,tier=frontend - Mount labels to
/etc/podinfo/labels - Mount annotations to
/etc/podinfo/annotations
Verify:
kubectl exec downward-volume -- cat /etc/podinfo/labelsDeployments
Question 15: Create Deployment with Rolling Update
Objective: Create deployment with specific rolling update strategy.
Requirements:
- Namespace:
web - Name:
frontend - Image:
nginx:1.20 - Replicas: 4
- Strategy: RollingUpdate, maxSurge=1, maxUnavailable=0
Verify:
kubectl describe deployment frontend -n web | grep -A5 "Strategy"Question 16: Update Image and Rollback
Objective: Update deployment image and rollback.
Requirements:
- Update
frontenddeployment tonginx:1.21 - Check rollout status
- Rollback to previous version
Verify:
kubectl rollout history deployment/frontend -n web
kubectl get deployment frontend -n web -o jsonpath='{.spec.template.spec.containers[0].image}'Question 17: Scale Deployment
Objective: Scale deployment to different replica count.
Requirements:
- Scale
frontenddeployment to 6 replicas - Then scale down to 2 replicas
Verify:
kubectl get deployment frontend -n webPod Disruption Budget
Question 18: Create PDB
Objective: Create PDB to ensure minimum availability.
Requirements:
- Name:
web-pdb - Selector:
app=frontend - Minimum available: 2
Verify:
kubectl get pdb web-pdb
kubectl describe pdb web-pdbEnvironment Variables
Question 19: Multiple Env Sources
Objective: Create pod with env vars from multiple sources.
Prerequisites:
kubectl create configmap app-config --from-literal=APP_ENV=production
kubectl create secret generic db-creds --from-literal=password=secret123Requirements:
- Name:
multi-env-pod - All keys from
app-configas env vars DB_PASSWORDfrom secretdb-credskeypassword- Static env var:
LOG_LEVEL=info
Verify:
kubectl exec multi-env-pod -- printenvVolumes
Question 20: Sidecar with Shared Volume
Objective: Create pod with two containers sharing an emptyDir volume.
Requirements:
- Name:
sidecar-pod - Container 1 (writer): busybox, write date to
/logs/app.logevery 5 seconds - Container 2 (reader): busybox, tail the log file
- Shared emptyDir volume mounted to
/logs
Verify:
kubectl logs sidecar-pod -c readerSolutions Reference
Question 1 Solution
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: fluentd
namespace: logging
spec:
selector:
matchLabels:
app: fluentd
template:
metadata:
labels:
app: fluentd
spec:
containers:
- name: fluentd
image: fluentd:v1.16
resources:
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
volumes:
- name: varlog
hostPath:
path: /var/logQuestion 3 Solution (Tolerations)
spec:
tolerations:
- key: node-role.kubernetes.io/control-plane
effect: NoSchedule
- key: node-role.kubernetes.io/master
effect: NoScheduleQuestion 9 Solution (Guaranteed QoS)
apiVersion: v1
kind: Pod
metadata:
name: guaranteed-pod
spec:
containers:
- name: app
image: nginx
resources:
requests:
cpu: "100m"
memory: "128Mi"
limits:
cpu: "100m"
memory: "128Mi"Question 11 Solution (Security Context)
apiVersion: v1
kind: Pod
metadata:
name: secure-pod
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
containers:
- name: app
image: busybox
command: ["sh", "-c", "id && sleep 3600"]
securityContext:
allowPrivilegeEscalation: falseQuestion 13 Solution (Downward API)
apiVersion: v1
kind: Pod
metadata:
name: downward-env
spec:
containers:
- name: app
image: busybox
command: ["sh", "-c", "printenv && sleep 3600"]
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeNameQuestion 15 Solution (Deployment)
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend
namespace: web
spec:
replicas: 4
strategy:
type: RollingUpdate
rollingUpdate:
maxSurge: 1
maxUnavailable: 0
selector:
matchLabels:
app: frontend
template:
metadata:
labels:
app: frontend
spec:
containers:
- name: nginx
image: nginx:1.20Question 16 Solution (Rollout)
kubectl set image deployment/frontend nginx=nginx:1.21 -n web
kubectl rollout status deployment/frontend -n web
kubectl rollout undo deployment/frontend -n webQuestion 18 Solution (PDB)
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: web-pdb
spec:
minAvailable: 2
selector:
matchLabels:
app: frontend