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

214
Views
Comando kubectl para encontrar un estado de pod particular como listo

Quería presionar un comando que busca el pod con el nombre del servicio e identificar el estado de su pod como "Listo"

Probé algunos de los comandos pero no funciona y no busca con service-name.

 kubectl get svc | grep my-service | --output="jsonpath={.status.containerStatuses[*].ready}" | cut -d' ' -f2

Traté de usar el bucle también, pero el script no da el resultado deseado.

¿Puede ayudarme a averiguar el comando exacto?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Si lo entendí correctamente, desea averiguar si un Pod específico conectado a un Endpoint específico está en estado "Ready" .

Con JSON PATH , puede mostrar todos los Pods en un espacio de namespace específico con su estado:

 $ kubectl get pod -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}'

Si está buscando el estado de los Pods conectados a un Endpoint específico, puede usar el siguiente script:

 #!/bin/bash endpointName="web-1" for podName in $(kubectl get endpoints $endpointName -o=jsonpath={.subsets[*].addresses[*].targetRef.name}); do if [ ! -z $podName ]; then kubectl get pod -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}' | grep $podName fi done for podName in $(kubectl get endpoints $endpointName -o=jsonpath={.subsets[*].notReadyAddresses[*].targetRef.name}); do if [ ! -z $podName ]; then kubectl get pod -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.phase}{"\n"}{end}' | grep $podName fi done

Tenga en cuenta que debe cambiar el nombre del Endpoint según sus necesidades; en el ejemplo anterior, uso el nombre web-1 .

Si esta respuesta no responde a su pregunta, especifique su propósito exacto.

over 4 years ago · Santiago Trujillo Report

0

cada servicio crea puntos finales que contienen el podIp y otra información para el servicio. solo puede usar esos endpoints para obtener sus pods. . le mostrará el pod listo para su my-service .

usa este comando:

 kubectl get endpoints -n <Name_space> <service_name> -o json | jq -r 'select(.subsets != null) | select(.subsets[].addresses != null) | .subsets[].addresses[].targetRef.name'

para ti el comando será:

 kubectl get endpoints my-service -o json | jq -r 'select(.subsets != null) | select(.subsets[].addresses != null) | .subsets[].addresses[].targetRef.name'

puede ejecutar el script para obtener el estado del pod

 #!/usr/bin/env bash for podname in $(kubectl get endpoints my-service -o json | jq -r 'select(.subsets != null) | .subsets[].addresses[].targetRef.name') do kubectl get pods -n demo $podname -o json | jq -r ' select(.status.conditions[].type == "Ready") | .status.conditions[].type ' | grep -x Ready done
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!