Zero Labs
Industry News / AI

Your First Kubernetes Deployment: From Zero to Running App

Source · Towards AI By Swapnil Ahire

From the publisher’s feed, collected in the ZeroLabs newsroom.

Write one YAML file, run three commands, then do something oddly satisfying: kill a Pod on purpose and watch Kubernetes bring it right back.your-first-kubernetes-deployment-tutorialThere’s a specific moment in learning Kubernetes that actually makes it click — and it’s not reading about Pods or Nodes. It’s watching Kubernetes fix something you just deliberately broke, without you touching a single command to fix it.That moment is the whole point of this tutorial. We’re going to deploy a real, simple app to a local cluster, then kill one of its Pods on purpose — just to watch Kubernetes notice, and quietly bring it back to life within seconds. If you’ve read the earlier pieces in this series about what Pods, Nodes, and Control Planes actually are, this is where that theory turns into something you can watch happen on your own screen.No prior hands-on Kubernetes experience required. Just a terminal, ten minutes, and a local cluster.Reading about self-healing is one thing. Watching a crashed Pod come back to life in three seconds, unassisted, is the moment Kubernetes stops being an abstract concept.What You’ll Need Before StartingYou’ll need kubectl (the command-line tool for talking to a Kubernetes cluster) and a running local cluster — Minikube, Kind, or k3d all work fine here, and if you're deciding between them, that's exactly what the previous article in this series walks through. For this tutorial, the examples assume Minikube, but the commands work identically regardless of which local cluster tool you're using, since kubectl doesn't know or care which one is underneath.If you haven’t got a cluster running yet, this gets you there in one line:minikube startkubectl get nodesIf that second command prints a Node with a Ready status, you're good to go.Key takeaway: Once your cluster is running, every command from here on works identically no matter which local Kubernetes tool put that cluster there.Step 1: Understand What We’re Actually DeployingBefore writing any YAML, it helps to know what a Deployment actually is in Kubernetes, because it’s doing more work than the name suggests. A Deployment isn’t just “start this app.” It’s a standing instruction that says: “I want this many copies of this app running, at all times, and if reality ever drifts from that — a Pod crashes, a Node dies — fix it automatically until reality matches what I asked for.”That’s the entire mechanism behind self-healing, spelled out in plain language. You’re not writing a script that restarts things. You’re declaring a desired state, and Kubernetes’s Control Plane spends its entire existence continuously nudging the real world back toward that state.We’re going to deploy a small, harmless web server called nginx — the "hello world" of container tutorials for good reason: it starts instantly, needs no configuration, and gives you something visibly real to check.Step 2: Write Your First deployment.yamlCreate a file called deployment.yaml and paste this in:apiVersion: apps/v1kind: Deploymentmetadata: name: my-first-appspec: replicas: 3 selector: matchLabels: app: my-first-app template: metadata: labels: app: my-first-app spec: containers: - name: nginx image: nginx:latest ports: - containerPort: 80This looks like more than it is, so let’s break it down piece by piece, because understanding each line matters more than copy-pasting it blindly.kind: Deployment — tells Kubernetes what type of object this is.replicas: 3 — this is the important one. You're asking for three identical Pods running this app, at all times. This single number is what makes the self-healing demo later actually visible.selector and labels — this is how the Deployment identifies which Pods belong to it. Think of app: my-first-app as a name tag Kubernetes uses to keep track of which Pods it's responsible for.containers — the actual container image to run (nginx:latest) and which port it listens on.Key takeaway: replicas: 3 is the whole reason self-healing has something visible to demonstrate — Kubernetes isn't just restarting a Pod, it's continuously enforcing "there must be exactly three."Step 3: Deploy ItFrom the same folder as your file, run:kubectl apply -f deployment.yamlYou should see a short confirmation that the Deployment was created. Now check on it:kubectl get deploymentskubectl get podsThe second command is the one that matters most here — you should see three Pods, each with a name like my-first-app-xxxxxxxxxx-xxxxx, and a STATUS of Running. If you're seeing Running next to all three, congratulations — you've just deployed your first real application to Kubernetes, and the Control Plane is already quietly watching over it.Step 4: Actually See the App RunningA Deployment on its own isn’t reachable from outside the cluster yet — it needs a Service to expose it. Rather than turning this into a networking deep-dive, the fastest way to peek at your running app is port-forward, which temporarily tunnels a port on your machine straight to a Pod:kubectl port-forward deployment/my-first-app 8080:80Now open http://localhost:8080 in your browser. You should see the default nginx welcome page. That's not a simulation — that's a real container, running inside a real Kubernetes Pod, serving a real HTTP response back to your browser.Leave that terminal running for a moment, then open a new terminal window for the next step — this is where it gets genuinely fun.Key takeaway: port-forward is a quick way to peek at a running Pod locally — it's a debugging convenience, not how you'd expose an app in production (that's what Services and Ingress are for, a topic worth its own article).Step 5: Kill a Pod on PurposeThis is the moment the whole tutorial has been building toward. In your new terminal, list your Pods again and copy one of the exact Pod names:kubectl get podsNow delete it, deliberately, on purpose, no mercy:kubectl delete pod Immediately run:kubectl get podsHere’s what you’ll actually see: the Pod you deleted will show as Terminating, and — almost immediately — a brand new Pod, with a different name, will appear with STATUS: ContainerCreating, then quickly flip to Running. Run kubectl get pods a couple more times over the next few seconds and watch it settle back to exactly three healthy Pods, just like before.You didn’t restart anything. You didn’t write a recovery script. You killed a Pod, and Kubernetes noticed the gap between “3 desired” and “2 actual,” and closed it — on its own, in seconds.What Just Actually Happened, TechnicallyFor the curious — here’s the mechanism in slightly more detail, without turning this into a deep architectural dive. The Control Plane’s scheduler and controller components continuously watch cluster state. When you deleted that Pod, the Deployment controller detected that the actual replica count had dropped from three to two, compared that against the desired count of three defined in your YAML, and immediately created a new Pod to close that gap. The new Pod got scheduled onto an available Node, the container image was pulled if not already cached locally, and the container started — all in the handful of seconds you probably watched go by in your terminal.Nothing about this was special-cased for “Pod deletion” specifically. The exact same mechanism handles a Pod crashing due to an application bug, a Node failing entirely, or you manually deleting a Pod just to see what happens. From Kubernetes’s perspective, all three scenarios look identical: actual state drifted from desired state, so fix it.Cleaning UpOnce you’re done experimenting, tear down what you created:kubectl delete -f deployment.yamlAnd if you want to stop the local cluster entirely:minikube stopNothing here costs you anything, and nothing here is permanent — which is exactly the point of practicing on a local cluster in the first place.Why This Exercise Matters More Than It SeemsIt’s easy to read about self-healing in an architecture diagram and nod along without it really landing. Watching it happen — on your own terminal, against a Pod you deleted with your own hands — tends to stick in a way that reading never quite does.This is also, practically speaking, the foundation almost everything else in Kubernetes builds on top of. Auto-scaling is this same mechanism, just triggered by load metrics instead of a manual delete. Rolling updates are this same mechanism, gradually replacing old Pods with new ones while maintaining the desired replica count throughout. Once “declare a desired state, and let the Control Plane continuously enforce it” genuinely clicks, a surprising amount of Kubernetes stops feeling like memorized commands and starts feeling like one consistent idea, applied repeatedly.Go ahead and try killing two Pods at once, or scaling replicas up to five and watching what happens — the exercise gets more interesting the more you deliberately try to break it.Your First Kubernetes Deployment: From Zero to Running App was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.