Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 04-while-loop-devops-usecases.md #75

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Day-09/04-while-loop-devops-usecases.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,33 @@ DevOps engineers often use "while" loops in various real-time use cases to autom

DevOps engineers often use "while" loops in CI/CD pipelines to monitor the deployment status of applications. They can create a "while" loop that periodically checks the status of a deployment or a rolling update until it completes successfully or fails. For example, waiting for a certain number of pods to be ready in a Kubernetes deployment:

In Linux:
```bash
while kubectl get deployment/myapp | grep -q 0/1; do
echo "Waiting for myapp to be ready..."
sleep 10
done
```
```
In Python:
import subprocess
import time

while True:
result = subprocess.run(
["kubectl", "get", "deployment/myapp"],
capture_output=True,
text=True
)

if "0/1" not in result.stdout:
break # Exit loop when the deployment is ready

print("Waiting for myapp to be ready...")
time.sleep(10)

print("myapp is ready!")
```

2. **Provisioning and Scaling Cloud Resources:**

Expand Down