Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
How do I make bash script wait until kubernetes pods restart?

I am writing a script, where I want to restart kubernetes pods with the scale-down scale-up method

kubectl scale --replicas=0 myPod -n myNamespace
kubectl scale --replicas=3 myPod -n myNamespace

I would like the script to wait until the pods are Running - so I thought something like

while kubectl get pods --field-selector=status.phase=Running -n myNameSpace | grep -c myPod = 3;
    do
        sleep 1
        echo "."
    done

could work - but no dice. The = 3 part doesn't work. I can't just use

while kubectl get pods --field-selector=status.phase!=Running -n myNameSpace | grep -c myPod > /dev/null

since the pods start in sequence, and I could get unlucky by querying just as one pod deployed, and others didn't even start.

How can I ensure that the script continues only after all 3 of the pods are Running?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Write your condition in [ ] and get the value of command with ` or $. for example in your case:

while [ "$(kubectl get pods --field-selector=status.phase=Running -n myNameSpace | grep -c myPod)" != 3 ]

  do
    sleep 1
    echo "wait"
  done

echo "All three pods is running and continue your script"
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!