The case

Twelve services and one that keeps failing. Who restarts the container at three in the morning?

Isaac's store has grown. Orders, stock, payments, notifications and the accountant's panel have become twelve containers. Each one needs copies running at the same time, a restart when it gets stuck, and a way to find the others.

One night, the stock service got stuck. Nobody noticed until the next morning, because nobody was watching.

This post builds on Containers in the Cloud and Serverless and Cloud Run on Google Cloud. With Cloud Run, Google decides when the container runs. Here, your team decides what runs, in how many copies, and how the parts find each other.

The problem

A container alone doesn't take care of itself

Starting a container is easy. Keeping it alive is another story:

  • Restarts: if the process gets stuck, someone has to notice and start it again.
  • Copies: to handle the crowd, several copies must run and be spread across machines.
  • Addresses: when a container is recreated, its address changes, and whoever depends on it breaks.

The solution

Kubernetes: the team describes, the system executes

Kubernetes (or K8s) is a container orchestration system. You declare the state you want, for example "three copies of the orders service always running", and it works to keep that state. If a copy falls, it creates another. If a machine disappears, it moves the copies to another one.

It's like asking the store manager to have three cashiers open at any hour. You don't choose who to call to cover an absence; they handle it and only tell you when they can't.

Three objects

Pod, Deployment and Service

Pod

The smallest unit in Kubernetes: one or more containers that run together and share the same address.

At the store: the stock service's container, with its log collector beside it.

Deployment

Declares how many copies of a pod must exist, and recreates the ones that fall.

At the store: three copies of the orders service, always.

Service

A stable address to reach the pods, even when they are recreated.

At the store: the "payments" address, which the orders service calls without knowing which machine the payment is on.

Don't mix them up

GKE Autopilot × GKE Standard

GKE (Google Kubernetes Engine) is Google Cloud's managed Kubernetes. In both modes, Google takes care of the control plane, the cluster's brain. The difference is who takes care of the nodes, the machines where the pods run.

GKE Autopilot

“Who manages the nodes?”

Example
Google. The team defines the pods and the resources each one asks for, and doesn't create or configure the machines.
Focus
Pays for the resources requested by the pods. It is the mode Google recommends.

GKE Standard

“Who manages the nodes?”

Example
The team chooses the machine type, the size and the number of nodes.
Focus
More control over the infrastructure, and more work to maintain it.

Underneath

Cluster, nodes and pods

A cluster is the control plane together with the nodes. The nodes are virtual machines, like the ones in Compute Engine, and each pod is scheduled on a node with free space. The control plane decides where each pod runs and checks whether the declared state is being met.

When traffic rises, the number of pods can grow automatically. If the nodes have no room for them, the cluster needs more nodes. In Autopilot, Google takes care of this; in Standard, the team configures this behavior.

In practice

What the store needs, and how to solve it

What the store needsHow to solve it
Three copies of the orders service always runningDeployment with three replicas
Restart the stock service when it gets stuckKubernetes recreates the pod that failed
Call payments by name, not by addressService
More orders at night, fewer in the morningAutomatic scaling of the pods, and of the nodes when there is no room
Nobody wants to manage machinesGKE Autopilot

Key terms

Five terms to remember

Tap a card to see the definition.

Quick test

Three questions, exam style

01

The team wants to run containers on Kubernetes without managing the machines. Which GKE mode fits best?

02

A service needs three copies of a container to be always running, recreating the ones that fail. Which Kubernetes object does this?

03

Which statement about GKE is true?


Kubernetes does not replace the container: it decides where and how many copies run. With GKE, Isaac stops waking up at night because of the stock, and the team looks at what the store needs, not at each machine. The next step of the track is security: who can access each service.