部署 heapster 插件
到 heapster release 页面 下载最新版本的 heapster
cd /opt/k8s/work
yum install -y unzip
wget https://github.com/kubernetes/heapster/archive/v1.5.4.zip
unzip v1.5.4.zip
mv v1.5.4.zip heapster-1.5.4
官方文件目录: heapster-1.5.4/deploy/kube-config/influxdb
$ cd /opt/k8s/work/heapster-1.5.4/deploy/kube-config/influxdb
$ ls *.yaml
grafana.yaml heapster.yaml influxdb.yaml
配置 heapster
$ cp grafana.yaml grafana.yaml.orig
$ diff grafana.yaml grafana.yaml.orig
67c67
< type: NodePort
---
> # type: NodePort
$ cp heapster.yaml heapster.yaml.orig
$ diff heapster.yaml heapster.yaml.orig
27c27
< - --source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250
---
> - --source=kubernetes:https://kubernetes.default
- granfan: 开启 NodePort 模式;
- 由于 kubelet 只在 10250 监听 https 请求,故修改 —source 参数;
执行所有定义文件
$ cd /opt/k8s/work/heapster-1.5.4/deploy/kube-config/influxdb
$ kubectl create -f .
$ cd ../rbac/
$ cp heapster-rbac.yaml{,.orig}
$ diff heapster-rbac.yaml.orig heapster-rbac.yaml
12a13,26
> ---
> kind: ClusterRoleBinding
> apiVersion: rbac.authorization.k8s.io/v1beta1
> metadata:
> name: heapster-kubelet-api
> roleRef:
> apiGroup: rbac.authorization.k8s.io
> kind: ClusterRole
> name: system:kubelet-api-admin
> subjects:
> - kind: ServiceAccount
> name: heapster
> namespace: kube-system
- heapster-rbac.yaml 文件中增加一个 ClusterRoleBinding,将 serviceAccount kube-system:heapster 与 ClusterRole system:kubelet-api-admin 绑定,授予它调用 kubelet API 的权限;
$ kubectl create -f heapster-rbac.yaml
检查执行结果
检查 Deployment
$ kubectl get deployments -n kube-system | grep -E 'heapster|monitoring'
heapster 1 1 1 1 1m
monitoring-grafana 1 1 1 1 1m
monitoring-influxdb 1 1 1 1 1m
检查 Pods
$ kubectl get pods -n kube-system | grep -E 'heapster|monitoring'
heapster-64589cbdc7-hqnsg 1/1 Running 0 3m
monitoring-grafana-86ddd9bf96-vb4f8 1/1 Running 0 3m
monitoring-influxdb-7c46466487-5f5xj 1/1 Running 0 3m
检查 kubernets dashboard 界面,看是显示各 Nodes、Pods 的 CPU、内存、负载等利用率曲线图;
访问 grafana
通过 kube-apiserver 访问:
获取 monitoring-grafana 服务 URL:
$ kubectl cluster-info
Kubernetes master is running at https://172.27.128.254:8443
Heapster is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/heapster/proxy
CoreDNS is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/kube-dns/proxy
kubernetes-dashboard is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/kubernetes-dashboard/proxy
monitoring-grafana is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy
monitoring-influxdb is running at https://172.27.128.254:8443/api/v1/namespaces/kube-system/services/monitoring-influxdb/proxy
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
通过 kubectl proxy 访问:
创建代理
$ kubectl proxy --address='172.27.128.254' --port=8086 --accept-hosts='^*$' --kubeconfig ~/.kube/config
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
通过 NodePort 访问:
$ kubectl get svc -n kube-system|grep -E 'monitoring|heapster'
heapster ClusterIP 10.254.113.167 <none> 80/TCP 3m
monitoring-grafana NodePort 10.254.114.120 <none> 80:8700/TCP 3m
monitoring-influxdb ClusterIP 10.254.206.90 <none> 8086/TCP 3m
grafana 监听 NodePort 8700;
浏览器访问 URL:
http://172.27.128.254:8700/?orgId=1
参考: