Prerrequisites
- Kubernetes API Connectivity
The plugin must be able to reach API remotely in order to extract the information. - Permissions
To make requests through the API, the account used to authenticate during execution requires certain permissions.
Permission Assignment
The steps to follow to create a user with sufficient permissions to obtain the monitoring data are described below.
1. Creation of a read “Cluster role” called “api-read-only”: A role will be created that grants “get”, “list” and “watch” permissions to all resources of Kubernetes.
cat <<EOF | kubectl apply -f -
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
name: api-read-only
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- get
- list
- watch
- nonResourceURLs:
- '*'
verbs:
- get
- list
- watch
EOF
2. Creation of a “Cluster role binding” called “bind-api-read-only”: The role will be linked previously created to an already existing “service account”.
kubectl create clusterrolebinding bind-api-read-only \
--clusterrole=api-read-only \
--serviceaccount=namespace:user
- Install metrics server
To install the “metrics-server” addon, it will be necessary to download it in the Kubernetes environment. You can get it from their github project:
https://github.com/kubernetes-incubator/metrics-server
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
You can verify that the deployment has been successful if when you launch the following command the status of your API appears as “true”:
kubectl get apiservices | grep metrics-server
v1beta1.metrics.k8s.io kube-system/metrics-server True 1m
If the deployment is successful, the metrics-server API should be accessible:
kubectl get --raw "/apis/metrics.k8s.io/v1beta1/"
{"kind":"APIResourceList","apiVersion":"v1","groupVersion":"metrics.k8s.io/v1beta1","res
ources":[{"name":"nodes","singularName":"","namespaced":false,"kind":"NodeMetrics
","verbs":["get","list"]},{"name":"pods","singularName":"","namespaced":true,"kind":"P
odMetrics","verbs":["get","list"]}]}
Additionally, after a few seconds, you should be able to obtain CPU and memory usage data for containers and nodes:
$ kubectl top node
NAMECPU(cores) CPU%MEMORY(bytes)MEMORY%
kube93m968Mi56%4%
$ kubectl top pod
NAMECPU(cores)MEMORY(bytes)
pod10m3Mi
pod20m3Mi
pod30m2Mi
pod40m3Mi
pod50m1Mi