A container and Kubernetes lab

Install Docker (or Podman) and a small local Kubernetes cluster so you can build images, run containers, write manifests and practise deployments and pipelines on your own computer.

  • Time: 45 to 60 minutes
  • Cost: free software, your own computer

What you need

A container engine builds and runs containers. On Linux, install Docker Engine (docs.docker.com) or Podman (podman.io), which is free and works with the same commands. On Windows and macOS the usual choice is Docker Desktop (read its licence terms: it is free for personal learning and small businesses, but larger companies need a paid plan) or the fully free Rancher Desktop or Podman Desktop.

For Kubernetes you do not need a cloud account. A local cluster in containers is enough: kind (kind.sigs.k8s.io), minikube (minikube.sigs.k8s.io) or k3d, driven by the kubectl command line (kubernetes.io/docs/tasks/tools).

Set it up

  1. Install the container engine and confirm it runs: docker run --rm hello-world prints a greeting.
  2. Install kubectl, then a local cluster. With kind: kind create cluster --name lab. With minikube: minikube start.
  3. Confirm the cluster: kubectl get nodes shows a node in the Ready state.
  4. Build your first image. Create a Dockerfile for a tiny app, then:
docker build -t demo:1.0 .
docker run --rm -p 8080:3000 demo:1.0
  1. Load the image into kind (kind load docker-image demo:1.0 --name lab) and apply a Deployment manifest with kubectl apply -f deployment.yaml. Expose it with kubectl port-forward deploy/demo 8080:3000.
  2. For pipelines, push your project to GitHub and add a workflow file under .github/workflows/; public repositories get free automation minutes (check current limits).

Check that it works

  • docker ps lists a running container and curl localhost:8080 answers.
  • kubectl get pods shows your pods Running, and kubectl rollout status deploy/demo ends with “successfully rolled out”.
  • kubectl describe pod <name> shows events; break the image name on purpose and watch ErrImagePull appear, then fix it.

Practise safely

  • Containers share your computer’s resources. Set limits (docker run --memory 256m) so a runaway container does not freeze your machine.
  • Do not run containers with --privileged or mount your home directory unless the exercise needs it.
  • Never put secrets in a Dockerfile or an image; images are easy to inspect. Use environment variables or Kubernetes Secrets, and keep real credentials out of a lab.
  • Clean up regularly: docker system prune removes unused data, and kind delete cluster --name lab removes the cluster.
  • Pull base images from official sources and pin their versions.

Go further

  • Make the image smaller with a multi-stage build and a slim base, and compare sizes with docker images.
  • Add health probes, resource requests and limits, and a rolling update strategy to your Deployment, then update the image and watch Kubernetes replace pods one at a time.
  • Cause each common failure on purpose (a wrong image tag, a missing secret, a probe on the wrong port, too little memory) and read kubectl describe to find it.
  • Build a pipeline that tests, builds an image on every push and deploys to your local cluster when you tag a release.

Courses that use this lab

Other lab guides

Software changes quickly. Menu names and version numbers may differ a little from what you see; the ideas and the check at the end of each section stay the same. Always download from the project's own website, and read the licence terms for your situation.