Kubernetes · Chapter 28 of 28

Capstone: Jhatpat opens in Kanpur

By the end of this chapter you have built Jhatpat's whole stack for a new city on your own, from an empty namespace: its databases with their own disks, four services with probes and resources, one front door, walls between the services, and room to grow on Dhanteras evening, and proved each layer before you built the next. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Packaging and operating
  • 5 tasks
  • Kubernetes
  • In the all labs plan

The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.

Why you need this

Jhatpat opens in Kanpur after Diwali: 6 dark stores, in Swaroop Nagar, Kakadeo, Kidwai Nagar, Govind Nagar, Kalyanpur and Civil Lines, and the same promise of groceries in 10 minutes. Tushar is from Kanpur and has waited a year for this. Ritika has one condition: Kanpur's first festival evening must go better than Lucknow's did, so it opens with everything Lucknow learned this autumn already in place.

Until now every chapter gave you most of the cluster and asked for one new thing. A city does not arrive like that. Nobody hands you a namespace with the Service already there, or the Secret already right; the orders service will not even start until its database answers, and a policy you forget is a door left open. Ammar's plan: you build Kanpur alone, in ch28, from a checklist, and he only reads what you built.

What you build: 5 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    data.yaml: PostgreSQL and Redis with their own disks

    Build Kanpur's data tier: the database and the cache, each with its own disk.

    1. Open data.yaml in the chapter folder. Its notes list every name and number.

    2. Write the Secret kanpur-db with two keys: password (any password) and url, postgres://jhatpat:<that password>@postgres:5432/orders.

    3. Write the StatefulSet postgres and its headless Service postgres on port 5432. POSTGRES_PASSWORD comes from kanpur-db's key password.

    4. Write the StatefulSet redis and its Service redis on port 6379.

    5. Apply data.yaml. List the StatefulSets and the claims.

    To pass: in ch28, kanpur-db's url uses the same password as its password key. postgres has serviceName postgres, POSTGRES_USER jhatpat and POSTGRES_DB orders. Both StatefulSets have a claim template named data and a ready pod, and the claims data-postgres-0 and data-redis-0 are Bound.

  2. Task 2

    apps.yaml: four apps with probes and resources

    Run Kanpur's four apps, each with health checks and resources.

    1. Open apps.yaml. Its notes list the image and env of catalog, cart, orders and storefront.

    2. Write a Deployment for each: 2 replicas, the label app=<its name>, a readinessProbe and a livenessProbe, requests for cpu and memory, and a memory limit.

    3. Write the ConfigMap storefront-config with a BANNER that has Kanpur in it. orders takes DATABASE_URL from the Secret kanpur-db, key url.

    4. Write a Service for each app, with the same name: port 80 to the pods' 8080.

    5. Apply apps.yaml. Wait until every pod is ready.

    To pass: the four Deployments run the images in the notes, and every container has both probes, both requests and a memory limit. All pods are ready. The storefront page shows the Kanpur banner and products in kanpur, its /api/cart/c-42 answers 200, and orders answers /orders to a storefront pod.

  3. Task 3

    edge.yaml: the Ingress and the NetworkPolicies

    Open the shop to customers, and let each app talk only to what it needs.

    1. Write the Ingress kanpur (class nginx). It sends kanpur.jhatpat.in, path / (Prefix), to the Service storefront on port 80.

    2. Write the NetworkPolicy default-deny. It selects every pod, for Ingress, with no rules.

    3. Write allow policies (any names): ingress-nginx to storefront on 8080, storefront to catalog, cart and orders on 8080, cart to redis on 6379, and orders to postgres on 5432.

    4. Apply edge.yaml. Then run lab curl http://kanpur.jhatpat.in/ yourself.

    To pass: you ran lab curl http://kanpur.jhatpat.in/ and got the shop page through the Ingress. A storefront pod can reach catalog, cart and orders. A catalog pod cannot reach cart. Only cart may reach redis, and only orders may reach postgres: no policy lets every pod in.

  4. Task 4

    dhanteras.yaml: the HPA, the PDB and the rush

    Get ready for the Dhanteras rush, then send it.

    1. In dhanteras.yaml, write the HorizontalPodAutoscaler storefront (autoscaling/v2) for the Deployment storefront: 2 to 8 replicas at 60% average CPU utilization.

    2. Write the PodDisruptionBudget storefront: minAvailable 1, for the pods with app=storefront.

    3. Apply dhanteras.yaml. Then send load with lab load storefront and a number of requests a second.

    4. Watch the HPA until storefront has more than 2 replicas. Then stop the load.

    To pass: the HPA and the PDB are as above. You ran lab load storefront with a number above 0, and the command worked. The HPA's events show a SuccessfulRescale to a size above 2. Do not apply apps.yaml again after this: it sets storefront back to 2.

  5. Task 5 · interview question

    Interview: a request from a phone to the orders database

    Interview question: follow one request from a customer's phone in Kanpur to the orders database.

    1. Ammar will ask: "A customer in Kanpur taps Place order. Walk me through every hop to the orders database."

    2. Write every hop in a few sentences of your own, from the phone to postgres-0 and its disk.

    3. Say where a NetworkPolicy checks the request on the way.

    4. Save it in answer.txt, below the notes.

    To pass: answer.txt names the Ingress, the Services, storefront, orders, postgres and a NetworkPolicy. Lines that start with # do not count.

What you will learn

  • The order: why the data tier comes first, then the apps, then the edge, then autoscaling.
  • Proving each layer: the one or two commands that show it works before you build on it.
  • The walls: default deny, then exactly the paths the stack needs.
  • The rush: an HPA and a PodDisruptionBudget, and lab load to watch them work.

More in Packaging and operating

Build "Capstone: Jhatpat opens in Kanpur" yourself

Jhatpat delivers groceries in ten minutes from 14 dark stores across Lucknow, and its hand-run servers fall over on festival evenings. You move it onto Kubernetes. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Kubernetes are free. This one comes with the all labs plan.