Guides
How to Deploy Your First App on Kubernetes (Deployment + Service)
By Ravindra Bagale, DevOps trainer · LinkedIn · Published: · Last updated:
Write a Deployment and a Service, kubectl apply, wait for Ready pods, then curl the Service DNS name.
Friends, Deployment runs the pods, Service finds them by label. Chala mitrano — if labels disagree, curl will hang forever.
मित्रांनो, Deployment pods चालवते, Service label ने शोधते. Chala mitrano — labels जुळले नाहीत तर curl अडकते.
मित्रों, Deployment pods चलाता है, Service label से खोजता है। Chala mitrano — labels न मिलें तो curl अटक जाता है।
Quick answer
Hold this vertical picture:
- Write deploy.yaml.
- Write svc.yaml with matching labels.
- kubectl apply.
- kubectl get pods.
- curl from a debug pod.
Language: English · मराठी · हिंदी
First K8s app
Why Deployment + Service
Pods die; you need a controller and a stable address.
Why: Bare pods vanish on node loss.
What: Deployment for replicas; Service for VIP.
How: YAML apply into the API.
Example 1: Deployment YAML
Type this:
mkdir -p /tmp/k8s1 && printf '%s\n' 'apiVersion: apps/v1' 'kind: Deployment' 'metadata:' ' name: web' 'spec:' ' replicas: 2' ' selector:' ' matchLabels:' ' app: web' ' template:' ' metadata:' ' labels:' ' app: web' ' spec:' ' containers:' ' - name: web' ' image: public.ecr.aws/docker/library/nginx:1.27-alpine' ' ports:' ' - containerPort: 80' > /tmp/k8s1/deploy.yaml && head -5 /tmp/k8s1/deploy.yaml
You will see:
What it means: Deployment keeps N pods alive — Flipkart-style web tier.
Example 2: Service YAML
Type this:
printf '%s\n' 'apiVersion: v1' 'kind: Service' 'metadata:' ' name: web' 'spec:' ' selector:' ' app: web' ' ports:' ' - port: 80' ' targetPort: 80' ' type: ClusterIP' > /tmp/k8s1/svc.yaml && grep type /tmp/k8s1/svc.yaml
You will see:
What it means: Service gives a stable virtual IP in front of pods.
Example 3: kubectl apply dry explanation
Type this:
printf '%s\n' 'kubectl apply -f deploy.yaml -f svc.yaml'
You will see:
kubectl apply -f deploy.yaml -f svc.yaml
What it means: apply is declarative — re-run safely.
Concept 1: Labels glue them
Selector must equal pod labels.
Why: Mismatch means empty endpoints.
What: app: web on both sides.
How: get endpoints / get pods -l.
Example 4: get pods pattern
Type this:
printf '%s\n' 'kubectl get pods -l app=web -o wide'
You will see:
kubectl get pods -l app=web -o wide
What it means: Labels must match the Service selector.
Example 5: get svc
Type this:
printf '%s\n' 'kubectl get svc web'
You will see:
What it means: ClusterIP is only reachable inside the cluster unless you use NodePort/Ingress.
Example 11: Label match reminder
Type this:
printf '%s\n' 'Service selector app=web must equal pod label app=web'
You will see:
Service selector app=web must equal pod label app=web
What it means: Mismatch = endpoints empty = curl hangs.
Concept 2: Prove with curl
DNS name equals the Service name.
Why: Guessing from outside the cluster confuses beginners.
What: curl from an in-cluster pod.
How: describe events if stuck.
Example 6: describe for events
Type this:
printf '%s\n' 'kubectl describe deploy web | sed -n "/Events/,+8p"'
You will see:
kubectl describe deploy web | sed -n "/Events/,+8p"
What it means: Events show ImagePullBackOff and failed scheduling.
Example 7: curl from a debug pod idea
Type this:
printf '%s\n' 'kubectl run curl --rm -it --image=public.ecr.aws/docker/library/curlimages/curl:8.5.0 -- curl -s http://web/'
You will see:
kubectl run curl --rm -it --image=public.ecr.aws/docker/library/curlimages/curl:8.5.0 -- curl -s http://web/
What it means: DNS name web resolves via ClusterIP.
Example 12: Ready vs Running
Type this:
printf '%s\n' 'Running is not enough — Ready 1/1 means probes passed'
You will see:
Running is not enough — Ready 1/1 means probes passed
What it means: Infosys interviews love this distinction.
Concept 3: Scale and rollout
Change replicas; wait for status.
Why: Leaving halfway rolls confuses users.
What: scale + rollout status.
How: Clean up lab with delete -f.
Example 8: Scale replicas
Type this:
printf '%s\n' 'kubectl scale deploy/web --replicas=3'
You will see:
kubectl scale deploy/web --replicas=3
What it means: Deployment controller creates the extra pods.
Example 9: Rollout status
Type this:
printf '%s\n' 'kubectl rollout status deploy/web'
You will see:
kubectl rollout status deploy/web
What it means: Wait until new pods are Ready before you celebrate.
Example 10: Delete safely
Type this:
printf '%s\n' 'kubectl delete -f svc.yaml -f deploy.yaml'
You will see:
kubectl delete -f svc.yaml -f deploy.yaml
What it means: Lab cleanup — never delete prod without a ticket.
First app card
1 Deployment 2 Service 3 apply 4 get pods 5 curl Service DNS
Suppose: endpoints empty
Fix label selector vs pod labels.
Suppose: ImagePullBackOff
Check image name and registry access.
Ravindra Bagale's Tip
At Amazon and Flipkart interviews, expect to draw Deployment + Service and explain ClusterIP vs NodePort in one minute.
Amazon आणि Flipkart interviews मध्ये Deployment + Service आणि ClusterIP vs NodePort एका मिनिटात सांगा.
Amazon और Flipkart interviews में Deployment + Service और ClusterIP vs NodePort एक मिनट में बताएँ।
Check yourself (quiz)
Q1. Who keeps replicas?
Deployment controller
Q2. Stable IP?
Service ClusterIP
Q3. Glue?
Labels and selectors
Q4. Empty endpoints?
Label mismatch
Q5. Ready meaning?
Probes passed / containers ready
Q6. curl from where?
Inside the cluster for ClusterIP
Reading tracking
Mark this guide when you finish. Your browser remembers it on this device.
YAML → apply → Ready → curl.
Did you understand? Let us try it once more.
Frequently asked questions
Pod vs Deployment?
Deployment owns replica Pods.
Why a Service?
Stable name and IP while pods churn.
ClusterIP reachability?
Inside the cluster only.
Empty endpoints?
Label selector mismatch.
ImagePullBackOff?
Bad image name or registry auth.
NodePort?
Opens a port on each node — next step after ClusterIP.