Posts

What is a Pod Environment Variable

 An environment variable is just a key-value pair that you pass into a container at runtime, so the application inside can read it without you hardcoding values in code or image. In Kubernetes, Pods support environment variables through the container spec: env:   - name: DB_USER     value: admin echo $DB_USER # admin 2. Why use environment variables in Pods? They help you: Make apps configurable without rebuilding the image → You can change DB_HOST or API_KEY by updating YAML, no code change. Separate secrets & configs from code → Avoid hardcoding credentials in the container image. Control behavior for different environments (dev, staging, prod) → Same image, different environment variables. Read runtime data from Kubernetes → Pull Pod metadata (name, namespace, IP, etc.) into your app automatically. 3. Ways to set Environment Variables in Pods A. Hardcoded values Good for small static values. env: - name: MODE value: producti...

Question 3

  Question No: 3 Create a new deployment called my-deployment . Scale the deployment to 3 replicas. Make sure the desired number of pods are always running. Ek naya deployment create karo jiska naam my-deployment ho. Is deployment ko 3 replicas tak scale karo. Ye ensure karo ki desired number of pods hamesha running rahein.  Solution Step 1: Deployment Create Karo kubectl create deployment my-deployment --image=nginx Step 2: Deployment ko 3 Replicas Tak Scale Karo kubectl scale deployment my-deployment --replicas=3 Step 3: Verify Karo Ki 3 Pods Chal Rahe Hain kubectl get deployments kubectl get pods Step 4: Ensure Karo Ki Desired Pods Hamesha Running Rahein Kubernetes khud crashed ya delete hua pod automatically restart kar dega. Test karne ke liye ek pod delete karke check kar sakte ho: kubectl delete pod <pod-name> kubectl get pods # Check karo ki naya pod create ho raha hai ya nahi