Enabling prometheus on k8s is pretty simple now. Helm has a complete stable chart of it, simply install it on k8s and it will work.

To collect all slave nodes’ CPU usage: sum (rate (container_cpu_usage_seconds_total{kubernetes_io_hostname !~"k8s-master.*"}[10m])) / sum (machine_cpu_cores) * 100

To collect all slave nodes’ RAM usage: sum (container_memory_working_set_bytes{kubernetes_io_hostname!~"k8s-master.*"}) / sum (machine_memory_bytes{kubernetes_io_hostname!~"k8s-master.*"}) * 100

To collect data from prometheus API: curl -g 'http://10.240.105.51/api/v1/series?match[]=container_cpu_usage_seconds_total{kubernetes_io_hostname!~"k8s-master.*"}' 10.240.105.51 is my prometheus server IP. needs to elimiate space for URL. match[]= is a foramt, value after = is the key to look for. You can use & to find mutiple matches, it’s an ‘either or’ option: curl -g 'http://10.240.105.51/api/v1/series?match[]=up&match[]=container_cpu_usage_seconds_total{kubernetes_io_hostname!~"k8s-master.*"}'