Check uptime for Kubernetes nodes


Use the following command to check the uptime for all of your Kubernetes nodes (assumes you have a SSH key set up to access all the nodes) :

for node in `kubectl get nodes | awk -F " " '{print $1}' | tail -n +2`; do ssh -o StrictHostKeyChecking=no $node uptime; done


20:35:21 up 4 days, 8:57, 0 users, load average: 0.05, 0.07, 0.21
20:35:21 up 4 days, 8:52, 0 users, load average: 0.23, 0.17, 0.27
20:35:21 up 3 days, 8:13, 0 users, load average: 0.19, 0.13, 0.18
20:35:21 up 4 days, 8:46, 0 users, load average: 0.21, 0.26, 0.41
20:35:21 up 4 days, 8:41, 0 users, load average: 0.22, 0.20, 0.30

Or this one, if you want to print the host name as well as uptime:

for node in `kubectl get nodes | awk -F " " '{print $1}' | tail -n +2`; do echo $node; ssh -o StrictHostKeyChecking=no $node uptime; done


kubernetes-node-1.example.com
20:37:21 up 4 days, 8:59, 0 users, load average: 0.33, 0.14, 0.21
kubernetes-node-2.example.com
20:37:21 up 4 days, 8:54, 0 users, load average: 0.22, 0.18, 0.26
kubernetes-node-3.example.com
20:37:21 up 3 days, 8:15, 0 users, load average: 0.21, 0.15, 0.18
kubernetes-node-4.example.com
20:37:21 up 4 days, 8:48, 0 users, load average: 0.31, 0.28, 0.40
kubernetes-node-5.example.com
20:37:22 up 4 days, 8:43, 0 users, load average: 0.46, 0.35, 0.35

And if you want to get fancy:

for node in `kubectl get nodes | awk -F " " '{print $1}' | tail -n +2`; do echo -e "\033[1m$node\033[0m"; ssh -o StrictHostKeyChecking=no $node uptime; done


kubernetes-node-1.example.com
20:37:21 up 4 days, 8:59, 0 users, load average: 0.33, 0.14, 0.21
kubernetes-node-2.example.com
20:37:21 up 4 days, 8:54, 0 users, load average: 0.22, 0.18, 0.26
kubernetes-node-3.example.com
20:37:21 up 3 days, 8:15, 0 users, load average: 0.21, 0.15, 0.18
kubernetes-node-4.example.com
20:37:21 up 4 days, 8:48, 0 users, load average: 0.31, 0.28, 0.40
kubernetes-node-5.example.com
20:37:22 up 4 days, 8:43, 0 users, load average: 0.46, 0.35, 0.35