This is a tested example.
Not all clusters will have the metrics API, but this will function for ones that do.
The deployment uses the bitnami/kubectl image
.
It runs "get node metrics" in a shell while loop that sleeps.
The Deployment's Pod-template uses a ServiceAccount that is ClusterRoleBound to a ClusterRole permitting the list
and get
verbs for the Node
kind in the metrics.k8s.io
API group.
Here's how to reproduce:
kubectl apply -f https://gist.githubusercontent.com/stealthybox/4b501b94c51a0421e8e84b6b440ca587/raw/52be01a73de42bafa93284e4501d8bbda67ead91/metrics-rbac-deploy.yaml
kubectl -n example get deploy,po
kubectl -n example logs -f deploy/metrics-fetcher
cleanup:
kubectl delete -f https://gist.githubusercontent.com/stealthybox/4b501b94c51a0421e8e84b6b440ca587/raw/52be01a73de42bafa93284e4501d8bbda67ead91/metrics-rbac-deploy.yaml
Note:
kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes
and
kubectl get nodes.metrics.k8s.io -o json
return the same objects.
However, they output different List types.