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

218
Vistas
kubectl command to find a particular pod status as ready

I wanted to hit a command which searches pod with the service name and identify its pod's status as "Ready"

I tried some of the commands but it does not work and it does not search with service-name.

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

I tried to use the loop also, but the script does not give the desired output.

Can you please help me figure out the exact command?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

If I understood you correctly, you want to find if specific Pod connected to specific Endpoint - is in "Ready" status .

Using JSON PATH you can display all Pods in specific namespace with their status:

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

If you are looking for status for Pods connected to specific Endpoint, you can use below 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

Please note that you need to change Endpoint name to your needs, in above example I use web-1 name.

If this response doesn't answer your question, please specify your exact purpose.

over 4 years ago · Santiago Trujillo Denunciar

0

every service create a endpoints which contain the podIp and other info for service. you can just use that endpoints to get you pods. . it will show you the ready pod for your my-service.

use this command:

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

for you the command will be:

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

you can run the script for getting the pod status

#!/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 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