Describe the pod info

12/17/2020

How I can describe the pod information if that is not belongs to default namespace. With default namespace I do not have any issue.

But I wanted to have information for that specific pod which does have namespace align to it.

enter image description here

But when I wanted to describe the same pod I could able to make that, see enter image description here

I tried with all namespace flag but it does not allow me to query, like this.

kubectl describe pods airflow-scheduler-646ffbfd67-k7dgh --all-namespaces

-- Indrajeet Gour
kubectl
kubernetes

1 Answer

12/17/2020

You would have to explicitly mention the namespace of the pod which you plan to describe. For that, you need to use the -n flag to kubectl command:

kubectl describe  pods airflow-scheduler-646ffbfd67-k7dgh -n <namespace>

If you are using bash environment to connect to Kubernetes cluster, you can use the below function to describe the POD from any namespace, you may alias it or put it in your bashrc:

describe_pod()
{
if [ $# -ne 1 ];then
    echo "Error: Pod name is missing as input argument"
    return 1
fi

pod_name=${1}

kubectl describe pod "${pod_name}"  -n $(kubectl get pod -A | awk -v pod="$pod_name" -v def=default '$2==pod{ns=$1} END{if(!length(ns))print def; else print ns}')
}

Example usage:

describe_pod <pod-name-from-any-namespace>

Eg:

describe_pod airflow-scheduler-646ffbfd67-k7dgh

With a simple modification of this function, it can be used for other k8s objects.

-- P....
Source: StackOverflow