0
0
Kubernetesdevops~10 mins

Desired replicas vs actual replicas in Kubernetes - Hands-On Comparison

Choose your learning style9 modes available
Desired replicas vs actual replicas
📖 Scenario: You are managing a Kubernetes deployment for a web application. You want to check if the number of running pods matches the desired number of replicas specified in the deployment configuration.
🎯 Goal: Build a simple script that stores the desired number of replicas and the actual number of running pods, compares them, and prints whether the deployment is healthy or not.
📋 What You'll Learn
Create a variable desired_replicas with the exact value 3
Create a variable actual_replicas with the exact value 2
Write a comparison to check if desired_replicas equals actual_replicas
Print "Deployment is healthy" if they match, otherwise print "Deployment is not healthy"
💡 Why This Matters
🌍 Real World
Kubernetes operators and DevOps engineers often need to verify if the actual running pods match the desired replicas to ensure application availability.
💼 Career
Understanding how to compare desired and actual states is fundamental for monitoring and troubleshooting Kubernetes deployments in real jobs.
Progress0 / 4 steps
1
Set desired replicas
Create a variable called desired_replicas and set it to the integer 3.
Kubernetes
Need a hint?

Use the assignment operator = to set desired_replicas to 3.

2
Set actual replicas
Create a variable called actual_replicas and set it to the integer 2.
Kubernetes
Need a hint?

Use the assignment operator = to set actual_replicas to 2.

3
Compare desired and actual replicas
Write an if statement that compares desired_replicas and actual_replicas using ==.
Kubernetes
Need a hint?

Use if desired_replicas == actual_replicas: to check equality and assign the status variable accordingly.

4
Print deployment status
Write a print statement to display the value of the variable status.
Kubernetes
Need a hint?

Use print(status) to show the deployment health message.