Docker and Kubernetes course menu
What Is Kubernetes? A Simple Introduction
Why Kubernetes exists, what it does beyond Docker, clusters, nodes, pods and the control plane, running a local cluster with kind, and your first kubectl commands.
On this page
Docker runs containers on one machine. But what happens if that machine fails, or if you need 50 copies of your app across 10 servers? Kubernetes (often written K8s) manages containers across many machines.
What Kubernetes does#
You describe the state you want, and Kubernetes keeps it that way.
- Self-healing: if a container or server dies, it starts a replacement.
- Scaling: run more copies with one command, or automatically.
- Rolling updates: replace containers gradually, with no downtime, and roll back if needed.
- Load balancing: spread traffic across the copies.
- Configuration: manage settings and secrets.
Do I need it?#
Often not. Kubernetes is powerful, but it is complex to run.
It is still worth learning, because many companies use it, and it comes up in DevOps and cloud interviews.
The architecture#
A cluster is a group of machines, called nodes.
Control plane
(API server, scheduler, etcd, controllers)
/ | \
Worker node Worker node Worker node
kubelet kubelet kubelet
[pods] [pods] [pods]A local cluster#
You do not need a cloud account. kind (Kubernetes in Docker) runs a whole cluster in Docker containers. Other choices are minikube, and the Kubernetes option in Docker Desktop.
Install kind and kubectl, then run:
kind create cluster --name laviyxThe lessons in this section ran on a real kind cluster.
kubectl#
kubectl is the command-line tool for Kubernetes:
kubectl version --client | head -n 1
kubectl cluster-info | head -n 1 | sed 's#https:.*#https://...#'
kubectl get nodesClient Version: v1.37.1
Kubernetes control plane is running at https://...
NAME STATUS ROLES AGE VERSION
laviyx-control-plane Ready control-plane 26s v1.37.0System pods#
Kubernetes runs its own parts as pods, in a namespace called kube-system. A namespace is a way to separate resources in a cluster:
kubectl get namespaces --no-headers | awk '{print $1}'
echo ---
kubectl get pods -n kube-system -o jsonpath='{range .items[*]}{.metadata.labels.component}{.metadata.labels.k8s-app}{"\n"}{end}' | sort -udefault
kube-node-lease
kube-public
kube-system
local-path-storage
---
etcd
kindnet
kube-apiserver
kube-controller-manager
kube-dns
kube-proxy
kube-schedulerYour first app#
kubectl create deployment hello --image=nginx:1.30-alpine
kubectl rollout status deployment/hello --timeout=90s
kubectl get pods --no-headers | awk '{print $2, $3}'deployment.apps/hello created
Waiting for deployment "hello" rollout to finish: 0 of 1 updated replicas are available...
deployment "hello" successfully rolled out
1/1 RunningNow see the self-healing. Delete the pod, and Kubernetes makes a new one, because you asked for one to exist:
old=$(kubectl get pods -l app=hello -o name)
kubectl delete "$old" --wait=false > /dev/null
sleep 8
kubectl get pods -l app=hello --no-headers | grep -c Running
[[ "$(kubectl get pods -l app=hello --field-selector=status.phase=Running -o name | head -n 1)" != "$old" ]] && echo "A new pod replaced the old one"
kubectl delete deployment hello1
A new pod replaced the old one
deployment.apps "hello" deleted from default namespaceThat is the main idea of Kubernetes: you declare what you want, and it works continuously to make it true.
Key words#
Common mistakes#
Key takeaway#
Next: Pods and Deployments.
Finished this lesson?
Related lessons
Recommended Docker and Kubernetes resources
- Docker Deep Dive by Nigel Poulton
A practical guide to how Docker works, for readers who have finished the basics.
Some links are affiliate links. If you buy through them, Laviyx Learn may earn a commission at no extra cost to you. As an Amazon Associate, we earn from qualifying purchases.