Stage 7 · Master
CKAD — Certified Kubernetes Application Developer
Application Design & Build (20%)
Multi-container pods, init containers, jobs, and volumes — building cloud-native applications.
Multi-Container Pods
Multi-container Pods run multiple containers as a single unit. The containers share networking (localhost) and storage volumes. This enables patterns like sidecar, ambassador, and adapter.
| Pattern | Purpose | Example |
|---|---|---|
| Sidecar | Extend or augment the main container | Log collector, proxy, monitoring agent |
| Ambassador | Proxy network connections | Database proxy, service mesh sidecar |
| Adapter | Standardize output format | Log formatting, metrics conversion |
apiVersion: v1
kind: Pod
metadata:
name: multi-container
spec:
containers:
- name: main
image: nginx
volumeMounts:
- name: shared-data
mountPath: /usr/share/nginx/html
- name: sidecar
image: busybox
command: ["sh", "-c", "while true; do date >> /shared/index.html; sleep 10; done"]
volumeMounts:
- name: shared-data
mountPath: /shared
volumes:
- name: shared-data
emptyDir: {}The main container serves content from the shared volume. The sidecar container appends timestamps to the same shared volume. They communicate through the filesystem.
Init Containers
Init Containers run before the main application containers start. They are useful for setup tasks like waiting for a dependency, downloading configuration, or running database migrations.
apiVersion: v1
kind: Pod
metadata:
name: my-app
spec:
initContainers:
- name: wait-for-db
image: busybox
command: ['sh', '-c', 'until nslookup my-db; do echo waiting for db; sleep 2; done']
containers:
- name: app
image: my-app:1.0The init container runs to completion before the main container starts. If it fails, Kubernetes restarts it. Use init containers to handle dependencies that may not be ready immediately.
Jobs and CronJobs
Jobs create one or more Pods and ensure that a specified number of them successfully terminate. CronJobs run Jobs on a schedule. Both are essential for batch processing and periodic tasks.
# Create a Job
kubectl create job my-job --image=busybox -- echo "Hello from the job"
# Create a CronJob
kubectl create cronjob my-cron --image=busybox --schedule="0 */6 * * *" -- echo "Every 6 hours"
# Check job status
kubectl get jobs
kubectl describe job my-job
kubectl logs job/my-jobThe --schedule flag uses standard cron syntax: minute hour day-of-month month day-of-week. The Job creates Pods that run the command to completion.
Volumes in Pods
Volumes provide persistent or ephemeral storage for containers. On the CKAD, you need to know how to mount volumes and understand the different volume types.
- emptyDir — Ephemeral, deleted when Pod is removed. Good for caches and scratch space.
- hostPath — Mounts node filesystem. Security risk in production.
- configMap — Mount ConfigMap data as files.
- secret — Mount Secret data as files.
- persistentVolumeClaim — Mount a PVC for durable storage.
spec:
containers:
- name: app
image: nginx
volumeMounts:
- name: config-volume
mountPath: /etc/nginx/conf.d
readOnly: true
- name: data-volume
mountPath: /usr/share/nginx/html
volumes:
- name: config-volume
configMap:
name: nginx-config
- name: data-volume
persistentVolumeClaim:
claimName: my-pvcVolume mounts reference volumes by name. The mountPath is where the volume appears inside the container. The readOnly flag prevents the container from modifying the volume.
Dockerfile Best Practices
Understanding Dockerfiles helps you build efficient container images. On the CKAD, you may need to build images, understand layers, and optimize for size and security.
FROM golang:1.21 AS builder
WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . .
RUN CGO_ENABLED=0 go build -o server .
FROM gcr.io/distroless/static
COPY --from=builder /app/server /
CMD ["/server"]Multi-stage builds reduce image size dramatically. The builder stage compiles the Go binary. The final stage uses a minimal distroless image with only the binary. No Go toolchain, no source code in the final image.
Practice building Docker images with docker build and pushing to registries. Know how to use --build-arg for build-time variables and how to use multi-stage builds to reduce image size.
Key Commands
kubectl get pods -o wide
kubectl describe pod my-pod
kubectl logs my-pod -c my-container
kubectl exec -it my-pod -- /bin/sh
kubectl get jobs
kubectl get cronjobs
kubectl create job my-job --image=busybox -- echo hello
kubectl create cronjob my-cron --image=busybox --schedule="*/5 * * * *" -- echo helloUse -c to specify a container in multi-container Pods. Use kubectl logs job/<name> to see Job output. These commands are fundamental for CKAD troubleshooting.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.