Kubernetes looks big from the outside. The docs use a lot of new words at once, and the first YAML file can feel like a wall of fields. It gets simpler once you learn the three objects that do most of the work: Pods, Deployments, and Services. If you understand those three, you can run a real application on Kubernetes. This post starts from zero, explains what each object does, and shows working YAML for each one.
What a cluster is, in plain terms
A Kubernetes cluster is a group of machines that run containers for you. One machine, called the control plane, decides where work should run. The other machines, called nodes, run the work. You describe the state you want, and the control plane keeps moving the cluster toward that state. You do not log in to a node and start a container by hand. You send a description to the API server, and if a container crashes, the control plane starts a new one. That loop, describe the state you want and let the system maintain it, is the core idea behind Kubernetes.
You talk to the cluster with kubectl. It reads a config file that points at a cluster and sends your requests to the API server. Most commands follow the same pattern: get, describe, apply, delete. Learn those four and you can do most daily work.
Pods: the smallest unit
A Pod is the smallest thing Kubernetes runs. It wraps one or more containers that share a network address and storage. In practice, most Pods hold a single container. The extra containers in a Pod are usually helpers, like a sidecar that ships logs or a proxy that handles traffic.
A Pod is not meant to last. It gets an IP address when it starts, and that address goes away when the Pod dies. You should never build anything that depends on a specific Pod staying alive or keeping the same IP. Kubernetes replaces Pods all the time, during deploys, node maintenance, and failures. Your application has to be fine with that.
Here is a Pod that runs a simple web server:
apiVersion: v1
kind: Pod
metadata:
name: web
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
Save it as pod.yaml and apply it:
kubectl apply -f pod.yaml
kubectl get pods
kubectl describe pod web
get shows the status. describe shows the detail: which node it landed on, the events that happened while it started, and any errors. When a Pod fails to start, describe is the first place to look. You can also see logs with kubectl logs web and run a shell inside a running container with kubectl exec -it web -- /bin/sh.
Pods on their own have a problem. If the Pod dies, nothing brings it back. That is why you almost never create Pods directly in production. You create a Deployment instead, and the Deployment creates and manages the Pods for you.
Deployments: the manager for your Pods
A Deployment says how many copies of a Pod you want and which container image they should run. It creates a ReplicaSet, which is the object that actually keeps the count correct. If a Pod dies, the ReplicaSet starts a replacement. If you ask for three copies, you get three copies, and the count stays at three.
Here is a Deployment for the same web server, with three replicas:
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
labels:
app: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
containers:
- name: web
image: nginx:1.27
ports:
- containerPort: 80
resources:
requests:
memory: "64Mi"
cpu: "100m"
limits:
memory: "128Mi"
cpu: "250m"
A few things in this file deserve attention. The selector tells the Deployment which Pods it owns, by label. The template is the Pod spec the Deployment stamps out for each replica, and its labels must match the selector. The resources block sets requests and limits. A request is what the container needs to run, and the scheduler uses it to pick a node with enough free capacity. A limit is the most the container may use. Without requests, the scheduler is guessing. Without limits, one bad container can starve the rest of the node.
Apply it and watch what happens:
kubectl apply -f deployment.yaml
kubectl get deployments
kubectl get pods -l app=web
kubectl get replicasets
Delete one Pod and watch the count recover:
kubectl delete pod <pod-name>
kubectl get pods -l app=web
A new Pod appears with a new name and a new IP. The Deployment did not care which Pod you deleted. It only cared that the count was wrong, and it fixed the count. That is the behavior you want in production: the system repairs itself without a person being paged for every single Pod failure.
Updating without downtime
Deployments also handle updates. Change the image tag, apply the file again, and the Deployment rolls out the new version one Pod at a time. The old Pods keep serving traffic until the new ones are ready. If the new version is broken, roll back with one command: kubectl rollout undo deployment/web. A bad deploy becomes a rollback instead of an incident. You can also set maxSurge: 1 and maxUnavailable: 0 in the strategy, so the rollout never takes a Pod down until a new one is ready.
Services: a stable address for shifting Pods
Pods come and go, and their IP addresses change each time. A Service gives you a stable address that does not change. It selects Pods by label and sends traffic to the ones that are currently healthy. When a Pod dies and a replacement starts, the Service picks up the new Pod automatically.
There are three Service types you will use most.
A ClusterIP Service is only reachable inside the cluster. It is the default, and it is the right choice for traffic between your own services.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
type: ClusterIP
A NodePort Service opens a port on every node and forwards traffic to the Service. It is useful for quick testing, but it is not how you expose production traffic.
A LoadBalancer Service asks the cloud provider for a load balancer with a public IP. On managed Kubernetes, this is the simplest way to expose a service to the internet. The cloud provider creates the load balancer, and the Service routes traffic from it to your Pods.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 80
type: LoadBalancer
Apply the Service, then check it:
kubectl apply -f service.yaml
kubectl get svc web
kubectl describe svc web
The describe output lists the endpoints, which are the current Pod IPs behind the Service. Delete a Pod and run describe again. The endpoint list updates on its own. That is the whole point. Your callers talk to the Service name, and the Service handles the fact that the Pods behind it keep changing. Inside the cluster, other Pods reach this Service at http://web, because Kubernetes DNS resolves the Service name.
Putting the three together
Here is the mental model to carry forward. A Pod runs your container. A Deployment keeps the right number of Pods running and rolls out updates. A Service gives those Pods a stable address and spreads traffic across them. Most of your daily work is editing one of these three objects.
Common first mistakes
A few mistakes show up again and again for people learning Kubernetes. Knowing them in advance saves hours.
Forgetting the label match. The Deployment selector, the Pod template labels, and the Service selector all have to agree. If they do not, the Deployment creates Pods but the Service finds nothing, or the Deployment reports zero available replicas. When traffic does not reach your app, check the labels first.
Using latest as the image tag. The latest tag moves, so two Pods can run different code while claiming the same tag. It also makes rollbacks unclear. Pin a version tag or a digest. The same build should produce the same image everywhere, which is also how CI/CD promotes one build across environments instead of rebuilding per environment.
Skipping resource requests. Without requests, the scheduler packs Pods onto nodes until the node runs out of room. The first sign of trouble is Pods getting evicted or containers getting killed for memory. Set requests from the start, even rough ones, and adjust them as you learn how the app actually behaves.
Treating Pods as pets. If you find yourself caring about a specific Pod name or IP, stop. The unit you manage is the Deployment. Pods are disposable by design. Any state your app needs must live outside the Pod, in a database or a volume, not in the container filesystem.
Applying and not checking. kubectl apply succeeding only means the API server accepted your YAML. It does not mean the Pods are running. Always follow an apply with kubectl get pods and kubectl rollout status.
A small practice exercise
Use a local cluster or a small managed cluster, and work through these steps: create the Pod, check its logs, then delete it. Create the Deployment with three replicas, delete one Pod, and watch it come back. Change the image tag and watch the rollout, then roll it back. Create the Service, check the endpoints, delete a Pod, and check them again. That exercise covers the core loop.
Checklist
- [ ] I can explain what a Pod, a Deployment, and a Service each do
- [ ] I have applied a Deployment and watched a deleted Pod get replaced
- [ ] I have rolled out an image change and rolled it back
- [ ] I have created a Service and seen its endpoints update after a Pod restart
- [ ] My Deployments set CPU and memory requests and limits
- [ ] My image tags are pinned to a version, not
latest - [ ] I check
kubectl get podsandrollout statusafter every apply
Closing
Kubernetes is a lot of objects, but you only need three to start. Pods run containers. Deployments keep them running and update them safely. Services give them a stable address. Learn those three well, practice the exercise above, and the rest of the platform will make more sense when you meet it.
Next article: how Pods talk to each other, what Ingress does, and storage that survives a restart.
Top comments (0)