Skip to content
Visual explainer 5h to learn 5 steps

Architecture, kubectl & a local cluster

Explain control plane vs nodes and run workloads on kind or minikube.

By Invicly Tech, , in Full DevOps with Python. About 13 minutes to read.

Topic 27 of 34

In short

A Kubernetes cluster has a control plane that decides what should run and worker nodes that run it. You describe desired state with kubectl, and controllers keep reality matching it.

Explained simply

Kubernetes is a system that runs containers for you on a group of machines. You do not tell it how to start each container. You tell it what you want, for example three copies of my API, and it keeps working until the real world matches that wish. This idea is called desired state.

A cluster has two parts. The control plane is the brain: it stores what you asked for and decides where things should run. The worker nodes are the muscles: each one is a machine that actually runs your containers and reports back how they are doing.

You talk to the cluster with a command line tool called kubectl. Every kubectl command becomes a request to one central component, the API server. Nothing in Kubernetes talks to the database directly; everything goes through the API server, which checks who you are and whether you are allowed.

For learning, you do not need cloud servers. A tool called kind (Kubernetes in Docker) runs a complete cluster inside Docker containers on your laptop. You can create it in about a minute, break it, delete it and start again for free.

Press Play on a diagram to walk through it one step at a time.

MapCluster components
Kubernetes cluster
  • Control plane
    • kube-apiserver
    • etcd
    • kube-scheduler
    • kube-controller-manager
  • Worker node
    • kubelet
    • kube-proxy
    • Container runtime (containerd)
    • Your Pods
Sequencekubectl apply a Pod
kubectl
API server
Scheduler
kubelet
  1. 1Create Pod spec
    kubectl to API server: Create Pod spec
  2. 2Validated, saved to etcd
    API server to kubectl: Validated, saved to etcd
  3. 3Watch: unscheduled Pod found
    Scheduler to API server: Watch: unscheduled Pod found
  4. 4Bind Pod to node-1
    Scheduler to API server: Bind Pod to node-1
  5. 5Watch: Pod assigned to me
    kubelet to API server: Watch: Pod assigned to me
  6. 6Image pulled, status Running
    kubelet to API server: Image pulled, status Running
FlowDebugging a Pod that will not run
  1. 1
    kubectl get pods

    Read STATUS and RESTARTS

  2. 2
    kubectl describe pod

    Check Events for scheduling or pull errors

  3. 3
    kubectl logs --previous

    See why the last run crashed

  4. 4
    kubectl exec -it

    Look inside a running container

  5. 5
    Fix the spec

    Change the image, command or limits and reapply

CompareWhere to run a practice cluster
kind
  • Nodes are Docker containers
  • Multi-node in one config file
  • Fast to create and delete
  • Great for CI tests
minikube
  • Single node VM or container
  • Built-in add-ons like ingress
  • minikube dashboard opens a UI
  • Good for first steps
Managed (EKS, GKE, AKS)
  • Cloud runs the control plane
  • Real load balancers and storage
  • Costs money per hour
  • What production usually uses

In depth

Controllers and the reconcile loop

The control plane is not one program but several, each with one job. kube-apiserver is the front door: it checks authentication, authorization and the shape of every object, then saves it in etcd, a distributed key-value store. etcd is the only place cluster state lives, so backing it up is backing up the cluster.

The real work is done by controllers. kube-controller-manager runs dozens of them in one process: the Deployment controller, the ReplicaSet controller, the Node controller, the Job controller and more. Each one watches the API server for changes to its kind of object, compares what exists with what is wanted, and acts to close the gap. Then it waits for the next change and repeats. This is the reconcile loop.

The scheduler is a special controller: it watches for Pods with no node assigned and picks one, based on free CPU and memory requests, node selectors, taints and affinity rules. In the cloud, cloud-controller-manager also creates load balancers and routes.

CycleWhat every controller does, forever
  1. 1
    Watch

    Get change events from the API server

  2. 2
    Observe

    Read the current state of its objects

  3. 3
    Compare

    Desired replicas 3, running 2

  4. 4
    Act

    Create or delete objects through the API

  5. Back to step 1

What actually runs on a worker node

The kubelet is the agent on every node. It watches the API server for Pods bound to its node and makes them real. It does not start containers itself: it calls a container runtime, usually containerd or CRI-O, through a standard interface called CRI (Container Runtime Interface). Docker Engine is no longer used directly as a runtime since Kubernetes 1.24, but images built with Docker run fine because they follow the same OCI image format.

