部署 heapster 插件

heapster release 页面 下载最新版本的 heapster

  1. cd /opt/k8s/work
  2. yum install -y unzip
  3. wget https://github.com/kubernetes/heapster/archive/v1.5.4.zip
  4. unzip v1.5.4.zip
  5. mv v1.5.4.zip heapster-1.5.4

官方文件目录: heapster-1.5.4/deploy/kube-config/influxdb

  1. $ cd /opt/k8s/work/heapster-1.5.4/deploy/kube-config/influxdb
  2. $ ls *.yaml
  3. grafana.yaml heapster.yaml influxdb.yaml

配置 heapster

  1. $ cp grafana.yaml grafana.yaml.orig
  2. $ diff grafana.yaml grafana.yaml.orig
  3. 67c67
  4. < type: NodePort
  5. ---
  6. > # type: NodePort
  7. $ cp heapster.yaml heapster.yaml.orig
  8. $ diff heapster.yaml heapster.yaml.orig
  9. 27c27
  10. < - --source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250
  11. ---
  12. > - --source=kubernetes:https://kubernetes.default
  • granfan: 开启 NodePort 模式;
  • 由于 kubelet 只在 10250 监听 https 请求,故修改 —source 参数;

执行所有定义文件

  1. $ cd /opt/k8s/work/heapster-1.5.4/deploy/kube-config/influxdb
  2. $ kubectl create -f .
  3. $ cd ../rbac/
  4. $ cp heapster-rbac.yaml{,.orig}
  5. $ diff heapster-rbac.yaml.orig heapster-rbac.yaml
  6. 12a13,26
  7. > ---
  8. > kind: ClusterRoleBinding
  9. > apiVersion: rbac.authorization.k8s.io/v1beta1
  10. > metadata:
  11. > name: heapster-kubelet-api
  12. > roleRef:
  13. > apiGroup: rbac.authorization.k8s.io
  14. > kind: ClusterRole
  15. > name: system:kubelet-api-admin
  16. > subjects:
  17. > - kind: ServiceAccount
  18. > name: heapster
  19. > namespace: kube-system
  • heapster-rbac.yaml 文件中增加一个 ClusterRoleBinding,将 serviceAccount kube-system:heapster 与 ClusterRole system:kubelet-api-admin 绑定,授予它调用 kubelet API 的权限;
  1. $ kubectl create -f heapster-rbac.yaml

检查执行结果

检查 Deployment

  1. $ kubectl get deployments -n kube-system | grep -E 'heapster|monitoring'
  2. heapster 1 1 1 1 1m
  3. monitoring-grafana 1 1 1 1 1m
  4. monitoring-influxdb 1 1 1 1 1m

检查 Pods

  1. $ kubectl get pods -n kube-system | grep -E 'heapster|monitoring'
  2. heapster-64589cbdc7-hqnsg 1/1 Running 0 3m
  3. monitoring-grafana-86ddd9bf96-vb4f8 1/1 Running 0 3m
  4. monitoring-influxdb-7c46466487-5f5xj 1/1 Running 0 3m

检查 kubernets dashboard 界面,看是显示各 Nodes、Pods 的 CPU、内存、负载等利用率曲线图;

dashboard-heapster

访问 grafana

  1. 通过 kube-apiserver 访问:

    获取 monitoring-grafana 服务 URL:

    1. $ kubectl cluster-info
    2. Kubernetes master is running at https://172.27.128.254:8443
    3. Heapster is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/heapster/proxy
    4. CoreDNS is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/kube-dns/proxy
    5. kubernetes-dashboard is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy
    6. monitoring-grafana is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
    7. monitoring-influxdb is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy
    8. To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

    浏览器访问 URL: https://172.27.128.254:6443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy

  2. 通过 kubectl proxy 访问:

    创建代理

    1. $ kubectl proxy --address='172.27.128.254' --port=8086 --accept-hosts='^*$' --kubeconfig ~/.kube/config
    2. Starting to serve on 172.27.129.80:8086

    浏览器访问 URL:http://172.27.128.254:8086/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy/?orgId=1

  3. 通过 NodePort 访问:

    1. $ kubectl get svc -n kube-system|grep -E 'monitoring|heapster'
    2. heapster ClusterIP 10.254.113.167 <none> 80/TCP 3m
    3. monitoring-grafana NodePort 10.254.114.120 <none> 80:8700/TCP 3m
    4. monitoring-influxdb ClusterIP 10.254.206.90 <none> 8086/TCP 3m
    • grafana 监听 NodePort 8700;

      浏览器访问 URL:http://172.27.128.254:8700/?orgId=1

grafana

参考:

  1. 配置 heapster:https://github.com/kubernetes/heapster/blob/master/docs/source-configuration.md