This topic describes how to install the metrics-server component. In this case, you do not need to upgrade your Kubernetes cluster.
Prerequisites
- A Kubernetes cluster is created. For more information, see Create a dedicated Kubernetes cluster.
- Kubernetes version 1.12.6 or earlier is used for the cluster.
To install the metrics-server component, perform the following steps: change the metric collector, switch the monitoring link, and update component settings.
Change the metric collector
Create a metrics-server.yaml file and copy the following content to the file. In the command-line interface (CLI),
enter
kubectl apply -f metrics-server.yaml
to change the metric collector from Heapster to metrics-server.apiVersion: v1
kind: ServiceAccount
metadata:
name: admin
namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin
namespace: kube-system
---
apiVersion: v1
kind: Service
metadata:
labels:
task: monitoring
# For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons)
# If you are NOT using this as an addon, you should comment out this line.
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: metrics-server
name: heapster
namespace: kube-system
spec:
ports:
- port: 80
targetPort: 8082
selector:
k8s-app: metrics-server
---
apiVersion: v1
kind: Service
metadata:
name: metrics-server
namespace: kube-system
labels:
kubernetes.io/name: metrics-server
spec:
selector:
k8s-app: metrics-server
ports:
- port: 443
protocol: TCP
targetPort: 443
---
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
name: v1beta1.metrics.k8s.io
spec:
service:
name: metrics-server
namespace: kube-system
group: metrics.k8s.io
version: v1beta1
insecureSkipTLSVerify: true
groupPriorityMinimum: 100
versionPriority: 100
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: metrics-server
namespace: kube-system
labels:
k8s-app: metrics-server
spec:
selector:
matchLabels:
k8s-app: metrics-server
template:
metadata:
name: metrics-server
labels:
k8s-app: metrics-server
spec:
serviceAccountName: admin
containers:
- name: metrics-server
image: registry. ##REGION##.aliyuncs.com/acs/metrics-server:v0.2.1-9dd9511-aliyun
imagePullPolicy: Always
command:
- /metrics-server
- '--source=kubernetes:https://kubernetes.default'
- '--sink=socket:tcp://monitor.csk. ##REGION##.aliyuncs.com:8093? clusterId=##CLUSTER_ID##
&public=true'
Note Replace
##REGION##
and ##CLUSTER_ID##
respectively with the region (such as cn-hangzhou) and ID of the selected cluster.
Switch the monitoring link
After the command is executed, the kubelet updates the controller manager.