GeekCoding101 make your way to geek

Kubernetes Orchestration Explained: Self-Heal, Scale, Roll Out

Kubernetes orchestration means declaring desired state and letting the control plane keep it true. Watch it self-heal, scale and roll out on a k3s cluster.

7 min read
Terminal screenshot of docker exec k3s kubectl get nodes showing a single k3s node with status Ready
On this pageWhat is container orchestration, and why do containers need it?

Kubernetes orchestration means you declare the state you want (for example, “three copies of this container, reachable at one address”) and the control plane continuously works to make the cluster match it. That covers scheduling containers onto machines, replacing failed ones, scaling, rolling out new versions with rollback, and routing traffic to the right containers.

Below you’ll get the concepts in plain terms, then run six short steps on your laptop with only Docker installed, so you can watch each behaviour happen. If you want the component-level detail afterwards, see Kubernetes Control Plane Components.

What is container orchestration, and why do containers need it?

Running one container on one machine is easy: docker run and you’re done. Running dozens of containers across several machines is not. Someone has to decide which machine runs what, restart things that crash, add copies under load, ship new versions without downtime, and make sure other services can find them as addresses change.

Container orchestration is the automation of that work. If you are new to containers themselves, start with Docker Notes.

What Kubernetes orchestrates

According to the Kubernetes overview, Kubernetes is a portable, extensible, open source platform for managing containerized workloads and services. The same page lists the capabilities that make up orchestration:

  • Scheduling (automatic bin packing): you say how much CPU and memory containers need, and Kubernetes places them on nodes that fit.
  • Self-healing: failed containers are restarted or replaced.
  • Horizontal scaling: change the replica count by command or automatically.
  • Automated rollouts and rollbacks: change the version gradually, and go back if it goes wrong.
  • Service discovery and load balancing: pods get a stable name and address in front of them.
  • Secret and configuration management: configuration and credentials are stored and delivered separately from container images.

How does Kubernetes orchestration work? The reconciliation loop

The core idea is the control loop. You submit desired state (a Deployment that says “3 replicas of nginx”). Kubernetes records it, then controllers compare it with the current state and act on any difference. The Controllers documentation describes this as a non-terminating loop that regulates the state of the system.

Three pieces do most of the visible work:

  • kube-controller-manager runs the controllers. The Deployment and ReplicaSet controllers notice “only 2 pods exist, 3 wanted” and create another pod object.
  • kube-scheduler sees a pod with no node and picks a node for it.
  • kubelet runs on each node, starts the containers for pods assigned to it, and reports their status.

You never tell Kubernetes “start a container on node 2”. You state the goal, and these parts converge on it. The Deployment documentation covers the object we’ll use below.

Try it: a single-node cluster on your laptop

You only need Docker. This runs k3s, a lightweight Kubernetes distribution, inside a container. It is for learning, not a production setup.

Terminal window
docker run -d --name k3s --privileged rancher/k3s:v1.33.6-k3s1 server

Give it a short while to start. Every command below runs kubectl inside that container, so you don’t need a kubeconfig on your machine. First confirm the client and server versions:

Terminal window
docker exec k3s kubectl version
kubectl version printing the client, kustomize and server versions, all v1.33.6

Step 1: check the node is Ready

Terminal window
docker exec k3s kubectl get nodes
Terminal output of docker exec k3s kubectl get nodes showing one control-plane node with STATUS Ready

Step 2: create a Deployment with three replicas

Terminal window
docker exec k3s kubectl create deployment web --image=nginx:1.27 --replicas=3
docker exec k3s kubectl get pods -o wide
kubectl create deployment web with three replicas, then kubectl get pods -o wide listing three Running web pods with their own IPs and the NODE column filled in

You asked for an outcome, not individual containers. The scheduler assigned each pod to a node, and the kubelet started them. Here there is only one node, but with several the scheduler would spread them according to available resources.

Step 3: watch self-healing

Delete one pod. The label app=web was added automatically by kubectl create deployment, so you can pick a pod without copying its name by hand:

Terminal window
POD=$(docker exec k3s kubectl get pods -l app=web -o jsonpath='{.items[0].metadata.name}')
docker exec k3s kubectl delete pod "$POD"
docker exec k3s kubectl get pods -l app=web
Deleting one web pod and listing pods again: three pods are Running and one has a much smaller AGE than the others

