简体   繁体   中英

Kubectl using command to get cluster status

I need to create a shell-script which examine the cluster Status.**

I saw that the kubectl describe-nodes provides lots of data I can output it to json and then parse it but maybe it's just overkill. Is there a simple way to with kubectl command to get the status of the cluster ? just if its up / down

The least expensive way to check if you can reach the API server is kubectl version . In addition kubectl cluster-info gives you some more info.

In addition to Michael's answer , that would only tell you about the API server or master and internal services like KubeDns etc, but not the nodes.

It depends on your need and definition of "status" here. You could run kubectl cluster-info followed by kubectl get nodes and check the STATUS column for all nodes using parsing tools like awk , jq or kubectl's own -o jsonpath option to verify that all nodes are ready.

The below command would display the health of scheduler, controller and etcd

kubectl get cs

Command below lists Kubernetes core components like, etcd , controller, scheduler, kube-proxy, core-dns, network plugin. All those pods should be running to be sure that Kubernetes is healthy.

kubectl get pod -n kube-system

Finally deploy one front-end and back-end Pod and verify the inter-pod communication to ensure that cluster is up and working correctly.

Below are the commands to get cluster status based on requirements:

  • To get information regarding where your Kubernetes master is running at, CoreDNS is running at, kubernetes-dasboard is running at, use kubectl cluster-info

  • To get detailed information to further debug and diagnose cluster problem, use kubectl cluster-info dump

  • To get only the health status for your node use, kubectl get componentstatus or kubectl get cs

*To show detailed information about a resource use kubectl describe node <node>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM