Tuesday, March 18, 2025

🛠 Managing Kubernetes Pods – Running and Controlling Containerized Applications

 

Managing Kubernetes Pods – Running and Controlling Containerized Applications

In Kubernetes, Pods are the fundamental unit for running applications. Managing Pods efficiently is crucial for deploying, scaling, and maintaining applications in a Kubernetes cluster.


🌍 Shape Your Future with AI & Infinite Knowledge...!!

🌐 Want to Generate Text-to-Voice, Images & Videos? 👉 http://www.ai.skyinfinitetech.com 📚 Read In-Depth Tech & Self-Improvement Blogs 👉 http://www.skyinfinitetech.com ▶ Watch Life-Changing Videos on YouTube 👉 https://www.youtube.com/@SkyInfinite-Learning 🔥 Transform Your Skills, Business & Productivity – Join Us Today! 🔥



📦 What is a Pod in Kubernetes?

A Pod is the smallest deployable unit in Kubernetes and consists of one or more containers that share:

Network – Containers inside the same Pod communicate using localhost.
Storage – Shared volumes can be mounted for persistent data.
Lifecycle – All containers in a Pod start, stop, and restart together.

🔹 Pods are ephemeral, meaning they can be terminated and recreated automatically by Kubernetes.



🏗 Creating a Pod in Kubernetes

You can create a Pod using the kubectl command or a YAML file.

🔹 Using kubectl Command


kubectl run mypod --image=nginx

🔹 This command creates a Pod named mypod running an nginx container.


🔹 Using a YAML File

yaml

apiVersion: v1 kind: Pod metadata: name: mypod spec: containers: - name: nginx-container image: nginx ports: - containerPort: 80

🔹 Save this as mypod.yaml and apply it using:


kubectl apply -f mypod.yaml


🔍 Viewing Pod Details

Once a Pod is created, you can check its status and logs:

🔹 List all running Pods


kubectl get pods

🔹 Displays all Pods running in the cluster.


🔹 Describe a specific Pod


kubectl describe pod mypod

🔹 Shows detailed information about the Pod, including events and errors.


🔹 Check Pod logs


kubectl logs mypod

🔹 Displays the logs from the container inside the Pod.


🔹 Access a running Pod's shell


kubectl exec -it mypod -- /bin/sh

🔹 Opens a shell inside the Pod, allowing you to run commands interactively.



🔄 Managing Pods

🔹 Deleting a Pod


kubectl delete pod mypod

🔹 This removes the Pod, but if it’s managed by a Deployment, it will be recreated.


🔹 Restarting a Pod


kubectl delete pod mypod --grace-period=0 --force

🔹 This forcefully deletes the Pod, causing Kubernetes to restart it if managed by a Deployment.



🚀 Scaling and Replicating Pods

Since Pods are ephemeral, Kubernetes does not recommend managing individual Pods manually. Instead, use Deployments or ReplicaSets for scalability.

🔹 Creating a Deployment with multiple replicas


kubectl create deployment myapp --image=nginx --replicas=3

🔹 This ensures that Kubernetes maintains 3 running Pods for high availability.


🔹 Scaling a Deployment


kubectl scale deployment myapp --replicas=5

🔹 Adjusts the number of running Pods dynamically.



🏆 Summary – Managing Kubernetes Pods at a Glance

CommandDescription
kubectl runCreate a new Pod
kubectl get podsList running Pods
kubectl describe pod <pod_name>View Pod details
kubectl logs <pod_name>View container logs
kubectl exec -it <pod_name> -- /bin/shAccess Pod’s shell
kubectl delete pod <pod_name>Remove a Pod
kubectl scale deployment <name> --replicas=<num>Scale Pods dynamically

📢 Next Up: Kubernetes Networking – Communication Between Pods, Services, and Ingress!

No comments:

Post a Comment

Terraform State Deep Dive: Why it's Crucial and How to Manage It

Terraform State Deep Dive: Why it's Crucial and How to Manage It ...