The ReplicaSet controller saw two pods where the desired state said three, and created a replacement. Nobody ran a restart command.

Step 4: scale up

Terminal window
docker exec k3s kubectl scale deployment web --replicas=5
docker exec k3s kubectl get deployment web
kubectl scale deployment web to five replicas, then kubectl get deployment web showing READY 5/5

You changed one number in the desired state. The same loop that replaced the deleted pod now added two more.

Step 5: roll out a new version, then roll it back

Change the image of the container named nginx (the name kubectl create deployment derives from the image):

Terminal window
docker exec k3s kubectl set image deployment/web nginx=nginx:1.28
docker exec k3s kubectl rollout status deployment/web
docker exec k3s kubectl rollout history deployment/web
kubectl set image, rollout status ending with successfully rolled out, and rollout history listing revisions 1 and 2

By default a Deployment replaces pods gradually, so the app stays available during the change. Now undo it:

Terminal window
docker exec k3s kubectl rollout undo deployment/web
docker exec k3s kubectl rollout status deployment/web
kubectl rollout undo reporting rolled back, then rollout status ending with successfully rolled out

See the kubectl rollout reference for pausing, restarting and rolling back to a specific revision.

Step 6: service discovery

Pods come and go, and their IPs change. A Service gives them one stable front door:

Terminal window
docker exec k3s kubectl expose deployment web --port=80
docker exec k3s kubectl get endpointslices -l kubernetes.io/service-name=web -o jsonpath='{range .items[*].endpoints[*]}{.addresses[0]}{"\n"}{end}'
docker exec k3s kubectl get pods -o wide
kubectl expose creating service/web, the endpoint IPs of the Service, and kubectl get pods -o wide showing the same five pod IPs

The five addresses listed for the Service are the same five pod IPs from get pods -o wide. (Plain kubectl get endpoints is deprecated in Kubernetes 1.33 and truncates long lists, so this reads the EndpointSlice instead.) The Service selects pods by label and keeps its list of endpoints up to date as pods are replaced or scaled. To learn the different Service types, read NodePort vs ClusterIP.

Clean up

Terminal window
docker rm -f k3s

Kubernetes vs Docker Compose vs Docker Swarm

Docker ComposeDocker SwarmKubernetes
Typical scopeOne machineA cluster of Docker hostsA cluster of nodes
Setup effortLowestModerateHighest
Self-healing and rolloutsLimitedBuilt inBuilt in, with extensive controls
Ecosystem and extensibilitySmallSmallerVery large and extensible
Good fitLocal dev, simple single-host appsSmall clusters that want Docker-native simplicityMulti-service apps that need the full orchestration feature set

Treat this table as a rough, qualitative guide. Check each project’s current documentation for exact features.

When you do not need Kubernetes

Kubernetes adds concepts to learn and a system to operate. You can reasonably skip it if:

  • Your app is one or two containers on a single server, where Docker Compose is enough.
  • You have no need for automated scaling, rolling updates or multi-node scheduling.
  • A managed platform that runs your containers for you covers your needs.

Reach for Kubernetes when you run many services across several machines and the manual work it automates has started to hurt.

Where to go next

FAQ

What does Kubernetes orchestrate?

Containers, grouped as pods. It schedules them onto nodes, restarts or replaces failed ones, scales replica counts, rolls out new versions, routes traffic through Services, and delivers configuration and secrets to them.

What is the difference between Kubernetes and Docker?

Docker builds and runs containers, typically on one host. Kubernetes orchestrates containers across a cluster of machines, deciding where they run and keeping them in the state you declared.

What is the Kubernetes reconciliation loop?

It is the cycle in which controllers compare the desired state you stored with the current state of the cluster and take action to close any gap. Self-healing, scaling and rollouts are all this loop at work.

Is Kubernetes the same as container orchestration?

Kubernetes is one container orchestration platform, and the most widely used. Docker Swarm is another, and other tools exist. Container orchestration is the general idea; Kubernetes is an implementation.

Thanks for reading my blog post! Feel free to check out my other posts or contact me via the social links in the footer.

Keep reading

All posts