Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Nodes, namespaces and pods in Kubernetes

After this lesson: I can say what a node, a namespace and a pod are.

45 min lesson9 commandsKubernetes lab: a one-node k3s cluster for each student on a private Ubuntu VM

What a Kubernetes cluster is made of

Kubernetes is a system that runs programs on one or more computers and keeps them running. Every table it prints uses three words, node, namespace and pod, so you need them before anything else makes sense.

A shop might run a website, a payment service and a stock service all day. Kubernetes watches each one for you.

By the end of this lesson

Note

I can say what a node, a namespace and a pod are.

Key words

WordWhat it meansExample
Clusterthe computers Kubernetes controls as one group
Nodeone machine of the cluster
Namespacea named folder that keeps one group's things apartkube-system
Podone running copy of a program
kubectlthe command that talks to the cluster

The cells students fill in are left blank in this preview.

A cluster is made of nodes

A cluster is the group of computers Kubernetes controls. Each computer in it is a node. A real cluster has many nodes. This lab has one, so one machine does every job.

A namespace is a named folder inside the cluster. It keeps one team's things apart from another's. Kubernetes keeps its own parts in kube-system, and you put your work in a namespace you make.

Worked example: three words in this lab

WordWhat it isWhere you meet it here
NodeOne machine of the clusterThe one machine you are logged in to
NamespaceA named folder of things`default` and `kube-system`
PodOne running copy of a programThe `coredns` pod in `kube-system`

The cells students fill in are left blank in this preview.

List the namespaces

Command
kubectl get namespaces --no-headers -o custom-columns=NAME:.metadata.name

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

List the pods Kubernetes started

Command
kubectl get pods -n kube-system --no-headers -o custom-columns=NAME:.metadata.name

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A pod is one copy of a program

A pod holds one or more containers. It has a name, and the program inside sees that name as its host name.

You can start a pod by hand with kubectl run. The -n flag says which namespace it goes in. The next Runs make a namespace called tour, start a pod called solo that sleeps for an hour, and ask it its name.

Make a namespace of your own

Command
kubectl create namespace tour

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Start one pod by hand

Command
kubectl run solo -n tour --image=busybox:1.37.0 -- sleep 3600

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Wait until the pod is ready

Command
kubectl wait --for=condition=Ready pod/solo -n tour --timeout=60s

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Ask the pod its own name

Command
kubectl exec solo -n tour -- hostname

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

A common mistake

Warning

Many people think Kubernetes starts a pod again when it is deleted. A pod you made by hand is gone for good, because nothing owns it. Only something that owns pods, such as a Deployment, makes new ones.

Delete the pod

Command
kubectl delete pod solo -n tour --grace-period=1

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Look for it again

Command
kubectl get pods -n tour

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

Remove the namespace

Command
kubectl delete namespace tour

Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.

About this lab and its source: Kubernetes lab: a one-node k3s cluster for each student on a private Ubuntu VM

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.