Checking your sign-in…
This lesson is in Phase 2 — ₹799, one-time
Pay once with UPI, card or netbanking. Keep it forever. Your progress saves, so you can stop and come back.
← Back to all lessonsKubernetes Lab — Your App on a Small Local Cluster
Phase 2 · The Rest of DevOpsWhat this is and why it matters
Kubernetes runs your app for you. You say how many copies you want, and it keeps that many running.
Think of a school bus driver with a list: "12 children must be on this bus." If one child gets off, the driver goes and gets a replacement. Kubernetes is the driver. Your app copies are the children.
In real work, a crashed app that stays down until someone restarts it by hand is the failure that wakes people up.
This lab runs a small cluster on your own machine. A Service is the stable front door to your app. Front door means: one address that always leads to your app, even when the copies behind it change.
You will also break it on purpose and fix it, the same way you did in the break-and-fix labs.
Test status — read this first
Syntax-checked only. This lab was NOT run end-to-end on a clean machine yet, and the lesson itself says so. Nothing here promises a step works on a real machine. Where a step is unverified, this lesson says so. If a step fails, read the error message first, as in every lab in this kit.
What is a pod, in plain words?
A pod is the smallest thing Kubernetes runs, usually one container. A container is a small sealed box that holds one program. So a pod is usually one box, running one program.
A pod has a name that changes every time it is made, like my-site-7d9f8b6c4-abc12. The random letters at the end are normal. Copy the real name from your screen each time. Never guess it.
What is a node, in plain words?
A node is one machine in the cluster. In this lab there is one node, called devops-practice-control-plane. Control-plane means the node that is in charge: it decides what runs where. In a small practice cluster, the same node is in charge and also runs your app.
What is a deployment, in plain words?
A deployment is a written instruction that says "keep this many copies of my app running". You write it in a file. Kubernetes reads the file and does what it says. If a copy dies, the deployment makes a new one by itself.
What is a service, in plain words?
A service gives your app a stable address inside the cluster, even when pods come and go. Pods come and go because their names change and they get replaced. The service address stays the same. Other things inside the cluster use that address to find your app.
What this lab is
You will run your Project 1 website on a small Kubernetes cluster that lives on your own machine. No cloud account, no bill. You will also break it on purpose and fix it, the same way you did in the break-and-fix labs.
What you need first
- Docker running (from zero-cost-lab.md).
- Your Project 1 image built:
my-site:1.0(from portfolio-projects.md, Project 1). - An image is a saved, ready-to-run copy of an app.
my-site:1.0means: the image calledmy-site, version1.0. The part before the colon is the name. The part after the colon is the tag, which is the version label.- Project 1 is a small website you build in a folder called
my-siteinside~/devops-practice. That folder is learner-created: you made it when you did Project 1. It does NOT come with the kit. - If you deleted the image, move into the Project 1 folder and build it again first:
cd ~/devops-practice/my-site
docker build -t my-site:1.0 .- Line 1:
cd ~/devops-practice/my-site. - WHAT: move into the folder called
my-siteinside~/devops-practice. - WHY: the build command must run in the folder that holds your website files and your Dockerfile.
- Word by word:
cd(change directory — move to another folder) +~/devops-practice/my-site(your home folder, thendevops-practice, thenmy-site). - Line 2:
docker build -t my-site:1.0 .. - WHAT: build an image from the recipe file in this folder, and call it
my-site:1.0. - WHY: Kubernetes needs this image to run your app. Without it, there is nothing to run.
- Word by word:
docker build(build an image) +-t(give it this name —tstands for tag) +my-site:1.0(the name and version) +.(this folder — the dot means "build from the files right here"). - You should see: the build lines scroll past, then a short image ID line at the end. An image ID is a code for the built image.
- If it breaks: "no such file or directory" means you are in the wrong folder. Run
cd ~/devops-practice/my-sitefirst, then build again.
Why kind?
This kit uses kind, short for "Kubernetes in Docker". kind runs a whole cluster as containers on your machine, so it needs only Docker, which you already have. The other common choice is minikube, but this kit uses kind only, so every command below matches kind. minikube is another tool that runs a small cluster on your machine. You do not need it here. Do not install it.
Where do the files in this lab live?
The files you make in this lab (deployment.yaml and service.yaml) live in the folder you are standing in when you make them. Work inside ~/devops-practice/my-site for this whole lab, unless a step says otherwise. That is the Project 1 folder, and it is where your image was built.
Move there first, before Step 1:
cd ~/devops-practice/my-site- WHAT: move into your Project 1 folder.
- WHY: so the files you make land in the right place, and the commands that use them can find them.
- To check where you are, run
pwd. It prints the folder you are in.pwdmeans "print working directory" — the folder you are standing in. - How to make a YAML file: use
nano deployment.yaml(a text editor inside the terminal — type the text, press Ctrl+O then Enter to save, Ctrl+X to leave), or usecat > deployment.yaml << 'EOF', then the lines, thenEOFon its own line.cat >writes the lines that follow into the file until it seesEOF. YAML uses spaces for structure. Never use the Tab key in a YAML file. If a YAML file fails with a strange error, check the spaces first.
Step 1 — Install kubectl and kind
- WHAT we are doing: downloading two tools and putting them where the computer can find them.
- WHY:
kubectlis the tool you use to talk to a cluster.kindis the tool that creates the cluster. Without them, you cannot do any step below. - The Linux download links below are for AMD64 Linux. AMD64 is the type of processor in most desktop and laptop computers. ARM64 is the type in some newer laptops and in most phones.
- If you are on a Mac, use section 1c below (Homebrew). If you are on Windows, use section 1d below (Chocolatey). The Linux steps are 1a and 1b. The check at the end (1e) is the same on all three.
- How to know which one you have: run
uname -min your terminal. - WHAT
uname -mis: print your machine type. - WHY: it tells you which download link to use.
- If it prints
x86_64, you have AMD64. Use the links below. - If it prints
aarch64orarm64, you have ARM64. Swapamd64forarm64in the links below, and check kind's install page if a link fails. ARM64 steps are unverified in this kit.
1a. Install kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/kubectl- Line 1: the long
curlline. - WHAT: download the newest stable kubectl for Linux AMD64.
- WHY: kubectl is how you talk to the cluster. You need the tool on your machine before you can use it.
- Word by word:
curl(download a file from the internet) +-LO(save it with its own name, and follow redirects if the address moves) + the address in quotes (the place to download from). - Inside the address,
$(curl -L -s https://dl.k8s.io/release/stable.txt)is a command inside a command. It downloads a tiny text file that holds the newest version number, likev1.29.0, and pastes that number into the address.$(...)means "run this and paste the result here".-Lmeans follow redirects.-smeans quiet, print no progress. - So the full address means: "the newest kubectl, for Linux, for AMD64 processors".
- Line 2:
chmod +x kubectl. - WHAT: mark the downloaded file as runnable.
- WHY: a downloaded file is not runnable yet. The computer will refuse to run it until you mark it.
- Word by word:
chmod(change the file's permissions) ++x(add the "can run" permission) +kubectl(the file). - This is the same
chmod +xyou met in zero-cost-lab.md Step 8. - Line 3:
sudo mv kubectl /usr/local/bin/kubectl. - WHAT: move the file into the folder
/usr/local/bin. - WHY:
/usr/local/binis a folder the computer always looks in when you type a command name. Once kubectl is there, you can typekubectlfrom any folder and the computer finds it. That list of folders the computer searches is called the PATH. - Word by word:
sudo(as administrator — moving into this folder needs administrator power) +mv(move a file) +kubectl(the file, in the folder you are standing in) +/usr/local/bin/kubectl(the destination: the same name, inside/usr/local/bin). - You should see: a download progress line, then your prompt back. The
mvstep prints nothing when it works. That is normal. - If it breaks: "Permission denied" on the
mvstep means you forgotsudo. Run themvline again withsudoin front. If the download fails, check your internet connection and try again.
1b. Install kind
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind- Line 1:
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64. - WHAT: download kind version 0.23.0 for Linux AMD64, and save it as a file called
kindin this folder. - WHY: kind is the tool that creates your cluster.
- Word by word:
curl(download) +-Lo ./kind(save the download as a file calledkindin this folder —./means "this folder") + the address (kind's download page, version 0.23.0, Linux AMD64). - Note: the kind version number changes over time. If that download link fails with "404 Not Found", the version is old. "404 Not Found" means "there is nothing at this address any more". Take the newest link from kind's install page.
- Line 2:
chmod +x ./kind. - WHAT: mark the downloaded file as runnable.
- WHY: same reason as kubectl above.
- Word by word:
chmod++x(add "can run") +./kind(the file calledkindin this folder). - Line 3:
sudo mv ./kind /usr/local/bin/kind. - WHAT: move kind into
/usr/local/bin, the folder the computer searches for commands. - WHY: so you can type
kindfrom any folder. - Word by word:
sudo(as administrator) +mv(move) +./kind(the file in this folder) +/usr/local/bin/kind(the destination). - You should see: a download progress line, then your prompt back. Again, the
mvstep prints nothing when it works. - If it breaks: "404 Not Found" means that kind version link is old. Take the newest link from kind's install page.
1c. On a Mac — install with Homebrew
- WHAT we are doing: installing both tools with Homebrew, the Mac app installer.
- WHY: Homebrew downloads the tools and puts them where the computer can find them, in two short commands — no manual download links to get wrong.
- If your Mac does not have Homebrew yet, install it first from https://brew.sh — that page shows the one install command. Then come back here and run the two lines below.
brew install kubectl
brew install kind- Line 1:
brew install kubectl. - WHAT: download and install kubectl with Homebrew.
- WHY: kubectl is how you talk to the cluster. You need the tool on your machine before you can use it.
- Word by word:
brew(the Homebrew installer) +install+kubectl(the tool to install). - Line 2:
brew install kind. - WHAT: download and install kind with Homebrew.
- WHY: kind is the tool that creates your cluster.
- Word by word:
brew+install+kind(the tool). - You should see: Homebrew printing its progress, then your prompt back. Both tools land where the computer can find them, so you can type
kubectlandkindfrom any folder. - Then check both with section 1e below — the same check as Linux.
- Honest note: these two commands were checked against the tools' own install pages, but they were not run end-to-end on a Mac in this kit. If a command fails, check kind's install page for your system.
1d. On Windows — install with Chocolatey
- WHAT we are doing: installing both tools with Chocolatey (choco), the Windows app installer.
- WHY: Chocolatey downloads the tools and puts them where the computer can find them, in two short commands — no manual download links to get wrong.
- Open PowerShell as Administrator first. PowerShell is a Windows terminal. "As Administrator" means with the power to install programs. To open it that way, right-click PowerShell and pick "Run as administrator". Run the two lines below in that window, not in Git Bash — installing tools needs administrator power, and Git Bash does not have it.
- If your Windows machine does not have Chocolatey yet, install it first from https://chocolatey.org/install — that page shows the install command. Then come back here and run the two lines below.
choco install kubernetes-cli -y
choco install kind -y- Line 1:
choco install kubernetes-cli -y. - WHAT: download and install kubectl with Chocolatey. The Chocolatey package for kubectl is called
kubernetes-cli— that is the package name, not a typo. - WHY: kubectl is how you talk to the cluster.
- Word by word:
choco(the Chocolatey installer) +install+kubernetes-cli(the package to install) +-y(say "yes" to the install without asking you to confirm). - Line 2:
choco install kind -y. - WHAT: download and install kind with Chocolatey.
- WHY: kind is the tool that creates your cluster.
- Word by word:
choco+install+kind(the package) +-y(say "yes" without asking). - After installing, close PowerShell and open a fresh terminal, so the computer picks up the new tools. Chocolatey puts both tools on the PATH — the list of folders the computer searches for commands — so after this step you can use
kindandkubectlfrom Git Bash like every other command in this kit. - Then check both with section 1e below — the same check as Linux.
- Honest note: these two commands were checked against the tools' install pages, but they were not run end-to-end on a Windows machine in this kit. If a command fails, check kind's install page for your system. From Step 2 on, the lab commands are the same on Windows, Mac, and Linux.
1e. Check both installed
kind version
kubectl version --client- Line 1:
kind version. - WHAT: ask kind for its version number.
- WHY: if it prints a version, kind is installed and found.
- Line 2:
kubectl version --client. - WHAT: ask kubectl for its own version number.
- WHY:
--clientmeans "only your tool on this machine, not the cluster". There is no cluster yet, so we only check the tool. - You should see a version number for each:
kind v0.23.0 go1.21.5 linux/amd64
Client Version: v1.29.0- How to read it:
kind v0.23.0is kind's version.go1.21.5is the version of Go, the language kind was written in — you do not need it.linux/amd64is your system type. On a Mac or Windows machine the system type at the end is different —darwin/arm64on a newer Mac, for example. That is fine. - Your version numbers will be different. That is fine.
- If it breaks: "command not found" means the
mvstep did not work. Check the file is in/usr/local/binwithls /usr/local/bin/kubectl /usr/local/bin/kind. - WHAT
lsis: list files. - WHY: it shows whether the two files really landed in
/usr/local/bin. If they are missing, redo themvlines.
Step 2 — Start the cluster
- WHAT we are doing: telling kind to create a cluster called
devops-practice. - WHY: the cluster is where your app will run. Nothing below works until it exists.
kind create cluster --name devops-practice- Word by word:
kind(the cluster tool) +create cluster(make a cluster) +--name devops-practice(call itdevops-practice). - You should see: lines scroll past as the cluster starts, then "Creating cluster ..." and your prompt back.
- If it breaks: "failed to create cluster" usually means Docker is not running. Start Docker and try again.
- The first run downloads the cluster's node image, so it takes a few minutes. A node image is the ready-made machine picture the cluster runs on. Be patient. Do not press Ctrl+C while it downloads.
- Then check it:
kubectl get nodes- WHAT: list the machines (nodes) in the cluster.
- WHY: to prove the cluster started and has a working node.
- Word by word:
kubectl(talk to the cluster) +get(list) +nodes(the machines). - You should see one node with STATUS Ready:
NAME STATUS ROLES AGE VERSION
devops-practice-control-plane Ready control-plane 2m v1.29.2- How to read it, column by column:
NAME(devops-practice-control-plane): the node's name.STATUS(Ready): the node is ready to run work. This is the column that matters. If it saysReady, the cluster works.ROLES(control-plane): this node is in charge of the cluster.AGE(2m): the node was made 2 minutes ago. Yours will differ.VERSION(v1.29.2): the Kubernetes version on the node. Yours will be different. That is fine.- If it breaks: if you see nothing, make sure Docker is running and try again. If the node shows "NotReady", wait a minute and run
kubectl get nodesagain. NotReady means "still starting".
Step 3 — Load your image into the cluster
- WHAT we are doing: copying your
my-site:1.0image into the cluster. - WHY: a kind cluster cannot see images sitting in your local Docker by itself. This is the step most beginners forget. Without it, the cluster would try to download your image from the internet and fail, because your image only exists on your machine.
kind load docker-image my-site:1.0 --name devops-practice- Word by word:
kind load(load something into the cluster) +docker-image(the thing is a Docker image) +my-site:1.0(the image name and version) +--name devops-practice(into the cluster calleddevops-practice). - You should see:
Image: "my-site:1.0" with ID "sha256:abc123..." not yet present on node "devops-practice-control-plane", loading...- How to read it: it says the image was not on the node yet, and it is loading it now. Your image ID will be different. That is fine.
sha256:abc123...is the image's fingerprint code. You do not need to remember it. - If it breaks: "image not found" means the image was never built. Go back to "What you need first" and build
my-site:1.0.
Step 4 — Run your app with a Deployment
- WHAT we are doing: writing a file that tells Kubernetes "keep one copy of my app running", then telling Kubernetes to read it.
- WHY: the file is the instruction. Kubernetes only does what the file says.
4a. Make the file deployment.yaml
- Make a file called
deployment.yamlin~/devops-practice/my-site(see "Where do the files in this lab live?" above for how). deployment.yamlis a settings file in YAML. YAML is a plain-text way of writing settings with indentation. Spaces matter. Never use the Tab key.
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-site
spec:
replicas: 1
selector:
matchLabels:
app: my-site
template:
metadata:
labels:
app: my-site
spec:
containers:
- name: web
image: my-site:1.0
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80- How to read this file, line by line:
apiVersion: apps/v1— WHAT: the version of the Deployment rules Kubernetes should use. WHY: Kubernetes has many versions of its rules. This line picks the right one. Copy it exactly.kind: Deployment— WHAT: this file describes a Deployment. WHY: it tells Kubernetes what sort of thing this file is.metadata:— WHAT: details about this Deployment. WHY: the next lines name it.name: my-site— WHAT: call this Deploymentmy-site. WHY: so you can refer to it by name in later commands.spec:— WHAT: the wanted state. WHY: everything underspecsays what Kubernetes must keep true.replicas: 1— WHAT: keep 1 copy running. WHY: one copy is enough while learning.replicasmeans copies.selector:— WHAT: how Kubernetes finds the pods this Deployment owns. WHY: it matches pods by their label, in the next lines.matchLabels:— WHAT: match pods with these labels. WHY: a label is a small tag stuck on a pod, likeapp: my-site.app: my-site— WHAT: the label isappwith the valuemy-site. WHY: the Deployment's pods carry this label, so the Deployment can find them.template:— WHAT: the pattern for making each pod. WHY: when Kubernetes needs a new copy, it follows this pattern.metadata:(inside the template) — WHAT: details about each pod. WHY: the next lines give the pod its label.labels:— WHAT: the labels to stick on each pod. WHY: the label must match theselectorabove, or the Deployment cannot find its own pods.app: my-site— WHAT: stick the labelapp: my-siteon each pod. WHY: this is the label the selector looks for.spec:(inside the template) — WHAT: what goes inside each pod. WHY: the next lines describe the container.containers:— WHAT: the list of containers in the pod. WHY: a pod usually holds one container. Here it holds one.- name: web— WHAT: call the containerweb. WHY: so you can refer to it. The-starts one item in the list.image: my-site:1.0— WHAT: run the imagemy-site:1.0. WHY: this is your Project 1 image, loaded in Step 3.imagePullPolicy: IfNotPresent— WHAT: use the image if it is already here; only download it if it is missing. WHY: your image only exists on your machine. Without this line, Kubernetes would try to download it from the internet and fail.ports:— WHAT: the list of doors this container listens on. WHY: the next line names the door.- containerPort: 80— WHAT: the container listens on door 80. WHY: door 80 is the door web servers normally listen on, and your Project 1 site is a web server. The-starts one item in the list.
4b. Check the file first, then apply it
Before you hand the file to Kubernetes, check it. A typed YAML file fails most often on spaces — one wrong indent and the file means something else. This check reads the file and tells you whether it is valid, without creating anything:
kubectl apply --dry-run=client -f deployment.yaml- WHAT: a trial run of
apply.--dry-run=clientmeans "check it on my machine only, do not send anything to the cluster and do not create anything". - WHY: it catches a bad file before Kubernetes ever sees it. A typo found here costs one line; a typo found after
applycosts a broken Deployment to clean up. - Word by word:
kubectl apply(the same command as below) +--dry-run=client(trial run, on your machine only) +-f(the file follows) +deployment.yaml(the file name).
What you should see:
deployment.apps/my-site created (dry run)(dry run) means "this is the trial — nothing was created". If you see it, the file is valid: run the real apply below. If it breaks: an error names the bad line. YAML uses spaces for structure — never use the Tab key. Fix the spaces, then run the check again. Do not run the real apply until this check passes.
kubectl apply -f deployment.yaml
kubectl get pods- Line 1:
kubectl apply -f deployment.yaml. - WHAT: give Kubernetes the file
deployment.yamland tell it to make it real. - WHY: writing the file alone does nothing.
applyis the step that hands it to Kubernetes. - Word by word:
kubectl(talk to the cluster) +apply(make this real) +-f(the file follows) +deployment.yaml(the file name). - Line 2:
kubectl get pods. - WHAT: list the pods.
- WHY: to see whether your app's pod started.
- Word by word:
kubectl+get(list) +pods(the pods). - You should see one pod named like
my-site-xxxx, with READY 1/1 and STATUS Running:
NAME READY STATUS RESTARTS AGE
my-site-7d9f8b6c4-abc12 1/1 Running 0 30s- How to read it, column by column:
NAME(my-site-7d9f8b6c4-abc12): the pod's name. The random letters at the end change every time. Copy the real name from your screen for the commands below. Never guess it.READY(1/1): 1 copy ready out of 1 wanted. This is the column that matters.1/1means ready.0/1means not ready yet.STATUS(Running): the pod is running.RESTARTS(0): the pod has not restarted. A high number here means it keeps crashing.AGE(30s): the pod was made 30 seconds ago.- If it breaks: if the pod shows
ImagePullBackOff, the image was not loaded into the cluster. Go back to Step 3. ImagePullBackOffmeans "I tried to download the image, failed, and I am waiting before trying again". BackOff means waiting.- If it shows
Pending, wait a minute and runkubectl get podsagain.Pendingmeans "waiting to start". It usually clears on its own. - If it shows
ErrImagePull, it means the same asImagePullBackOff: the image could not be pulled (downloaded).
4c. Open your app in the browser (through the Deployment)
kubectl port-forward deployment/my-site 8080:80- WHAT: connect door 8080 on your machine to door 80 on your app, through the Deployment.
- WHY: your app runs inside the cluster. Your browser cannot reach inside the cluster by itself. Port-forward is a temporary tunnel from your machine to your app, so you can look at it.
- Word by word:
kubectl(talk to the cluster) +port-forward(make a tunnel for a door) +deployment/my-site(the Deployment calledmy-site) +8080:80(door 8080 on your machine leads to door 80 in the app). - You should see:
Forwarding from 127.0.0.1:8080 -> 80
Forwarding from [::1]:8080 -> 80- How to read it:
127.0.0.1is another name forlocalhost, which means "this machine".[::1]is the same idea in the newer address style. Both lines say the same thing: door 8080 on your machine now leads to door 80 in your app. - If it breaks: "address already in use" means another port-forward is already running. Stop it with Ctrl+C first, then try again.
- WHAT Ctrl+C is: hold Ctrl and press C. It stops the command running in this terminal.
- WHY: two tunnels cannot use the same door 8080 at the same time.
- This connects port 8080 on your machine to your app. Open
http://localhost:8080. You should see your Project 1 site. - Keep this terminal open while you look. Stopping it with Ctrl+C only stops the forwarding, not your app. Your app keeps running inside the cluster.
4d. Expose it with a Service
- WHAT we are doing: making a second file that gives your app a stable address inside the cluster.
- WHY: the Deployment's pods change names and get replaced. The Service address stays the same, so other things inside the cluster can always find your app.
- Make a file called
service.yamlin the same folder (~/devops-practice/my-site):
apiVersion: v1
kind: Service
metadata:
name: my-site
spec:
selector:
app: my-site
ports:
- port: 80- How to read this file, line by line:
apiVersion: v1— WHAT: the version of the Service rules. WHY: copy it exactly, the same idea as in the Deployment file.kind: Service— WHAT: this file describes a Service. WHY: it tells Kubernetes what sort of thing this file is.metadata:— WHAT: details about this Service. WHY: the next line names it.name: my-site— WHAT: call this Servicemy-site. WHY: so you can refer to it by name.spec:— WHAT: the wanted state. WHY: everything under it says what the Service must do.selector:— WHAT: which pods this Service leads to. WHY: it matches pods by their label.app: my-site— WHAT: send traffic to pods labelledapp: my-site. WHY: that is the same label your Deployment gives its pods, so the Service finds them. If the label does not match, the Service leads nowhere.ports:— WHAT: the list of doors this Service offers. WHY: the next line names the door.- port: 80— WHAT: the Service listens on door 80. WHY: door 80 is the door your app listens on inside its pod.- Apply and check. Check the file first, the same way as the Deployment file — a trial run that creates nothing:
kubectl apply --dry-run=client -f service.yamlWhat you should see: service/my-site created (dry run). If it breaks, fix the spaces in service.yaml and check again. Then run the real apply:
kubectl apply -f service.yaml
kubectl get services- Line 1:
kubectl apply -f service.yaml. - WHAT: give Kubernetes the Service file and make it real.
- WHY: same as the Deployment file. Writing it alone does nothing.
- Line 2:
kubectl get services. - WHAT: list the services.
- WHY: to see whether your Service exists and what address it got.
- You should see
my-sitewith a CLUSTER-IP:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-site ClusterIP 10.96.123.45 <none> 80/TCP 10s- How to read it, column by column:
NAME(my-site): the Service's name.TYPE(ClusterIP): this Service is only reachable inside the cluster. ClusterIP is the default type. It means "an address inside the cluster only".CLUSTER-IP(10.96.123.45): the stable address inside the cluster. Yours will be different. That is fine. This address is for things inside the cluster. Your browser cannot open it directly.EXTERNAL-IP(<none>): there is no outside address.<none>means "none". That is normal for a ClusterIP Service. It does not mean something is broken.PORT(S)(80/TCP): the Service offers door 80, using TCP network traffic.AGE(10s): the Service was made 10 seconds ago.- If it breaks: if
my-siteis missing, check the file name and runkubectl apply -f service.yamlagain. - Stop the first port-forward with Ctrl+C first. Both port-forwards use port 8080, so they cannot run at the same time. Stopping it ends only the forwarding, not your app.
4e. Open it through the Service instead of the Deployment
kubectl port-forward service/my-site 8080:80- WHAT: make a tunnel from door 8080 on your machine to the Service.
- WHY: this proves the Service works. Before, you reached the app through the Deployment. Now you reach it through the Service.
- Word by word:
kubectl+port-forward(make a tunnel) +service/my-site(the Service calledmy-site) +8080:80(door 8080 on your machine leads to door 80). - You should see the same two "Forwarding from" lines as before.
- If it breaks: "address already in use" means the first port-forward is still running. Stop it with Ctrl+C first.
- Open
http://localhost:8080again. Same site, now reached through the Service. This is the address other things inside the cluster would use. Your browser reaches it here only through the port-forward above. That does not expose the app publicly. Publicly means anyone on the internet could open it. They cannot. Only your machine can, through this tunnel.
4f. Read about your pod
kubectl describe pod <pod-name>
kubectl logs <pod-name>- Line 1:
kubectl describe pod <pod-name>. - WHAT: show details and recent events for one pod.
- WHY: when something breaks, the Events at the bottom usually name the problem.
- Word by word:
kubectl+describe(show details) +pod(a pod) +<pod-name>(the pod's real name — replace the whole thing, brackets included, with the name you copied fromkubectl get pods). - The brackets
< >mean "replace this with the real value". Never type the brackets themselves. - Line 2:
kubectl logs <pod-name>. - WHAT: show what your app printed.
- WHY: the app's own words tell you what it did, and what went wrong.
- Word by word:
kubectl+logs(show printed lines) +<pod-name>(the pod's real name, as above). - You should see: details and recent events for your pod (
describe), and what your app printed (logs). - If it breaks: "No resources found" means the pod name is wrong. Pod names change every time, so copy the real name from
kubectl get pods. Replace<pod-name>with it, without the brackets. describeshows details and recent events.logsshows what your app printed. When something breaks, these two commands are where you look first.
Step 5 — Break it, then fix it
- WHAT we are doing: changing the image name to one that does not exist, watching the pod fail, finding the cause in the Events, then changing it back.
- WHY: this proves the Deployment controls the pod. The pod only does what its Deployment says. Fix the Deployment, and the pod follows.
5a. Break it
- Change the image in
deployment.yamlto a tag that does not exist, for examplemy-site:badtag. - HOW: open
deployment.yamlinnano(or your text editor), find the lineimage: my-site:1.0, change1.0tobadtag, save, and close. A tag is the version label after the colon.badtagis not a real version, so no such image exists. - Then apply it again:
kubectl apply -f deployment.yaml
kubectl get pods- Line 1:
kubectl apply -f deployment.yaml. - WHAT: hand the changed file to Kubernetes.
- WHY: Kubernetes only knows what you tell it. Until you apply, it still uses the old file.
- Line 2:
kubectl get pods. - WHAT: list the pods, to see the failure.
- WHY: the pod list is where the broken status shows up.
- You should see your pod not reaching Running. Its STATUS will show something like ImagePullBackOff or ErrImagePull, and its restarts may climb:
NAME READY STATUS RESTARTS AGE
my-site-7d9f8b6c4-abc12 0/1 ImagePullBackOff 0 30s- How to read it:
READY 0/1means 0 ready out of 1 wanted — not ready.STATUS ImagePullBackOffmeans "I tried to download the image, failed, and I am waiting before trying again".ErrImagePullmeans the same thing in shorter form: error pulling (downloading) the image. - If it breaks: if the pod still shows Running, the bad tag was not applied. Check
deployment.yamlreally saysmy-site:badtag, then apply again.
5b. Find it
kubectl describe pod <pod-name>- WHAT: show details and recent events for the broken pod.
- WHY: the Events at the bottom say the image could not be pulled or was not found. That names the cause.
- Replace
<pod-name>with the real pod name fromkubectl get pods, without the brackets. Note: after the bad apply, the pod name may have changed. Copy the new name from the latestkubectl get pods. - You should see: an event at the bottom saying the image could not be pulled or was not found.
- If it breaks: if there are no Events yet, wait 30 seconds and describe the pod again. Events take a moment to appear.
- Read the Events at the bottom. They will say the image could not be pulled or was not found. The lesson: the Deployment file is wrong, not the pod. A pod only does what its Deployment says.
5c. Fix it
- Change the image back to
my-site:1.0indeployment.yaml, apply it again, and check:
kubectl apply -f deployment.yaml
kubectl rollout status deployment/my-site
kubectl get pods- Line 1:
kubectl apply -f deployment.yaml. - WHAT: hand the fixed file to Kubernetes.
- WHY: this tells Kubernetes to go back to the real image.
- Line 2:
kubectl rollout status deployment/my-site. - WHAT: wait and report whether the new version finished rolling out.
- WHY:
kubectl applyalone does not mean the app is healthy yet. A rollout is the slow swap from the old copies to the new copies. This command watches it and tells you when it is done. - Word by word:
kubectl+rollout status(report the rollout) +deployment/my-site(the Deployment calledmy-site). - Line 3:
kubectl get pods. - WHAT: list the pods, to confirm the fix.
- WHY: the pod list proves a healthy pod is running.
- You should see the rollout finish, then a pod with READY 1/1 and STATUS Running:
deployment "my-site" successfully rolled out
NAME READY STATUS RESTARTS AGE
my-site-7d9f8b6c4-def34 1/1 Running 0 20s- How to read it:
successfully rolled outmeans the swap finished. The pod name is different from before — that is normal. A new pod was made.READY 1/1andSTATUS Runningmean healthy. - If it breaks: if the rollout hangs, describe the pod and read the Events. The error line names the problem.
- Wait for the rollout to finish: the expected result is a pod with READY 1/1 and STATUS Running.
kubectl applyalone does not mean the app is healthy yet. If the rollout fails, read the pod Events and status again. - A new pod starts and reaches Running. Deleting the broken pod alone would NOT have fixed it. The Deployment would simply have made the same broken pod again. Fix the Deployment, and the pod follows.
5d. Try self-healing once
- On the healthy pod, run
kubectl delete pod <pod-name>, thenkubectl get podsagain. - WHAT
kubectl delete pod <pod-name>is: delete one pod. - WHY: to watch the Deployment make a replacement by itself, to keep your chosen number of copies running. That is self-healing: the system fixes the missing copy on its own.
- Replace
<pod-name>with the real pod name, without the brackets. - You should see: the old pod is gone, and a new pod with a different name appears, reaching READY 1/1 and STATUS Running.
- That is not proof the app itself is healthy. Replacing a pod and knowing it works are different things. Later, learn readiness and liveness probes, which are how Kubernetes checks real health.
- A readiness probe is a check that asks "are you ready to take traffic?" A liveness probe asks "are you still alive?" You do not need them yet. Just know the words for later.
- That "later" is now: the Advanced section at the end of this lesson implements both probes in your deployment.yaml.
Clean up
Remove your app but keep the cluster
kubectl delete -f deployment.yaml
kubectl delete -f service.yaml- Line 1:
kubectl delete -f deployment.yaml. - WHAT: delete everything the Deployment file made.
- WHY: this removes your app's pods, but keeps the cluster itself.
- Word by word:
kubectl+delete(remove) +-f(the file follows) +deployment.yaml(the file that describes what to delete). - Line 2:
kubectl delete -f service.yaml. - WHAT: delete the Service.
- WHY: same idea. The Service goes, the cluster stays.
- You should see:
deployment.apps "my-site" deleted
service "my-site" deleted- How to read it: each line names what was deleted.
deployment.appsis the full name for a Deployment.serviceis the full name for a Service. - If it breaks: "not found" means it was already deleted. That is fine. Move on.
Remove the whole cluster when you are done with this lab
kind delete cluster --name devops-practice- WHAT: delete the whole cluster called
devops-practice. - WHY: when you are done with this lab, the cluster only uses disk space and memory. Deleting it frees both.
- Word by word:
kind+delete cluster(remove a cluster) +--name devops-practice(the cluster calleddevops-practice). - You should see:
Deleting cluster "devops-practice" ...
Deleted nodes: ["devops-practice-control-plane"]- How to read it: it says the cluster is being deleted, then lists the node that was deleted.
Deleted nodeslists the machines that were removed. - If it breaks: "no cluster with name" means it was already deleted. Nothing to do.
- Your Docker images stay on your machine, so you can start again any time with
kind create cluster --name devops-practice. - WHAT that means: deleting the cluster does not delete your images. Your
my-site:1.0image is still in Docker, ready to load again.
Note on what is unverified here
This lab was not run end-to-end while writing this kit. That note is at the top of the lesson too, because it matters from the start: treat every step as syntax-checked only, not proven on a real machine. Kind version links change over time. If a download link fails, take the newest link from kind's install page. Mac and Windows steps are unverified here. If a step fails, read the error message first, as in every lab in this kit.
What comes next
Kubernetes runs your app. Phase 1 teaches the data tier your app talks to: Kafka, PostgreSQL with a standby copy, Redis, Moto and a load balancer. The end-to-end lab there runs all of them together on one machine. End-to-end means from the first step to the last step, all together.
Sources
Studied to check how the ideas are explained elsewhere, then rewritten here in plain words. No text was pasted from these pages.
- Kubernetes official tutorials — the people who make Kubernetes explain it in short guided exercises: https://kubernetes.io/docs/tutorials
- TechWorld with Nana (YouTube) — slow, visual explanations of Docker, Kubernetes, and CI/CD ideas, with diagrams: https://www.youtube.com/@TechWorldwithNana
- Docker's official getting-started guide — the toolmaker's own first steps for Docker, in order: https://docs.docker.com/get-started
Advanced — Probes, resources, namespaces, RBAC, ingress, and the old versions
This section is for the reader who already did the lab above. It covers the five things the review of this kit flagged as missing for advanced readers: readiness and liveness probes, resources and limits, namespaces, RBAC, and ingress — plus a note on the old example versions. The probe and resource YAML goes into the same deployment.yaml this lab already teaches, so nothing here needs a new file. The probe and namespace commands were checked against the lab's own files and the Kubernetes docs; the ingress part was not run on this kit, as the section says.
Advanced 1 — First, the old versions: what they mean
What this is: this lesson installs kind v0.23.0 and kubectl v1.29.0, and its cluster reports node version v1.29.2. Those are early-2024 versions. Why it matters: the commands in this lesson still work, but newer releases exist, and a tutorial that names old versions will keep naming them forever.
What to do about it: before you download kind or kubectl, check the current release on the kind releases page and the Kubernetes releases page, and use the current version number in the download address. The version sits in the address itself — the lesson downloads from kind.sigs.k8s.io/dl/v0.23.0/kind-linux-amd64, so a newer kind means a newer number in that same place. Do not copy a version number from a tutorial without checking it first, including this one. Also know: kubectl and the cluster should be close in version — kubectl should stay within one minor version of the cluster, older or newer, or it can behave strangely — so check both numbers, not just one.
Advanced 2 — Probes: implement them, do not just read about them
What this is: a readiness probe is a check that asks "are you ready to take traffic?" A liveness probe asks "are you still alive?" This lesson already defines both, then says "Later, learn readiness and liveness probes". This section is that later. Why they matter: without a readiness probe, the Service sends visitors to a pod that is still starting up, and they get errors. Without a liveness probe, a pod that is stuck — running, but never answering — stays in rotation forever.
Add both probes to the web container in the deployment.yaml this lesson already teaches. Open the file and add these lines under the container, at the same level as ports:
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 3
periodSeconds: 5
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 10
periodSeconds: 10Word by word:
readinessProbe:— the readiness check for this container.httpGet:— the check is a web request (HTTP GET).path: /asks for the home page.port: 80asks on door 80 — the door the container already serves on (containerPort: 80in this same file).initialDelaySeconds: 3— wait 3 seconds after the container starts before the first check. The app needs a moment to start.periodSeconds: 5— check again every 5 seconds.livenessProbe:— the liveness check, same shape, but slower to start (initialDelaySeconds: 10) so a slow start does not look like a dead app.
Check the file first, as in Step 4 — kubectl apply --dry-run=client -f deployment.yaml — then apply it and watch:
kubectl apply -f deployment.yaml
kubectl get podsWord by word: kubectl apply is the command this lesson already teaches. kubectl get pods now shows a READY column that reads 0/1 while the pod is starting and 1/1 once the readiness probe passes. That 1/1 is the proof the probe works: before probes, the pod showed Ready the moment the container started, whether the site answered or not. Then check the probe results in detail:
kubectl describe pod <pod-name>(Use the real pod name from kubectl get pods.) What you should see: in the Containers part, lines naming both probes (Liveness: and Readiness: with the web request), and in the Conditions part, Ready True once the readiness probe passes. If the site is not answering, the Events part at the bottom shows failure lines like Readiness probe failed instead — a passing probe writes no event, a failing one does. A third probe shape exists and is worth knowing by name: an exec probe runs a command inside the container instead of a web request — useful when the app has no web page to ask.
Two warnings that save real incidents. First: a liveness probe that checks something the app needs — like its database — will restart the pod in a loop whenever the database is slow, which makes everything worse. Probe the app itself, not its dependencies. Second: a readiness probe that is too strict keeps the pod out of rotation forever, and the Service has nowhere to send traffic. If all pods are unready, check the probe first.
Advanced 3 — Resources and limits: ask for what you need, cap what you take
What this is: requests are what a pod asks for — the scheduler uses them to choose which machine the pod fits on. Limits are the ceiling — cross them and the pod is throttled (CPU) or killed and restarted (memory). Why they matter: without requests, the scheduler packs pods blindly and a machine fills up. Without limits, one greedy pod can starve every other pod on the same machine.
Add them to the same container, under the probes:
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "250m"Word by word:
requests: memory: "64Mi"— this pod asks for 64 MiB of memory.Mimeans mebibytes (1 MiB is about a million bytes).cpu: "100m"asks for a tenth of a CPU.mmeans millicores:1000mis one whole CPU.limits: memory: "128Mi"— the pod may never use more than 128 MiB; past that, it is killed and restarted.cpu: "250m"— it may use at most a quarter of a CPU; past that, it is slowed down, not killed.
Check the file first, as in Step 4 — kubectl apply --dry-run=client -f deployment.yaml — then apply with kubectl apply -f deployment.yaml again. Then try the command that shows live use:
kubectl top podsWhat you should see — honestly: on a plain kind cluster this may answer with an error saying the metrics server is not available. kind does not install the metrics server by default, and kubectl top needs it. That error is expected, not your mistake. Installing the metrics server is a separate step; know the command exists and what it needs.
Advanced 4 — Namespaces: rooms inside one cluster
What this is: a namespace is a named room inside one cluster. Pods, Services, and Deployments live in a namespace, and names only have to be unique inside their own room. Why it matters: one cluster can hold a practice room, a staging room, and a live room, each separate. Limits and access rules also apply per room.
Try it:
kubectl create namespace practice
kubectl get pods -n practiceWord by word: kubectl create namespace practice makes a room called practice. -n practice means "in the namespace practice". What you should see: No resources found in practice namespace — the room is empty. Deployments go into a room with kubectl apply -f deployment.yaml -n practice, and the same -n flag works on get, describe, and logs. The room you have been using all along is called default — kubectl uses it when you do not say -n. Delete a room with kubectl delete namespace practice, which deletes everything inside it — that is the fastest way to wipe a practice setup, and the reason to be careful with the command.
Advanced 5 — RBAC: who may do what, at concept level
What this is: RBAC (role-based access control) is the rule book for who may do what in a cluster. A Role says what is allowed in one namespace ("may read pods in practice, may not delete them"). A RoleBinding gives that Role to a person or a service. A ClusterRole and ClusterRoleBinding do the same for the whole cluster. Why it matters: the kubectl in this lab runs as cluster-admin — full power over everything. In real clusters nobody works as admin: each person and each service gets the smallest Role that lets them do their job, and nothing more.
This section gives no RBAC commands to run: kind's admin setup is the lab's setup, and real RBAC needs real users and service accounts to bind to. Know the four names, the smallest-permission rule, and the shape: Role says what, Binding says who.
Advanced 6 — Ingress: one front door for many services, at concept level
What this is: an Ingress is one front door that routes by web address and path to many Services — shop.example.com goes to the shop Service, blog.example.com goes to the blog Service. Why it matters: the Services in this lab are reached one at a time. Real clusters have dozens of services behind one door, with TLS ending at that door (see the load balancer lab's Advanced section — the same idea, in Kubernetes).
The Ingress file itself is short, and the shape is real — the Kubernetes rules version is networking.k8s.io/v1:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-site
spec:
rules:
- host: my-site.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: my-site
port:
number: 80Word by word: rules: lists the routing rules. host: my-site.local is the web address this rule matches. path: / with pathType: Prefix means every path starting with /. backend: service: name: my-site, port: 80 means "send it to the Service called my-site on door 80" — the Service this lesson already teaches.
The honest part: an Ingress does nothing until an ingress controller is installed in the cluster — the program that reads Ingress files and actually routes the traffic. kind ships none. Installing one (ingress-nginx is the usual one) is a separate step, and its install page changes — check the current install page, do not copy an old command from a tutorial. This section was not run on this kit for that reason: the YAML above is real, the controller install is not verified here.
What you can now say, truthfully — advanced
- "I know the lesson's kind v0.23.0 and kubectl v1.29.0 are early-2024 versions, and I check the current release before downloading." (Only if you did Advanced 1.)
- "I added readiness and liveness probes to a Deployment and watched the pod's READY column go from 0/1 to 1/1." (Only if you did Advanced 2.)
- "I set resource requests and limits on a pod and can explain what happens when each is crossed." (Only if you did Advanced 3.)
- "I made a namespace, deployed into it with
-n, and can explain Role, RoleBinding, ClusterRole, and Ingress at concept level." (Only if you did Advanced 4, 5, and 6.)
Quick check — try it yourself
Question: In the terminal, type: kubectl rollout status deployment/my-site — what line tells you the app update finished?
Open the practice terminal to test this →
Show answer
You should see deployment "my-site" successfully rolled out.