This topic describes how to install the metrics-server component without upgrading the cluster.

Prerequisites

  • You have created a Kubernetes cluster. For more information, see Create Kubernetes clusters.
  • The Kubernetes cluster version is 1.12.6 or earlier.

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. Run the kubectl apply -f metrics-server.yaml command 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: extensions/v1beta1
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=
&public=true'
Note Replace ##REGION## and ##CLUSTER_ID## with the region (for example, cn-hangzhou) and ID of the selected cluster respectively.

Switch the monitoring link

  1. In the left-side navigation pane, choose Clusters > Nodes to go to the Nodes page.
  2. Select the target cluster.
  3. Find the three master nodes in the cluster. Click the ID of a master node to go to the Instance Details page. This topic uses master-01 as an example.
    Switch link step 1
  4. Click Connect. The Enter VNC Password dialog box appears. Enter the VNC password and click OK. After you are logged on to the instance, run the following command:
    sed -i 's/--horizontal-pod-autoscaler-use-rest-clients=false/--horizontal-pod-autoscaler-use-rest-clients=true/' /etc/kubernetes/manifests/kube-controller-manager.yaml                            
    Switch link step 2
  5. Repeat the steps on nodes master-02 and master-03.

After the command is executed, the kubelet updates the controller manager.

Update component settings

  1. In the left-side navigation pane, choose Ingresses and Load Balancing > Services to go to the Services page.
  2. Select the target cluster and the kube-system namespace. Select the heapster service and click View in YAML in the Actions column.
    Update step 1
  3. In the dialog box that appears, set the value of the k8s-app field to metrics-server. Click Update.
    Update step 2
  4. In the left-side navigation pane, choose Applications > Deployments to go to the Deployments page.
  5. Select the target cluster and the kube-system namespace.
    Update step 3
  6. Select Heapster-related components such as heapster and monitoring-influxdb. In the Actions column, choose More > Delete. In the dialog box that appears, click OK.
    Update step 4
    Note When you delete the monitoring-influxdb component, select the Delete the associated monitoring-influxdb service check box and click OK in the Delete monitoring-influxdb dialog box.
  7. Check the link status.
    It takes about three minutes to initialize the link.
    In the left-side navigation pane, choose Applications > Pods. On the Pods page, if the CPU and memory usage are normal, it indicates that the link is switched.
    Note If the CPU and memory usage of all components are zero, it indicates that an error has occurred.
    Update step 5