Deploy Metrics server for Kubernetes
Metrics Server
collects resource metrics from Kubelet
and exposes them to API server through Metric API. It’s a great tools to monitor system resources usage.
To deploy, use the following config with modification as below
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "2"
creationTimestamp: "2020-07-07T13:15:40Z"
generation: 2
labels:
k8s-app: metrics-server
name: metrics-server
namespace: kube-system
resourceVersion: "273400"
selfLink: /apis/extensions/v1beta1/namespaces/kube-system/deployments/metrics-server
uid: f4682170-c053-11ea-838e-000c29c98773
spec:
progressDeadlineSeconds: 600
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
k8s-app: metrics-server
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
k8s-app: metrics-server
name: metrics-server
spec:
containers:
- args:
- --cert-dir=/tmp
- --secure-port=4443
***- --kubelet-insecure-tls***
***- --kubelet-preferred-address-types=InternalIP,ExternalIP,Hostname***
image: k8s.gcr.io/metrics-server-amd64:v0.3.6
imagePullPolicy: IfNotPresent
name: metrics-server
ports:
- containerPort: 4443
hostPort: 4443
name: main-port
protocol: TCP
resources: {}
securityContext:
procMount: Default
readOnlyRootFilesystem: true
runAsNonRoot: true
runAsUser: 1000
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /tmp
name: tmp-dir
dnsPolicy: ClusterFirst
hostNetwork: true
nodeSelector:
kubernetes.io/arch: amd64
kubernetes.io/os: linux
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
serviceAccount: metrics-server
serviceAccountName: metrics-server
terminationGracePeriodSeconds: 30
volumes:
- emptyDir: {}
name: tmp-dir
status:
availableReplicas: 1
conditions:
- lastTransitionTime: "2020-07-07T13:15:48Z"
lastUpdateTime: "2020-07-07T13:15:48Z"
message: Deployment has minimum availability.
reason: MinimumReplicasAvailable
status: "True"
type: Available
- lastTransitionTime: "2020-07-07T13:15:40Z"
lastUpdateTime: "2020-07-09T12:50:00Z"
message: ReplicaSet "metrics-server-548456dbd5" has successfully progressed.
reason: NewReplicaSetAvailable
status: "True"
type: Progressing
observedGeneration: 2
readyReplicas: 1
replicas: 1
updatedReplicas: 1
Wait a while for metrics-server
to collect metrics. Then, we can query the metrics via kubectl
$ kubectl top node
NAME CPU(cores) CPU% MEMORY(bytes) MEMORY%
master 226m 11% 4957Mi 64%
worker1 83m 4% 2439Mi 66%
worker2 94m 4% 4182Mi 75%