Shell Example

A bash shell example to query cpu/ram usage on k8s through kubernetes native tool kubectl: #!/bin/bash lines=$(kubectl top nodes | grep k8s-slave -c) cpu=$(kubectl top nodes | grep k8s-slave | awk '{ SUM += $3} END { print SUM}') ram=$(kubectl top nodes | grep k8s-slave | awk '{ SUM += $5} END { print SUM}') cpu_usage=$[cpu/lines] ram_usage=$[ram/lines] if [ $cpu_usage -le 15 ]; then echo "too much wasted cpu resource!" fi if [ $ram_usage -ge 50 ]; then echo "ram's too low!

Continue reading

Author's picture

LuLU

Love coding and new technologies

Cloud Solution Consultant

Canada