Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

279
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda