Part 2 · Exercises

Part 2 Exercises

Hands-on practice for Docker, CI/CD, Kubernetes, and ArgoCD.

These exercises test your understanding of Part 2. Some require you to write code or configuration; others ask you to explain concepts in your own words. Read each problem carefully before you write a single line — understanding what is being asked is half the work.

💡 How to Use These Exercises

For hands-on exercises, create a dedicated directory on your machine and actually run the commands. The goal is not to write the right answer on paper — it is to develop muscle memory by doing the thing for real. For conceptual questions, try to explain the answer out loud to yourself before writing it down. If you cannot explain it out loud simply, you do not understand it yet — and that is valuable information.

Exercise 1
Write a Dockerfile for a Python Flask App

You have a Python Flask application. The entry point is app.py and the dependencies are listed in requirements.txt. The application listens on port 5000.

Write a complete Dockerfile that:

  • Uses python:3.12-slim as the base image
  • Sets a working directory of /app
  • Copies requirements.txt first (before copying the source code — why does this order matter?)
  • Installs dependencies with pip install --no-cache-dir -r requirements.txt
  • Copies the rest of the application code
  • Exposes port 5000
  • Starts the app with python app.py

After writing the Dockerfile, explain in one sentence why you copy requirements.txt before copying the source code.

Exercise 2
Build and Run Your Container Locally

Using the Dockerfile you wrote in Exercise 1, complete the following steps:

  1. Build the Docker image and tag it flask-app:v1.
  2. Run the container in detached mode, mapping your machine's port 8080 to the container's port 5000. Give the container the name flask-demo.
  3. Visit http://localhost:8080 in your browser to verify it works.
  4. View the container logs.
  5. Open a shell inside the running container and list the files in /app.
  6. Stop and remove the container.

Write out the exact commands you would run for each of the six steps.

Exercise 3
Image vs Container — What's the Difference?

In your own words (two to three sentences each), explain:

  • What is a Docker image? Use an analogy that doesn't involve food if you can think of one.
  • What is a Docker container? What is its relationship to an image?
  • Can you have ten containers running from the same image? What would happen if you deleted all the containers — would the image be affected?
Exercise 4
Write a docker-compose.yml for an App with a Database

Write a docker-compose.yml file that defines:

  • A service called api that builds from a local Dockerfile and listens on port 4000 (mapped to host port 4000).
  • A service called db using the postgres:16-alpine image with environment variables for POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB.
  • A named volume called pgdata mounted at /var/lib/postgresql/data inside the db container.
  • The api service should declare that it depends on the db service.
  • An environment variable DATABASE_URL in the api service that points to the db service using the service name as the hostname.

What single command would you run to start both services in the background? What command stops and removes the containers but preserves the volume data?

Exercise 5
Create a GitHub Actions Workflow That Runs Tests

Create a file at .github/workflows/ci.yml in a project repository. The workflow should:

  • Trigger on every push to any branch and on every pull request targeting main.
  • Have a single job called test that runs on ubuntu-latest.
  • Set up Node.js version 20 with npm caching enabled.
  • Run npm ci to install dependencies.
  • Run npm test to execute the tests.

Write the complete YAML file. Make sure the indentation is correct — YAML is whitespace-sensitive and a single wrong indentation will break the workflow.

Exercise 6
GitHub Actions Triggers — When Does a Workflow Run?

For each of the following scenarios, write the correct on: trigger block in a GitHub Actions workflow YAML:

  1. Run on every push to the main branch only.
  2. Run on every pull request targeting main or develop.
  3. Run every day at midnight UTC (use a cron schedule).
  4. Run only when manually triggered from the GitHub UI (no automatic trigger).
  5. Run on pushes to main AND on pull requests to main (combine them in one block).
Exercise 7
CI vs CD — Explain the Difference

A colleague tells you: "We have CI/CD. Our tests run automatically." You suspect they only have CI, not CD. Explain to them, in plain language:

  • What Continuous Integration means, and what it does.
  • What Continuous Delivery adds on top of CI.
  • What Continuous Deployment means, and how it differs from Continuous Delivery.
  • What question you would ask them to determine which of the three they actually have.
Exercise 8
Write a Kubernetes Deployment for nginx

Write a complete Kubernetes Deployment manifest with the following requirements:

  • Name: nginx-web
  • Namespace: default
  • 3 replicas
  • Container image: nginx:1.25-alpine
  • Container port: 80
  • Resource requests: 64Mi memory, 100m CPU
  • Resource limits: 128Mi memory, 200m CPU
  • A label app: nginx-web on both the Deployment and the Pod template

After writing the manifest, write the single kubectl command you would use to apply it to a running cluster.

Exercise 9
Kubernetes kubectl — Reading Pod Logs

You have deployed an application to Kubernetes. The Pod name is api-server-7d4f9b-xk2pq and it is in the production namespace. Write the exact kubectl command for each scenario:

  1. View the current (non-streaming) logs for this Pod.
  2. Follow the logs in real time (streaming).
  3. View logs from the previous container instance (it crashed and was restarted — you want to see what happened before the crash).
  4. View only the last 50 lines of logs.
  5. Open an interactive shell inside the running Pod.
Exercise 10
What Does a Kubernetes Service Do?

Imagine you explain Kubernetes Services to a new developer who has never used Kubernetes before. Write a clear explanation (3-5 sentences) that covers:

  • Why Pods alone cannot serve as stable network endpoints (think: what happens to a Pod's IP address when it is restarted?).
  • What a Service does to solve this problem.
  • How a Service knows which Pods to route traffic to (hint: labels).
  • The difference between a ClusterIP Service (internal only) and a LoadBalancer Service (internet-facing).
Exercise 11
What is GitOps — and Why Is It Better Than Manual kubectl?

A senior engineer at your company is skeptical of GitOps. "Why do I need ArgoCD? I can just run kubectl apply from my CI pipeline," they say.

Write a response that explains:

  • What GitOps means (one clear sentence definition).
  • Three specific problems with pushing from CI directly via kubectl apply — focus on real operational pain: drift, rollback, audit trail, disaster recovery.
  • How ArgoCD's selfHeal and prune settings address those problems.
  • One legitimate scenario where running kubectl directly (bypassing GitOps) might be acceptable.
Exercise 12
Liveness vs Readiness Probes — What's the Difference?

Both liveness and readiness probes are defined in the same container spec, and both make HTTP calls to your application. But they do very different things when they fail.

Explain each of the following scenarios by choosing the correct probe type and justifying your answer:

  1. Your application has just started and is running database migrations. It will take 20 seconds before it is ready to accept HTTP requests. During this time, you do not want any traffic routed to it — but you also do not want Kubernetes to restart it. Which probe type handles this? What values would you set for initialDelaySeconds?
  2. Your application has been running for three hours and has entered a deadlock — the process is alive and the port is open, but every request hangs forever. You want Kubernetes to detect this and restart the container. Which probe type handles this?
  3. Your application's /health endpoint returns 200 even when the database connection pool is exhausted. Your /ready endpoint returns 503 in that case. Explain why having both endpoints return different values is architecturally correct.
📊 Bonus Challenge: End-to-End Pipeline

If you have completed all twelve exercises, try building a complete pipeline from scratch: create a simple web application (even just a static HTML page served by nginx), write a Dockerfile, push it to GitHub, create a GitHub Actions workflow that builds and pushes the Docker image to GitHub Container Registry on every push to main, write Kubernetes manifests for the Deployment and Service, and install minikube locally to apply them. When you can see your HTML page through a port-forwarded Kubernetes Service, you have connected every concept in Part 2 in a single working system.