k8s 1.12.3部署metrics-server,获取k8s中cpu、内存使用率

官网部署方法

git clone https://github.com/kubernetes-incubator/metrics-server
cd metrics-server
kubectl create -f deploy/1.8+/
kubectl -n kube-system get pods -l k8s-app=metrics-server

实际部署步骤

下载部署文件
[root@elasticsearch01 metrics-server]# ls
aggregated-metrics-reader.yaml auth-reader.yaml metrics-server-deployment.yaml resource-reader.yaml
auth-delegator.yaml metrics-apiservice.yaml metrics-server-service.yaml

下载地址

https://github.com/kubernetes-incubator/metrics-server
$ cd metrics-server/deploy/1.8+/
root@blk:/home/metrics-server/deploy/1.8+# ls
aggregated-metrics-reader.yaml  auth-reader.yaml         metrics-server-deployment.yaml  resource-reader.yaml
auth-delegator.yaml             metrics-apiservice.yaml  metrics-server-service.yaml

创建:
root@blk:/home/metrics-server/deploy/# kubectl create -f /k8s/yaml/metrics-server/1.8+

1.kubectl命令 使用对应证书
2.curl api 使用对应证书
3.metrics服务配置问题

在k8s服务需要修改的配置

1.在kube-apiserver.service新增如下参数(https://www.jianshu.com/p/d0a131e001da)
  --etcd-cafile=/etc/kubernetes/ca/ca.pem \
  --etcd-certfile=/etc/kubernetes/ca/kubernetes/kubernetes.pem \
  --etcd-keyfile=/etc/kubernetes/ca/kubernetes/kubernetes-key.pem \
  --requestheader-client-ca-file=/etc/kubernetes/ca/ca.pem \
  --requestheader-allowed-names=aggregator \
  --requestheader-extra-headers-prefix=X-Remote-Extra- \
  --requestheader-group-headers=X-Remote-Group \
  --requestheader-username-headers=X-Remote-User \
  --proxy-client-cert-file=/etc/kubernetes/ca/kube-proxy/kube-proxy.pem \
  --proxy-client-key-file=/etc/kubernetes/ca/kube-proxy/kube-proxy-key.pem \
  --enable-aggregator-routing=true \
2. 在kube-controller-manager.service新增如下参数

--horizontal-pod-autoscaler-use-rest-clients=true

在下载的deploy配置metrics-server-deployment.yaml中需要更新的配置

+        image: registry.cn-beijing.aliyuncs.com/minminmsn/metrics-server:v0.3.1
+        imagePullPolicy: IfNotPresent
+        command:
+        - /metrics-server
+        - --metric-resolution=30s
+        - --kubelet-insecure-tls
+        - --kubelet-preferred-address-types=InternalIP,Hostname,InternalDNS,ExternalDNS,ExternalIP

metrics-server-service.yaml
+  type: NodePort
   selector:
     k8s-app: metrics-server
   ports:
   - port: 443
     protocol: TCP
     targetPort: 443
+    nodePort: 30443


deploy/1.8+/resource-reader.yaml
   - pods
   - nodes
   - nodes/stats
+  - namespaces

-  name: system:metrics-server
+  name: cluster-admin

访问方式:
SECRET=$(kubectl get secrets -n kube-system| grep kubelet-api-test | awk '{print $1}')
TOKEN=$(kubectl describe secret -n kube-system ${SECRET} | grep -E '^token' | awk '{print $2}')
echo ${TOKEN}

curl -ik \
  -H "Authorization: Bearer $(cat ./token)" \
  https://172.16.5.205:30443/apis/metrics.k8s.io/v1beta1/nodes
  

可以理解为:
cpu: 最多使用1个核,最低要求 250/1000 = 1/4 核 (1 = 1000m);可以使用top简单查看你的机器的cpu总共有多少个核;
memory: 最多使用128M,最低要求64 M;

CPU和RAM单元
CPU资源以cpus为单位。允许小数值。你可以用后缀m来表示mili。例如100m cpu等同于100 milicpu,意思是0.1cpu。
RAM资源以bytes为单位。你可以将RAM表示为纯整数或具有这些后缀之一的定点整数:
E, P, T, G, M, K, Ei, Pi, Ti, Gi, Mi, Ki。例如,以下代表大约相同的数值:
128974848, 129e6, 129M , 123Mi

metrics-server部署好后可以,安装prometheus https://blog.csdn.net/weixin_36171533/article/details/82790968

你可能感兴趣的:(k8s 1.12.3部署metrics-server,获取k8s中cpu、内存使用率)