关于metrics-server

原有的kubernetes容器监控服务heapster,从kubernetes 1.11版本开始逐渐退休,如下图所示,红框中显示新的监控服务即metrics-server
metrics1.png
metrics-server的github地址https://github.com/kubernetes-sigs/metrics-server

环境信息

  1. 本次实战环境由三台CensOS7服务器组成,已部署了kubernetes 1.15版本;
  2. 即将部署的metrics-server版本为v0.3.6,与kubernetes版本的匹配关系如下:
    metrics2.png

下载metrics-server

  1. ssh登录kubernetes机器
  2. 从GitHub下载metrics-server的发布包
[root@k8s-master metrics-server]# wget https://github.com/kubernetes-sigs/metrics-server/archive/v0.3.6.tar.gz

3.解压下载的文件

[root@k8s-master metrics-server]# tar -zxvf v0.3.6.tar.gz

4.得到名为metrics-server-0.3.6的文件夹,下载工作完成

修改相应参数

1.接下来还不能立即部署服务,有两个问题要先解决:
metrics-server默认使用的是hostname,但是coredns中并没有三台物理机器的hostname和IP地址的关系,需要改为使用主机IP地址;
2.验证客户端证书的问题,需要改为不验证;

上述问题通过以下步骤解决:
1.进入目录metrics-server-0.3.6/deploy/1.8+/:

[root@k8s-master metrics-server]# cd metrics-server-0.3.6/deploy/1.8+/
[root@k8s-master 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

2.打开文件metrics-server-deployment.yaml,新增一些内容,如下图,红框中为新增的内容:
metrics3.png

部署metrics-server

1.还是在目录metrics-server-0.3.6/deploy/1.8+/,执行命令kubectl apply -f ./
2.控制台提示多种资源被创建

[root@k8s-master 1.8+]# pwd
/home/metrics-server/metrics-server-0.3.6/deploy/1.8+
[root@k8s-master 1.8+]# 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

3.等待metrics-server的pod为running状态,如下图:
metrics4.png
4.至此,metrics-server部署已经完成,接下来验证服务是否正常

验证功能

1.执行命令kubectl top node查看服务器节点情况

[root@k8s-master 1.8+]# kubectl top node
NAME         CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%   
k8s-master   187m         4%     6049Mi          78%       
k8s-node1    684m         17%    6288Mi          53%       
k8s-node2    297m         7%     5063Mi          43%

2.执行命令kubectl top pod -n kube-system查看kube-system这个namespace下所有pod的基本情况

[root@k8s-master 1.8+]# kubectl top po -n kube-system 
NAME                                 CPU(cores)   MEMORY(bytes)   
coredns-bccdc95cf-tdtch              3m           12Mi            
coredns-bccdc95cf-z99kn              4m           14Mi            
etcd-k8s-master                      20m          230Mi           
kube-apiserver-k8s-master            28m          384Mi           
kube-controller-manager-k8s-master   12m          71Mi            
kube-flannel-ds-amd64-76hqv          4m           15Mi            
kube-flannel-ds-amd64-f6ln4          4m           16Mi            
kube-flannel-ds-amd64-fzw5s          3m           13Mi            
kube-proxy-74mcf                     1m           18Mi            
kube-proxy-87dvk                     1m           21Mi            
kube-proxy-z54vt                     1m           14Mi            
kube-scheduler-k8s-master            3m           25Mi            
metrics-server-75d7987c79-rczth      1m           11Mi

3.来试试metrics-server的API服务,执行命令kubectl proxy --port=8088,用来开代理端口

[root@k8s-master 1.8+]# kubectl proxy --port 8088
Starting to serve on 127.0.0.1:8088

4.再开打一个同样的ssh连接,执行命curl localhost:8088/apis/metrics.k8s.io/v1beta1/

[root@k8s-master ~]# curl localhost:8088/apis/metrics.k8s.io/v1beta1/
{
  "kind": "APIResourceList",
  "apiVersion": "v1",
  "groupVersion": "metrics.k8s.io/v1beta1",
  "resources": [
    {
      "name": "nodes",
      "singularName": "",
      "namespaced": false,
      "kind": "NodeMetrics",
      "verbs": [
        "get",
        "list"
      ]
    },
    {
      "name": "pods",
      "singularName": "",
      "namespaced": true,
      "kind": "PodMetrics",
      "verbs": [
        "get",
        "list"
      ]
    }
  ]

5.查看名为etcd-k8s-master的pod的基本信息,命令是:curl localhost:8088/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/etcd-k8s-master

[root@k8s-master ~]# curl localhost:8088/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/etcd-k8s-master
{
  "kind": "PodMetrics",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "name": "etcd-k8s-master",
    "namespace": "kube-system",
    "selfLink": "/apis/metrics.k8s.io/v1beta1/namespaces/kube-system/pods/etcd-k8s-master",
    "creationTimestamp": "2020-05-23T14:37:07Z"
  },
  "timestamp": "2020-05-23T14:36:12Z",
  "window": "30s",
  "containers": [
    {
      "name": "etcd",
      "usage": {
        "cpu": "19054869n",
        "memory": "238744Ki"
      }
    }
  ]
}

至此,kubernetes环境的metrics-server部署和验证都完成了

文章作者: 鲜花的主人
版权声明: 本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 爱吃可爱多
Kubernetes Kubernetes
喜欢就支持一下吧
打赏
微信 微信
支付宝 支付宝