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.
But when I wanted to describe the same pod I could able to make that, see
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
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.