k8s1.18.3部署Metrics-Server监控服务

参考
https://www.jianshu.com/p/82b91109a443
http://blog.ljmict.com/?p=98

下载并解压Metrics-Server

wget https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz
tar xf v0.3.6.tar.gz

修改配置文件

cd metrics-server-0.3.6/deploy/1.8+
sed -i 's#k8s.gcr.io/metrics-server-amd64:v0.3.6#mirrorgooglecontainers/metrics-server-amd64:v0.3.6#g' metrics-server-deployment.yaml
sed -i 's/Always/IfNotPresent/g' metrics-server-deployment.yaml 

安装Metrics-Server

kubectl apply -f .

clusterrole.rbac.authorization.k8s.io/system:aggregated-metrics-reader created
clusterrolebinding.rbac.authorization.k8s.io/metrics-server:system:auth-delegator created
rolebinding.rbac.authorization.k8s.io/metrics-server-auth-reader created
apiservice.apiregistration.k8s.io/v1beta1.metrics.k8s.io created
serviceaccount/metrics-server created
deployment.apps/metrics-server created
service/metrics-server created
clusterrole.rbac.authorization.k8s.io/system:metrics-server created
clusterrolebinding.rbac.authorization.k8s.io/system:metrics-server created

查看创建的相关Metrics-Server组件

kubectl get deployments.apps,svc,pods -n kube-system  | grep metrics
deployment.apps/metrics-server            1/1     1            1           81s
service/metrics-server   ClusterIP   10.103.252.240   <none>        443/TCP                  81s
pod/metrics-server-57bc7f4584-zkbqz            1/1     Running   0          81s

查看pod和node的资源使用情况

kubectl top nodes
NAME        CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
master-11   169m         4%     1651Mi          28%       
node1-12    102m         2%     552Mi           14%       
node2-13    93m          2%     533Mi           14%  
kubectl top pods -n kube-system 
NAME                                       CPU(cores)   MEMORY(bytes)   
calico-kube-controllers-578894d4cd-k4ccx   2m           26Mi            
calico-node-4svc2                          15m          81Mi            
calico-node-r8xlx                          21m          29Mi            
calico-node-vvksl                          23m          44Mi            
coredns-7ff77c879f-sz87s                   2m           14Mi            
coredns-7ff77c879f-v8vg8                   2m           16Mi            
etcd-master-11                             15m          146Mi           
kube-apiserver-master-11                   26m          490Mi           
kube-controller-manager-master-11          10m          41Mi            
kube-proxy-4q2fg                           1m           26Mi            
kube-proxy-fpn7d                           1m           8Mi             
kube-proxy-mvwf7                           1m           12Mi            
kube-scheduler-master-11                   3m           15Mi            
metrics-server-57bc7f4584-zkbqz            2m           10Mi    

部署METRICS-SERVER时遇到的问题

kubectl top node
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get nodes.metrics.k8s.io)

查看metrics-server日志

kubectl logs -n kube-system deploy/metrics-server
unable to fully collect metrics: [unable to fully scrape metrics from source kubelet_summary:k8s-node01.ljmict.com: unable to fetch metrics from Kubelet k8s-node01.ljmict.com (k8s-node01.ljmict.com): Get https://k8s-node01.ljmict.com:10250/stats/summary?only_cpu_and_memory=true: dial tcp: lookup k8s-node01.ljmict.com on 10.96.0.10:53: no such host, unable to fully scrape metrics from source kubelet_summary:k8s-node02.ljmict.com: unable to fetch metrics from Kubelet k8s-node02.ljmict.com (k8s-node02.ljmict.com): Get https://k8s-node02.ljmict.com:10250/stats/summary?only_cpu_and_memory=true: dial tcp: lookup k8s-node02.ljmict.com on 10.96.0.10:53: no such host]

修改metrics-server-deployment.yaml文件,在metrics-server容器配置位置添加如下配置

        command:
        - /metrics-server
        - --kubelet-preferred-address-types=InternalIP
        - --kubelet-insecure-tls

继续查看kube-apiserver日志

v1beta1.metrics.k8s.io failed with: failing or missing response from https://10.96.142.17:443/apis/metrics.k8s.io/v1beta1: Get https://10.96.142.17:443/apis/metrics.k8s.io/v1beta1: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

在kube-apiserver选项中添加如下配置选项

vi /etc/kubernetes/manifests/kube-apiserver.yaml
...
--enable-aggregator-routing=true

你可能感兴趣的:(kubernetes,jenkins,运维,git)