For each Pod, the runtime first creates a small sandbox (the pause container) that holds the Pod's network namespace. A CNI (Container Network Interface) plugin such as Calico, Cilium or Flannel gives that sandbox its own IP address. Then your containers start inside it, which is why containers in one Pod can reach each other on localhost.

kube-proxy watches Services and programs packet rules (iptables, IPVS or nftables) on each node so that a Service IP is forwarded to a healthy Pod. Some CNI plugins, like Cilium, can replace kube-proxy entirely.

LayersThe stack on one worker node
  1. 1
    Your Pods

    App containers sharing one IP per Pod

  2. 2
    kubelet

    Starts, watches and reports on Pods

  3. 3
    Container runtime

    containerd or CRI-O, called via CRI

  4. 4
    CNI plugin and kube-proxy

    Pod IPs and Service forwarding rules

  5. 5
    Linux kernel

    Namespaces, cgroups, netfilter

kind: a real cluster inside Docker

kind creates each Kubernetes node as a Docker container. Inside that container run systemd, containerd and the kubelet, and on the control-plane node also the API server, etcd, scheduler and controller manager as static Pods. So it is a real, conformant cluster, just packed into containers. It needs Docker (or Podman) and about 2 GB of free memory for a small cluster.

kind create cluster --name dev writes a context called kind-dev into your kubeconfig and switches kubectl to it. A config file lets you add worker nodes, choose the Kubernetes version with a node image, or map ports from your laptop into the cluster.

One surprise for beginners: the nodes cannot see images you built locally with docker build, because each node has its own containerd image store. Use kind load docker-image api:dev --name dev to copy the image in. minikube is a popular alternative that runs a single VM or container and has handy add-ons like an ingress controller and a dashboard.

  • kind get clusters lists clusters; kind delete cluster --name dev removes one
  • Avoid the latest tag with kind load, or Kubernetes will try to pull it from a registry
  • k3d (k3s in Docker) is another light option

Reading Pod status like an engineer

A Pod has a phase, one of five values: Pending (accepted but not running yet, for example waiting for scheduling or an image pull), Running, Succeeded (all containers exited with code 0), Failed, and Unknown (the node stopped reporting).

The words you see in the STATUS column of kubectl get pods are often not phases but container reasons. ErrImagePull and ImagePullBackOff mean the image name, tag or registry credentials are wrong. CrashLoopBackOff means the container keeps exiting and the kubelet waits longer between each restart, up to five minutes. OOMKilled means the container used more memory than its limit.

The tools follow a fixed order. kubectl get pods -o wide shows status, restarts, IP and node. kubectl describe pod shows the spec plus the Events list at the bottom, which explains scheduling and pull problems. kubectl logs shows container output, and kubectl logs --previous shows the output of the last crashed run, which is usually where the real error is.

Namespaces, kubeconfig and contexts

A namespace is a name scope inside one cluster. Two teams can each have a Deployment called api if they live in different namespaces. A fresh cluster has four: default, kube-system (cluster components such as CoreDNS), kube-public and kube-node-lease (node heartbeats). Namespaces are also the unit for access rules and resource quotas. Some objects are cluster-wide and have no namespace, such as Nodes, PersistentVolumes and Namespaces themselves; kubectl api-resources --namespaced=false lists them.

kubectl finds clusters through a kubeconfig file, by default ~/.kube/config, or the files listed in the KUBECONFIG environment variable. It has three lists: clusters (API address and CA certificate), users (credentials) and contexts. A context ties one cluster, one user and an optional default namespace together under a name. kubectl config use-context switches the whole tool to another cluster, so checking the current context before a delete is a habit worth building.

MapInside a kubeconfig file
~/.kube/config
  • clusters
    • kind-dev: https://127.0.0.1:port
    • prod-eks: API URL and CA
  • users
    • kind-dev: client certificate
    • prod-admin: aws eks get-token
  • contexts
    • kind-dev = cluster + user
    • prod = cluster + user + namespace
  • current-context
    • The one kubectl uses now

Learn it in 5 short steps

About 1h each. Track them with a timer in your plan.

  1. 1
    Learn control plane and node components~1h
  2. 2
    Create a local cluster with kind~1h
  3. 3
    Use kubectl get, describe and logs~1h
  4. 4
    Run a Pod and inspect it~1h
  5. 5
    Understand namespaces and contexts~1h

