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

288
Views
Is there any way to run a script with arguments for kubernetes pods?

I have a script to extract the logs of crushed pods, but i want also to give as a parameter the pod names (In case I need also the logs from other pods, not just crushed ones). My script looks like this:

#!/bin/bash

y=1;
for pod in "$@"
do
        echo "Pod name: $y: $pod";
        y=$((y + 1));
done

CrashLoopBackOff=`for i in $(kubectl get po -n namespace |grep CrashLoopBackOff | awk '{print $1}'); do echo $i; done`

echo "Pods in CrashLoopBackOff: "
echo
echo ======= $CrashLoopBackOff ==========
echo
arr2=()
while read -r CrashLoopBackOff _; do
  while IFS= read -r line; do
    arr2+=("$CrashLoopBackOff: $line")
  done < <(kubectl logs "$CrashLoopBackOff" -n namespace| tail -10)
done < <(kubectl get po -n namespace| grep CrashLoopBackOff)

printf %s\\n "${arr2[@]}"

But seems that if I pass the pods name as arguments, the output is just for the crushed pod. I don't have so much experience with scripting and I got stuck here, any help is appreciated. Thank you

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can add this at the end of the file:

for pod in $@
do
  echo "Printing logs for requested pod $pod"
  kubectl logs -n namespace $pod | tail -n 10
done

Hope that helps to progress 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!