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.
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.
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-slimas the base image - Sets a working directory of
/app - Copies
requirements.txtfirst (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.
Using the Dockerfile you wrote in Exercise 1, complete the following steps:
- Build the Docker image and tag it
flask-app:v1. - 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. - Visit
http://localhost:8080in your browser to verify it works. - View the container logs.
- Open a shell inside the running container and list the files in
/app. - Stop and remove the container.
Write out the exact commands you would run for each of the six steps.
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?
Write a docker-compose.yml file that defines:
- A service called
apithat builds from a local Dockerfile and listens on port 4000 (mapped to host port 4000). - A service called
dbusing thepostgres:16-alpineimage with environment variables forPOSTGRES_USER,POSTGRES_PASSWORD, andPOSTGRES_DB. - A named volume called
pgdatamounted at/var/lib/postgresql/datainside thedbcontainer. - The
apiservice should declare that it depends on thedbservice. - An environment variable
DATABASE_URLin theapiservice that points to thedbservice 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?
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
testthat runs onubuntu-latest. - Set up Node.js version 20 with npm caching enabled.
- Run
npm cito install dependencies. - Run
npm testto 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.
For each of the following scenarios, write the correct on: trigger
block in a GitHub Actions workflow YAML:
- Run on every push to the
mainbranch only. - Run on every pull request targeting
mainordevelop. - Run every day at midnight UTC (use a cron schedule).
- Run only when manually triggered from the GitHub UI (no automatic trigger).
- Run on pushes to
mainAND on pull requests tomain(combine them in one block).
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.
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:
64Mimemory,100mCPU - Resource limits:
128Mimemory,200mCPU - A label
app: nginx-webon 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.
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:
- View the current (non-streaming) logs for this Pod.
- Follow the logs in real time (streaming).
- View logs from the previous container instance (it crashed and was restarted — you want to see what happened before the crash).
- View only the last 50 lines of logs.
- Open an interactive shell inside the running Pod.
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
ClusterIPService (internal only) and aLoadBalancerService (internet-facing).
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
selfHealandprunesettings address those problems. - One legitimate scenario where running kubectl directly (bypassing GitOps) might be acceptable.
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:
- 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? - 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?
- Your application's
/healthendpoint returns 200 even when the database connection pool is exhausted. Your/readyendpoint returns 503 in that case. Explain why having both endpoints return different values is architecturally correct.
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.