Ravindra BagaleCourses & study guides मराठी Track your progress

Guides

Kubernetes वर पहिली App Deploy कशी करावी (Deployment + Service)

Deployment + Service YAML, kubectl apply, Ready pods, Service DNS वर curl.

Friends, Deployment runs the pods, Service finds them by label. Chala mitrano — if labels disagree, curl will hang forever.

Quick answer

Hold this vertical picture:

  1. deploy.yaml.
  2. svc.yaml matching labels.
  3. apply.
  4. get pods.
  5. debug pod मधून curl.

Language: English · मराठी · हिंदी

Deployment YAMLPods desired Service YAMLStable VIP kubectl applyAPI accepts get pods/svcCheck Ready curl via DNSweb hostname
First K8s app

Deployment + Service का

Pods मरतात; controller + VIP.

Why: Bare pods निघून जातात. What: Deployment + Service. How: kubectl apply.

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:

apiVersion: apps/v1

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:

type: ClusterIP

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

Selector = pod labels.

Why: Mismatch = empty endpoints. What: app: web. How: 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:

kubectl get svc web

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: curl

DNS = Service name.

Why: बाहेरून ClusterIP गोंधळ. What: in-cluster curl. How: describe events.

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

replicas बदला; status.

Why: Halfway rollout. What: scale + rollout status. How: 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

Suppose: empty endpoints

Labels.

Suppose: ImagePullBackOff

Image/registry.

Ravindra Bagale's Tip

At Amazon and Flipkart interviews, expect to draw Deployment + Service and explain ClusterIP vs NodePort in one minute.

Check yourself (quiz)

Q1. Replicas?

Deployment

Q2. VIP?

Service

Q3. Glue?

labels

Q4. Empty?

mismatch

Q5. Ready?

probes

Q6. curl?

in-cluster

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.