DevOps.Academy
CoursesCurriculumInterview prepPricing
◔My learningSign in
DevOps.Academy

Free, hands-on DevOps lessons. Made with care in India.

System status

Learn

All coursesLinux roadmapCurriculumInterview questionsCheat sheetsMy learning

Academy

PricingCertificates

Legal

PrivacyTermsContact

devops.rajeev.pro

Kubernetes & HelmLesson 2 of 16
Your progress · 0%
On this page
  1. An image built for Kubernetes
  2. Push it to a registry
↖ Course roadmap
Lesson 2 · Containers refresher

Images and registries for Kubernetes

The container knowledge Kubernetes assumes: building a small, non-root image, tagging it properly, and pushing it to a registry the cluster can pull from, with a real push to Amazon ECR.

20 min read · intermediate · hands-on

By the end of this lesson you'll be able to

0 of 4 complete
Lab status

Verified lab: the shop-web image built with Docker and pushed to a real Amazon ECR repository in ap-south-1. The output shown is real.
Code walkthrough: none.
Cloud lab: ECR needs an AWS account (storage is a few cents per GB-month).

Kubernetes runs containers; it doesn't build them. Before a cluster can run your app, the app has to be an image in a registry the nodes can reach. The Docker course covers images in depth. This lesson is the short version Kubernetes needs, and it builds the shop-web app that every later lesson deploys.

An image built for Kubernetes

shop-web is a tiny Python web server. It answers / with a page, /api with JSON saying which version and which Pod answered, /healthz for health checks, and /burn to use CPU in the autoscaling lesson. The Dockerfile:

FROM python:3.13-alpine
WORKDIR /app
COPY app.py .
RUN adduser -D -u 10001 app
USER 10001
EXPOSE 8080
ARG APP_VERSION=v1
ENV APP_VERSION=$APP_VERSION
CMD ["python", "app.py"]

Four choices here matter later:

  1. A small base image (python:3.13-alpine). Smaller images pull faster when a Pod lands on a new node, which matters when autoscaling adds nodes under load.
  2. A non-root user (USER 10001). The Security lesson enforces the restricted Pod Security standard; images that need root fail it.
  3. A fixed port (EXPOSE 8080). The Service and health checks in later lessons point at 8080.
  4. The version comes from the build (ARG APP_VERSION), so /api reports which version a Pod runs. That makes rollouts and rollbacks visible.

The lab built three images: v1, v2, and v3-broken, which exits on start with config error: DATABASE_URL is not set. You'll use v3-broken to see a failed rollout, a CrashLoopBackOff and a Helm rollback.

Tags, not latest

Every Kubernetes manifest in this course names an exact tag: shop-web:v1. With :latest, two nodes that pulled at different times can run different code under the same name, and "roll back to the previous version" has no meaning. Tag every build with a version or the Git commit SHA, and never reuse a tag.

Same tag name, different code: what latest does to two nodes that pull a few hours apart.© Diagram: DevOps Academy

Same tag name, different code: what latest does to two nodes that pull a few hours apart.© Diagram: DevOps Academy

Push it to a registry

A registry stores images; nodes pull from it. Docker Hub is public by default. For your own apps, use a private registry next to your cluster: Amazon ECR on AWS.

Push once, pull on every node that runs the Pod. The node's IAM role is what lets it pull from ECR.© Diagram: DevOps Academy

Push once, pull on every node that runs the Pod. The node's IAM role is what lets it pull from ECR.© Diagram: DevOps Academy

The lab created one:

$ aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=true
{
    "name": "shop-web",
    "uri": "626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web",
    "scanOnPush": true
}
aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=true
  • awsthe AWS command line

scanOnPush makes ECR scan every pushed image for known vulnerabilities. The URI has three parts: the account ID, the region, and the repository name. That full URI, plus a tag, is what goes in your Pod specs.

Log Docker in to ECR (the password is a short-lived token), tag, and push:

$ aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 626159997645.dkr.ecr.ap-south-1.amazonaws.com
Login Succeeded
$ docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v1
$ docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v2
$ docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-broken
$ aws ecr describe-images --repository-name shop-web
---------------------------------------------------------------
|                       DescribeImages                        |
+-----------------------------------+-----------+-------------+
|              pushed               |  sizeMB   |     tag     |
+-----------------------------------+-----------+-------------+
|  2026-11-09T05:40:15.891000+00:00 |  16943891 |  None       |
|  2026-11-09T05:40:15.900000+00:00 |  1166     |  None       |
...
|  2026-11-09T05:40:20.282000+00:00 |  16944155 |  v3-broken  |
|  2026-11-09T05:40:18.329000+00:00 |  16943891 |  v2         |
|  2026-11-09T05:40:16.233000+00:00 |  16943891 |  v1         |
+-----------------------------------+-----------+-------------+
aws ecr get-login-password --region ap-south-1 | docker login --username AWS --password-stdin 626159997645.dkr.ecr.ap-south-1.amazonaws.com
  • awsthe AWS command line
  • --regionwhich Region
  • |pipe: send output to the next command
  • dockerbuild and run containers
  • loginsign in to a registry
docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v1
  • pushupload an image to a registry
  • 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v1the image
docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v2
  • 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v2the image
docker push 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-broken
  • 626159997645.dkr.ecr.ap-south-1.amazonaws.com/shop-web:v3-brokenthe image

(The sizeMB column is really bytes: about 17 MB compressed, against 70 MB locally.) The untagged entries surprise people: Docker's build tooling attaches attestations (provenance records of how the image was built) and a multi-platform index, which the registry stores as separate manifests. They're expected, not junk.

How nodes get permission to pull

ECR repositories are private. On EKS, the worker node group's IAM role carries the AmazonEC2ContainerRegistryReadOnly policy, so the kubelet on each node can pull from ECR in the same account with no password stored anywhere. For other private registries (GitHub Container Registry, a Docker Hub private repo), you create a Secret of type kubernetes.io/dockerconfigjson and reference it in the Pod spec as imagePullSecrets.

When a pull fails, the Pod shows ErrImagePull, then ImagePullBackOff. The Monitoring lesson reproduces it with a tag that doesn't exist.

⌘
Mini mission

Publish an image your cluster can pull

Build shop-web as v1 and v2 (different APP_VERSION build args), create a private repository with scan on push, push both tags, and list them. Record the repository URI and both image digests.

Input: The Dockerfile and app from this lessonOutput: ~/registry.txt
Reveal one safe solution
$ docker build -t shop-web:v1 --build-arg APP_VERSION=v1 .
$ docker build -t shop-web:v2 --build-arg APP_VERSION=v2 .
$ aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=true
$ REG=<account>.dkr.ecr.<region>.amazonaws.com
$ aws ecr get-login-password | docker login --username AWS --password-stdin $REG
$ for t in v1 v2; do docker tag shop-web:$t $REG/shop-web:$t && docker push $REG/shop-web:$t; done
$ aws ecr describe-images --repository-name shop-web --query 'imageDetails[].[imageTags[0],imageDigest]' --output text > ~/registry.txt
docker build -t shop-web:v1 --build-arg APP_VERSION=v1 .
  • dockerbuild and run containers
  • buildbuild an image from a Dockerfile
  • -t shop-web:v1name and tag the image
  • --build-arg APP_VERSION=v1a build argument (visible in history)
  • .the build context: the files COPY can see
docker build -t shop-web:v2 --build-arg APP_VERSION=v2 .
  • -t shop-web:v2name and tag the image
  • --build-arg APP_VERSION=v2a build argument (visible in history)
aws ecr create-repository --repository-name shop-web --image-scanning-configuration scanOnPush=true
  • awsthe AWS command line
aws ecr get-login-password | docker login --username AWS --password-stdin $REG
  • |pipe: send output to the next command
  • loginsign in to a registry
for t in v1 v2; do docker tag shop-web:$t $REG/shop-web:$t && docker push $REG/shop-web:$t; done
  • forloop over a list
  • dostart of what the loop runs each time
  • taggive an image another name
  • shop-web:$tthe image, then its new name
  • $REG/shop-web:$tthe image, then its new name
  • &&run the next command only if this one worked
  • pushupload an image to a registry
  • $REG/shop-web:$t;the image
  • doneend of the loop
aws ecr describe-images --repository-name shop-web --query 'imageDetails[].[imageTags[0],imageDigest]' --output text > ~/registry.txt
  • --querypick fields from the JSON response
  • --outputoutput format
  • >write output to a file, replacing it

You should see v1 and v2 with digests (and possibly untagged attestation entries). No AWS account? Push to Docker Hub or GitHub Container Registry instead; the Kubernetes side is the same, with an imagePullSecret.

Try it yourself

0 of 5 steps done

Run each task in your own account or terminal, then tick it off.

Knowledge check

Quick check

Question 1 of 3

Why should Kubernetes manifests use image tags like v2 instead of latest?

Go deeper

Official reading for this lesson

  • DocsImages (Kubernetes concepts)Kubernetes ↗
  • DocsAmazon ECR user guideAWS Docs ↗
  • DocsUsing Amazon ECR images with Amazon EKSAWS Docs ↗
  • DocsPull an image from a private registryKubernetes ↗

Or get every quiz answer right and it completes itself.

Something unclear, wrong or out of date in this lesson? Tell me, and I'll fix it.

← PreviousKubernetes: what it solves, and when you don't need itNext lesson →Setting up: a cluster, kubectl and your first deployment