olxbr / metrics-server-exporter

Metrics Server Exporter
MIT License
69 stars 24 forks source link
grafana metrics-server platform prometheus squad-platform

metrics-server-exporter CircleCI Total alerts Language grade: Python

Deprecated project, replaced by using kube-state-metrics.

metrics-server-exporter provides cpu and memory metrics for nodes and pods, directly querying the metrics-server API /apis/metrics.k8s.io/v1beta1/{pods, nodes}

Node metrics

labels

Pod metrics

labels

API metrics

Variables

How to build

$ docker build . -t ${{ secrets.CONTAINER_REGISTRY_HOST }}/metrics-server-exporter

How to run

You will need K8S_TOKEN and K8S_ENDPOINT to access the api-server. Use "--insecure-tls" or mount the CA certificate into the container. Kubernetes will provide the CA certificate in a Kubernetes installation.

$ docker run -p 8000:8000 -e "K8S_ENDPOINT=${K8S_ENDPOINT}" -e "K8S_TOKEN=${K8S_TOKEN}" ${{ secrets.CONTAINER_REGISTRY_HOST }}/metrics-server-exporter --insecure-tls

How to deploy

Set you target k8s context and apply the deployment files

$ kubectl apply -f deploy/

Blacklist

If you want, you could blacklist some names of namespaces, pods or containers, you just need to apply this ConfigMap, replacing the example names

apiVersion: v1
kind: ConfigMap
metadata:
  name: metrics-server-exporter
  labels:
    k8s-app: metrics-server-exporter
data:
  NAMES_BLACKLIST: kube-proxy,calico-node,kube2iam # example names

Minikube

How to test in Minikube

$ minikube delete; minikube start --vm-driver=kvm2 --cpus=2 --memory=4096
* Deleting "minikube" from kvm2 ...
* The "minikube" cluster has been deleted.
* minikube v1.2.0 on linux (amd64)
* Creating kvm2 VM (CPUs=2, Memory=4096MB, Disk=20000MB) ...
* Configuring environment for Kubernetes v1.15.0 on Docker 18.09.6
* Downloading kubelet v1.15.0
* Downloading kubeadm v1.15.0
* Pulling images ...
* Launching Kubernetes ...
* Verifying: apiserver proxy etcd scheduler controller dns
* Done! kubectl is now configured to use "minikube"

Enable metrics-server addon

$ minikube addons enable metrics-server
* metrics-server was successfully enabled

Deploy the files in minikube

$ kubectl apply -R -f deploy/ -n kube-system

Then, test the connectivity

$ kubectl port-forward -n kube-system svc/metrics-server-exporter 9104:9104 &
$ curl http://localhost:9104/metrics

Helm

To install metrics-server-exporter, use

$ helm install --name=metrics-server-exporter --namespace kube-system helm/

You could set the variables using the --set parameters

$ helm install --name=metrics-server-exporter --set custom.k8s_endpoint=https://kubernetes.default.svc helm/

You could assign a specific nodePort. $ helm install --name=metrics-server-exporter --set service.type=NodePort --set service.nodePort=31001 helm/

Grafana Dashboard

You can use the following dashboard to plot metrics from metrics-server-exporter to Grafana.

image

https://grafana.com/grafana/dashboards/12363