Updating the Metrics Server parameters
Metrics Serverkubelet
and provides them through the Metrics APIkubectl top node
or kubectl top pod
command. For more information, see the Metrics Server documentation
A pod on the Metrics Server has two containers, metrics-server
and metrics-server-nanny
, the latter running addon-resizermetrics-server
. The metrics-server-nanny
container is responsible for the automatic allocation of resources to the metrics-server
container depending on the number of Managed Service for Kubernetes cluster nodes.
In some cases, the metrics-server-nanny
component may run incorrectly. For instance, if many pods are created while there are few nodes in the Managed Service for Kubernetes cluster. If so, the Metrics Server pod will exceed its limits, which may degrade the server performance.
To avoid this, change the parameters of the Metrics Server manually:
- View the amount of resources allocated to the Metrics Server pod.
- Update the Metrics Server parameters.
- Check the results.
To restore the default values of the Metrics Server parameters, reset them.
View the amount of resources allocated to the Metrics Server pod
Run the following command:
kubectl get pod <metrics server pod name> \
--namespace=kube-system \
--output=json | \
jq '.spec.containers[] | select(.name == "metrics-server") | .resources'
The resources are calculated using the following formula:
cpu = baseCPU + cpuPerNode * nodesCount
memory = baseMemory + memoryPerNode * nodesCount
Where:
baseCPU
is the base number of CPUs.cpuPerNode
is the number of CPUs per node.nodesCount
is the number of nodes.baseMemory
is the base amount of RAM.memoryPerNode
is the amount of RAM per node.
Update the Metrics Server parameters
-
Open the Metrics Server configuration file:
kubectl edit configmap metrics-server-config \ --namespace=kube-system \ --output=yaml
-
Add or update the resource parameters under
data.NannyConfiguration
:apiVersion: v1 data: NannyConfiguration: |- apiVersion: nannyconfig/v1alpha1 kind: NannyConfiguration baseCPU: <base number of CPUs>m cpuPerNode: <CPUs per node>m baseMemory: <base amount of RAM>Mi memoryPerNode: <RAM per node>Mi ...
Sample configuration fileapiVersion: v1 data: NannyConfiguration: |- apiVersion: nannyconfig/v1alpha1 kind: NannyConfiguration baseCPU: 48m cpuPerNode: 1m baseMemory: 104Mi memoryPerNode: 3Mi kind: ConfigMap metadata: creationTimestamp: "2022-12-15T06:28:22Z" labels: addonmanager.kubernetes.io/mode: EnsureExists name: metrics-server-config namespace: kube-system resourceVersion: "303569" uid: 931b88ca-21da-4d04-a3c1-da7e8c95cc47
-
Restart the Metrics Server. To do this, delete it and wait until the Kubernetes controller creates it again:
kubectl delete deployment metrics-server \ --namespace=kube-system
Check the results
View the amount of resources allocated to the Metrics Server pod once again and make sure it has been updated for the new pod.
Reset the Metrics Server parameters
To reset the parameters to their default values, delete the Metrics Server configuration file and its Deployment:
kubectl delete configmap metrics-server-config \
--namespace=kube-system && \
kubectl delete deployment metrics-server \
--namespace=kube-system
As a result, a new pod of the Metrics Server is created automatically.