Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

Chapter 5Name in the course: Kubernetes

Run apps on Kubernetes

Most DevOps jobs today run apps on Kubernetes. You need one tool to talk to the cluster (kubectl), one or two to package apps (Helm, Kustomize), a local cluster to practise (minikube, kind, k3s) and helpers to find problems fast (k9s, stern).

  • 6 Lessons
  • 9 Commands

$ run as a normal user# run as root (or with sudo)

Skills in this chapter

  • Kubernetes — 8

5.1

kubectl — talk to the cluster

kubectl creates, reads, changes and deletes everything in Kubernetes.

kubectl get pods -n shop -o wide
kubectl apply -f deploy.yaml
kubectl rollout status deploy/shop -n shop
kubectl logs deploy/shop -n shop --since=10m
kubectl describe pod shop-7d9c-abcde -n shop

Good practice:

  • Changes go through Git (GitOps); kubectl on production is for reading and emergencies.
  • Requests and limits, readiness and liveness probes on every container.

5.2

Helm — packages for Kubernetes

helm installs an app from a chart with your values, and upgrades or rolls it back as one release.

helm repo add bitnami https://charts.bitnami.com/bitnami
helm upgrade --install shop ./charts/shop -n shop -f values-prod.yaml
helm history shop -n shop
helm rollback shop 3 -n shop

Commands in this lesson

5.3

Kustomize — one base, many environments

kustomize changes plain YAML per environment with overlays — no templates.

kubectl kustomize deploy/overlays/prod
kubectl apply -k deploy/overlays/prod
kustomize edit set image shop=ghcr.io/acme/shop:1.4.0

5.4

minikube, kind and k3s — clusters to practise

A real cluster on your laptop or a small VM, made in a minute and thrown away.

minikube start --addons ingress,metrics-server
kind create cluster --name lab
curl -sfL https://get.k3s.io | sh -
ToolBest for
minikubelearning, add-ons, one laptop
kindCI tests, many clusters, fast
k3ssmall real servers, home lab, edge

5.5

k9s and stern — find problems fast

k9s is a live terminal UI for the cluster; stern follows the logs of many pods at once.

k9s -n shop --readonly
stern -n shop deployment/shop --since 15m -i ERROR

5.6

Debug a pod that does not start

The same 5 steps for every broken pod.

  1. kubectl get pods — the STATUS: Pending, ImagePullBackOff, CrashLoopBackOff, OOMKilled?
  2. kubectl describe pod — the Events at the bottom tell why.
  3. kubectl logs POD --previous — the logs of the container before it crashed.
  4. kubectl get events --sort-by=.lastTimestamp — what happened around it.
  5. kubectl exec -it POD -- sh or kubectl debug — look inside.

Remember

Pending = scheduling (resources, taints); ImagePullBackOff = image name or registry login; CrashLoopBackOff = the app itself or its config.

All commands in this chapter