I would like to know if there is a command in kubernetes that returns true if all resources in a namespace have the ready status and false otherwise.
Something similar to this (ficticious) command:
kubectl get namespace <namespace-name> readiness
If there is not one such command, any help guiding me in the direction of how to retrieve this information (if all resources are ready in a given namespace) is appreciated.
You may have to use kubectl config view --minify | grep namespace: to get current namespace.
Using kubectl describe pods to check kube-system If the output from a specific pod is desired, run the command kubectl describe pod pod_name --namespace kube-system . The Status field should be "Running" - any other status will indicate issues with the environment.
To list the existing namespaces in a cluster 'kubectl get namespace' command is used. After executing the command, the following output will be generated: Observe that the Kubernetes object starts with four initial namespaces: Default, kube-node-lease, kube-public, and kube-system.
We can list all of the pods, services, stateful sets, and other resources in a namespace by using the kubectl get all command. As a result, you may use this command to see the pods, services, and stateful sets in a specific namespace.
There is no such command. try the below command to check all running pods
kubectl get po -n <namespace> | grep 'Running\|Completed'
below command to check the pods that are failed,terminated, error etc.
kubectl get po -n <namespace> | grep -v Running |grep -v Completed
With the following sh scirpt, it is possible to check if all pods in a given namespace are running:
allRunning() {
podStatus=$(kubectl get pods -n <namespace> -o=jsonpath='{range .items[*]}{.status.conditions[?(@.type=="ContainersReady")].status}{"\n"}{end}')
for elem in $podStatus
do
echo $elem
if [ $elem != "Running" ]
then
return 0
fi
done
return 1
}
allRunning
allAreRunning=$
if [ $allAreRunning == 1 ]
then
echo "all are running"
else
echo "not ready"
fi
EDIT 1: As suggested in the comments, pods do not seem to be the correct resource type to check readiness against. Thus, I suggest the following command for querying readiness which is based on deployment availability:
kubectl get deployments -o=jsonpath='{range .items[*]}{.status.conditions[?(@.type=="Available")].status}{"\n"}{end}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With