Skip to content
Laviyx Learn

Try

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.

Advanced6 min readUpdated
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.

SituationGood choice
One server, small appDocker Compose
Don't want to manage serversCloud Run, ECS, or a hosting platform
Many services, teams and serversKubernetes

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.

Text
             Control plane
   (API server, scheduler, etcd, controllers)
          /            |            \
     Worker node   Worker node   Worker node
     kubelet       kubelet       kubelet
     [pods]        [pods]        [pods]
PartJob
API serverThe front door; kubectl talks to it
etcdThe database of the cluster's state
SchedulerChooses a node for each new pod
ControllersCompare what you asked for with what exists, and fix differences
kubeletRuns on each node, and starts its containers

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:

Terminal
kind create cluster --name laviyx

The lessons in this section ran on a real kind cluster.

kubectl#

kubectl is the command-line tool for Kubernetes:

Terminal
kubectl version --client | head -n 1
kubectl cluster-info | head -n 1 | sed 's#https:.*#https://...#'
kubectl get nodes
Output
Client 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.0

System 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:

Terminal
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 -u
Output
default
kube-node-lease
kube-public
kube-system
local-path-storage
---
etcd
kindnet
kube-apiserver
kube-controller-manager
kube-dns
kube-proxy
kube-scheduler

Your first app#

Terminal
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}'
Output
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 Running

Now see the self-healing. Delete the pod, and Kubernetes makes a new one, because you asked for one to exist:

Terminal
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 hello
Output
1
A new pod replaced the old one
deployment.apps "hello" deleted from default namespace

That is the main idea of Kubernetes: you declare what you want, and it works continuously to make it true.

Key words#

WordMeaning
PodThe smallest unit; one or more containers
DeploymentKeeps a set number of pods running
ServiceA stable address for a set of pods
ConfigMap, SecretSettings for pods
NamespaceA group of resources

Common mistakes#

Key takeaway#

Next: Pods and Deployments.

Finished this lesson?

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.