Bitpath

Boss lesson · Unit 03

Make the api production-ready

Requests, limits and the scheduler, OOMKilled, three probes, and namespaces.

13 exercisesabout 3 min

What you practise

  • Requests and limits and what the scheduler does with them, OOMKilled, liveness, readiness and startup probes, namespaces

Try a question from this lesson

Pick one

A node has 4 CPUs. The scheduler must decide whether one more Pod fits on it, but that Pod has never run, so nobody knows what it will use. What can the scheduler go by?

Hint

The decision is made before the Pod exists. Where could a number come from at that point?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Requests and limits

Each container can state two figures per resource.

A request is what it is guaranteed. The scheduler adds up requests, not real usage, to decide what fits on a node.

A limit is the most it may use, enforced on the node. Over its CPU limit a container is throttled: slowed, never killed. Over its memory limit it is killed, and the kubelet restarts it.

CPU is counted in millicores: 500m is half a CPU. 256Mi of memory is 256 mebibytes.

YAML
resources:
  requests:
    cpu: 500m
    memory: 256Mi
  limits:
    cpu: "1"
    memory: 512Mi

Concept

Three probes

The kubelet can ask a container how it is, on a schedule. A probe is that question, often an HTTP request.

Liveness: is it stuck? If it fails, the container is restarted.

Readiness: can it take traffic now? If it fails, the Pod is taken off its Services' lists, and nothing is restarted.

Startup: has it finished booting? Until it passes, the other two are not run, so a slow start is not mistaken for a hang.

YAML
readinessProbe:
  httpGet:
    path: /ready
    port: 8080
  periodSeconds: 5
livenessProbe:
  httpGet:
    path: /healthz
    port: 8080
  failureThreshold: 3

Concept

Namespaces

A namespace is a named area of a cluster. Object names must be unique inside a namespace, not across the cluster, so two teams can each have a Deployment called api.

Most objects you have met live in a namespace: Pods, Deployments, Services, ConfigMaps, Secrets, claims. Nodes and PersistentVolumes belong to the whole cluster.

kubectl works in the namespace default unless told otherwise with -n. The cluster's own parts run in kube-system.

shell
kubectl get pods -n shop
kubectl get pods --all-namespaces

9 more exercises in the app

  • 2× type the answer
  • 1× true or false
  • 4× multiple choice
  • 1× match the pairs
  • 1× fill the blanks

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy