K8S 资源收集和展示 top & DashBoard-UI

一、前言

在近期的 K8S 开发调试的过程中,总会想知道 Node 或者 Pod 的更多信息。但

$ kubectl top node
$ kubectl top pod

中的 top 操作符,需要 metrics 服务的支持。

同理,DashBoard-UI 也需要通过 metrics 获得资源使用状态。

所以,盘他没商量。。。

二、版本介绍

  • OS_VERSION = 'Ubuntu-16.04-amd64'
  • DOCKER_VERSION = '18.06.3ce3-0~ubuntu'
  • K8S_VERSION = '1.14.8-00'

三、安装 metrics Service

1. 下载 metrics 项目

$ git clone https://github.com/kubernetes-sigs/metrics-server.git

2. 进入发布配置目录

$ cd metrics-server/deploy/kubernetes

3. 修改 metrics-server-deployment.yaml

加入以下内容(command 部分),并修改镜像源

$ vim metrics-server-deployment.yaml
...
      containers:
      - name: metrics-server
        image: bluersw/metrics-server-amd64:v0.3.6
        imagePullPolicy: IfNotPresent
        command:
          - /metrics-server
          - --kubelet-preferred-address-types=InternalIP
          - --kubelet-insecure-tls
...

k8s.gcr.io/metrics-server-amd64:v0.3.6 => bluersw/metrics-server-amd64:v0.3.6

4. 最后发布全部资源即可

$ kubectl apply -f .

5. 稍等一会后,就可以使用 top 操作符了

$ kubectl top node

四、安装 DashBoard Service

1. 下载 dashboard 发布文件

$ wget https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0-beta5/aio/deploy/recommended.yaml

2. 修改 dashboard.yaml

添加 kubernetes-dashboard 的 ClusterRole 所需的权限,也可直接使用我已经改好的发布文件 https://raw.githubusercontent.com/PharbersDeveloper/BP-Server-Deploy/master/core-compose/dashboard.yaml

- apiGroups: [""]
    resources:
    - "nodes"
    - "namespaces"
    - "pods"
    - "events"
    - "secrets"
    - "configmaps"
    - "replicationcontrollers"
    - "persistentvolumeclaims"
    - "services"
    verbs: ["get", "list", "watch"]
  - apiGroups: ["extensions"]
    resources:
    - "ingresses"
    verbs: ["get", "list", "watch"]
  - apiGroups: ["apps"]
    resources:
    - "statefulsets"
    - "replicasets"
    - "deployments"
    - "daemonsets"
    verbs: ["get", "list", "watch"]
  - apiGroups: ["batch"]
    resources:
    - "jobs"
    - "cronjobs"
    verbs: ["get", "list", "watch"]

3. 发布 dashboard

$ kubectl apply -f dashboard.yaml

五、使用 DashBoard-UI

  1. 确保已经配置了相关集群的 config-cert,并在此环境中

  2. 启动 ApiServer 代理

$ kubectl proxy
  1. 访问 http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/

  2. 生成 token,复制打印的 token 并以其登陆

$ kubectl -n kubernetes-dashboard describe secret $(kubectl -n kubernetes-dashboard get secret | grep kubernetes-dashboard-token | awk '{print $1}')
  1. 效果如下:
    image

猜你喜欢

转载自www.cnblogs.com/clockq/p/12622195.html
今日推荐