AWS Builder Center

Kubernetes Doesn’t Have to Be Scary – Delete a Pod and Watch Kubernetes Bring It Back! Part 2

In my previous article, we explored Kubernetes using Minikube, created our first local cluster, and deployed a simple application. But today, let's do something different.

Volunteer @aws user group ahmedabad | AWSome
What happens if you accidentally delete your running application?
Does Kubernetes panic? Does your application disappear forever?
Let's find out!

1. First, Check Your Running Pods

Before breaking anything, let's check whether our application is running.
kubectl get pods
You should see something similar to this:
NAME READY STATUS RESTARTS
hello-minikube-xxxxxxxxxx-xxxxx 1/1 Running 0
Your application is running successfully!

2. Let's Do Something Dangerous: Delete the Pod!

Now, let's delete the running Pod.
First, copy your actual Pod name from the previous command.
kubectl delete pod <your-pod-name>
Example:
kubectl delete pod hello-minikube-xxxxxxxxxx-xxxxx
You should see:
pod "hello-minikube-xxxxxxxxxx-xxxxx" deleted
Wait! Did we just delete our application?
Not exactly.

3. The Magic of Kubernetes: Self-Healing!

Now run this command again:
kubectl get pods
You might notice something interesting.
A new Pod appears with a different name!
NAME READY STATUS RESTARTS
hello-minikube-yyyyyyyyyy-yyyyy 1/1 Running 0
What just happened?
Your Kubernetes Deployment noticed that the desired number of Pods was no longer available.
It automatically created a replacement Pod to maintain the desired state.
This is called Self-Healing.
Think of it like an automatic backup player in a cricket team. If one player leaves the field, another player steps in!
That's one of the reasons Kubernetes is so powerful.

4. Understand What's Managing Your Application

Let's inspect our Deployment:
kubectl get deployments
You should see something like:
NAME READY UP-TO-DATE AVAILABLE
hello-minikube 1/1 1 1
Now, let's explore the Deployment in more detail:
kubectl describe deployment hello-minikube
Look for the Replicas section.
It tells Kubernetes how many Pod replicas should be running.

5. Let's Scale Our Application!

What if one Pod isn't enough?
Let's increase the number of replicas from 1 to 3.
Run:
kubectl scale deployment hello-minikube --replicas=3
Now check:
kubectl get pods
Amazing! You should now see three running Pods.
You just scaled your application without manually creating three separate Pods.
Want to scale it back?
kubectl scale deployment hello-minikube --replicas=1
Kubernetes will reduce the number of Pods to one.

6. Bonus: Clean Up Your Environment

Finished experimenting?
Delete your Deployment:
kubectl delete deployment hello-minikube
Check your Pods:
kubectl get pods
Your application Pods should now be gone.

What Did We Learn Today?

By running just a few commands, you learned three important Kubernetes concepts:
  1. Pod Deletion: How to delete a running Pod.
  1. Self-Healing: How Kubernetes automatically replaces a deleted Pod when managed by a Deployment.
  1. Scaling: How to increase or decrease the number of application replicas.
And the best part? You did all of this locally using Minikube!

What's Coming Next?

In the next article, we'll explore something equally interesting:
How do we access our application from outside the Kubernetes cluster?
We'll learn about Kubernetes Services, create our first Service, and expose our application using Minikube.
Because deploying an application is only half the journey. Making it accessible is the other half!
If you're learning Kubernetes alongside me, drop a comment and share your experience.
Let's learn, experiment, break things, and grow together!
Happy Learning! 🚀
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article