Key points

  • Everything talks to the API server; etcd stores the cluster's desired and current state.
  • The scheduler picks a node; the kubelet on that node actually starts containers.
  • kind runs a whole cluster inside Docker containers, ideal for local practice.
  • Namespaces group resources; contexts choose which cluster and user kubectl uses.

Key terms

Tap a card to flip it. 0/6 known

Examples

bash
kind create cluster --name dev
kubectl config current-context
kubectl get nodes
kubectl run web --image=nginx:1.27
kubectl get pods -o wide
kubectl describe pod web
kubectl logs web
kubectl get pods -n kube-system

Create a local cluster and inspect your first Pod.

A three-node kind cluster running your own image

Step 1: write a kind config with one control-plane node and two workers. Step 2: create the cluster; kubectl now points at the context kind-dev. Step 3: build your FastAPI image locally with a fixed tag. Step 4: load it into the kind nodes, because they cannot see your laptop's Docker images. Step 5: run a Pod from it and check which worker the scheduler picked with -o wide.

bash
cat > kind.yaml <<'EOF'
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
  - role: control-plane
  - role: worker
  - role: worker
EOF
kind create cluster --name dev --config kind.yaml
kubectl get nodes                       # 3 nodes, all Ready
docker build -t api:dev .
kind load docker-image api:dev --name dev
kubectl run api --image=api:dev --port=8000
kubectl get pod api -o wide             # NODE shows dev-worker or dev-worker2

Find out why a Pod is in CrashLoopBackOff

Step 1: start a Pod whose command prints a line and exits with code 1. Step 2: kubectl get pods shows the restart count climbing and the status CrashLoopBackOff. Step 3: describe shows Last State: Terminated with Exit Code 1, and Events show Back-off restarting failed container. Step 4: logs --previous shows what the crashed run printed. Step 5: delete the Pod once you understand it. In a real app the logs usually show a missing environment variable or a failed database connection.

bash
kubectl run crash --image=busybox:1.36 -- sh -c "echo starting; exit 1"
kubectl get pods -w                 # RESTARTS 1, 2, 3... STATUS CrashLoopBackOff
kubectl describe pod crash | grep -A3 "Last State"
kubectl logs crash --previous       # prints: starting
kubectl get events --sort-by=.metadata.creationTimestamp | tail -5
kubectl delete pod crash

Quick reference

  • kubectl config get-contexts lists contexts; the starred one is current
  • kubectl config set-context --current --namespace=dev changes your default namespace
  • kubectl get pods -A lists Pods in all namespaces
  • kubectl logs pod-name --previous shows output from the last crashed container
  • kubectl explain pod.spec.containers documents any field from the live API
  • kubectl get pod web -o yaml shows the full object, including status
  • kind load docker-image img:tag --name dev copies a local image into kind nodes
  • kubectl api-resources lists every resource type and its short name

Common mistakes

  • Running commands against the wrong cluster; always check the current context.
  • Treating Pods as permanent; they are replaced, so use Deployments for real apps.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1Which component is the only one that reads and writes etcd directly?

Question 2

2A Pod shows ImagePullBackOff. What is the most likely cause?

Question 3

3You built api:dev with docker build, but a kind cluster cannot find it. What fixes it?

Question 4

4Which object is cluster-scoped and does not belong to any namespace?

Question 5

5Why can two containers in the same Pod talk over localhost?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Create a kind cluster, list the system Pods, and name which control plane component each one is.

  2. Exercise 2medium

    Create a namespace called team-a, make it your default for the current context, run an nginx Pod there, and open a shell in it.

  3. Exercise 3hard

    Prove that Kubernetes reconciles: create a Deployment with 3 replicas, delete one Pod, and watch a replacement appear. Then stop the kubelet on a kind worker and see the node turn NotReady.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Should I learn with kind or minikube?
Both run real Kubernetes. kind is faster to recreate and supports several nodes easily, so it suits practice and CI; minikube has friendlier add-ons for a first look.
Does Kubernetes still use Docker?
Not as its runtime: dockershim was removed in Kubernetes 1.24 and clusters use containerd or CRI-O. Images built with Docker still run, because they are standard OCI images.
What is the difference between a Pod and a container?
A Pod is a wrapper around one or more containers that share an IP address and volumes. Kubernetes schedules and restarts Pods, not single containers.
How do I stop running commands on the wrong cluster?
Check kubectl config current-context before risky commands, give production its own kubeconfig file, and consider a shell prompt that shows the current context.

Go deeper

ShareXLinkedInWhatsApp