← Back to list

Day 4/30: The Immortality Engine: Mastering Deployments and YAML

The Real-Time Scenario: The Silent Crash

Vishnuvardhanreddy · 2026-05-27 05:18 · 0 claps · 1.8 min read
#kubernetes
Open on Medium ↗
Wiki topics: ☁️ · DevOps & Cloud

Day 4/30: The Immortality Engine: Mastering Deployments and YAML

The Real-Time Scenario: The Silent Crash

Imagine your Node.js application is running as a single, naked Pod in your cluster. It’s Black Friday, and the app is processing thousands of orders. Suddenly, the underlying EC2 instance hits a kernel panic and dies.

If you deployed a naked Pod, that Pod is gone forever. Your users are getting 502 Bad Gateway errors until you wake up, open your laptop, and deploy a new Pod. This is unacceptable. We need a system that constantly monitors health and instantly replaces casualties.

The Solution: Deployments & ReplicaSets

In Kubernetes, we achieve high availability using a Deployment. A Deployment is a blueprint. It does not run containers directly; instead, it manages a ReplicaSet.

  • The ReplicaSet’s only job: Ensure that a specified number of Pod replicas are running at any given exact millisecond.
  • The Deployment’s job: Manage the ReplicaSet and handle version updates (like rolling out v2.0 of your app without dropping traffic — which we will cover next week!).

Infrastructure as Data: Writing YAML

Kubernetes uses YAML (YAML Ain’t Markup Language) to define the “Desired State”. Here is what a professional Deployment looks like:

YAML

apiVersion: apps/v1
kind: Deployment
metadata:
  name: java-api-deployment
spec:
  replicas: 3 # The Magic Number: We want 3 clones!
  selector:
    matchLabels:
      app: java-api # How the ReplicaSet knows which pods it owns
  template: # The blueprint for the Pods it will stamp out
    metadata:
      labels:
        app: java-api
    spec:
      containers:
      - name: java-app
        image: my-repo/java-api:v1.0
        ports:
        - containerPort: 8080

To apply this to your cluster, you simply run: kubectl apply -f deployment.yaml

If you run kubectl get pods, you will see 3 perfectly identical Pods spinning up. If you intentionally delete one (kubectl delete pod <pod-name>), Kubernetes will instantly spawn a brand new one to replace it in less than a second.

Troubleshooting / Dev Gotcha: Editing the Wrong Thing

A classic beginner mistake is trying to troubleshoot a Deployment by manually editing the Pod. If you find a typo in an environment variable inside a running Pod and try to fix it using kubectl edit pod, the moment that Pod restarts, your changes will vanish!

Why? Because the ReplicaSet will look at the Pod, realize it no longer matches the Deployment template, kill it, and stamp out a new one using the old blueprint. The Golden Rule: Never edit a Pod managed by a Deployment. Always edit the deployment.yaml file and run kubectl apply -f again. Let Kubernetes orchestrate the changes!


메타데이터
post_id
5eb92609e16a
slug
day-4-30-the-immortality-engine-mastering-deployments-and-yaml-5eb92609e16a
url
https://medium.com/@vishnuvardhanreddy8654/day-4-30-the-immortality-engine-mastering-deployments-and-yaml-5eb92609e16a
canonical_url
https://medium.com/@vishnuvardhanreddy8654/day-4-30-the-immortality-engine-mastering-deployments-and-yaml-5eb92609e16a
author_url
https://medium.com/@vishnuvardhanreddy8654
status
ok
fetched_at
2026-06-09 15:37:30