1、下载heapster的代码
1 2 |
#直接现在Github上的最新代码。 git clone https://github.com/kubernetes/heapster.git |
1.1、在heapster/deploy/kube-config/influxdb目录下有几个yaml文件:

看下用了哪些镜像:
1 |
find . -name "*.php" | xargs grep "images:" |
1 2 3 |
./grafana.yaml: image: k8s.gcr.io/heapster-grafana-amd64:v5.0.4 ./influxdb.yaml: image: k8s.gcr.io/heapster-amd64:v1.5.4 ./heapster.yaml: image: k8s.gcr.io/heapster-influxdb-amd64:v1.5.2 |
从外面下载镜像,存储到国内私有镜像仓库里(有梯子的随意)
1 2 |
image: registry.cn-shanghai.aliyuncs.com/shooer/heapster-influxdb-amd64:v1.5.4 image: registry.cn-shanghai.aliyuncs.com/shooer/heapster-amd64:v1.5.4 |
2、部署influxdb
1 |
#说明:所有的容器组都运行在kube-system 命名空间 |
2.1、influxdb 部署
给influxdb deployment 添加 pvc ,源项目没相关yaml
1 2 3 4 5 6 7 8 |
1.修改容器镜像源 influxdb 2.添加节点lable kubectl label nodes k8s-node-01 dashboard=kubernetes-dashboard 3.添加指定节点运行 nodeSelector: dashboard: kubernetes-dashboard #指定节点运行 |
1 |
vim influxdb.yaml |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
--- apiVersion: v1 kind: PersistentVolumeClaim metadata: name: nfs-influxdb namespace: kube-system spec: accessModes: - ReadWriteMany storageClassName: nfs-csi resources: requests: storage: 5Gi --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: monitoring-influxdb namespace: kube-system spec: replicas: 1 selector: matchLabels: task: monitoring k8s-app: influxdb template: metadata: labels: task: monitoring k8s-app: influxdb spec: nodeSelector: dashboard: kubernetes-dashboard #添加指定节点运行kubectl label nodes k8s-node-01 dashboard=kubernetes-dashboard containers: - name: influxdb image: registry.cn-shanghai.aliyuncs.com/shooer/heapster-influxdb-amd64:v1.5.4 volumeMounts: - mountPath: /data name: influxdb-storage volumes: - name: influxdb-storage persistentVolumeClaim: claimName: nfs-influxdb --- apiVersion: v1 kind: Service metadata: labels: task: monitoring # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) # If you are NOT using this as an addon, you should comment out this line. kubernetes.io/cluster-service: 'true' kubernetes.io/name: monitoring-influxdb name: monitoring-influxdb namespace: kube-system spec: ports: - port: 8086 targetPort: 8086 selector: k8s-app: influxdb |
2.2、执行生成yaml 文件
1 |
kubectl apply -f influxdb.yaml |
1 2 3 4 5 6 |
[root@k8s-master-01 influxdb]# kubectl get pod -n kube-system -o wide | grep influxdb monitoring-influxdb-6d968c5c7d-vq852 1/1 Running 0 2d8h 10.244.1.81 k8s-node-01 <none> <none> [root@k8s-master-01 influxdb]# curl http://10.244.1.81:8086/ 404 page not found #返回404 证明访问正常 |
1 2 3 4 5 |
[root@k8s-master-01 influxdb]# kubectl get service -n kube-system | grep influxdb monitoring-influxdb ClusterIP 10.102.185.200 <none> 8086/TCP 2d8h [root@k8s-master-01 influxdb]# curl http://10.102.185.200:8086/ 404 page not found #返回404 证明访问正常 |
3、heapster 部署
3.1、 创建clusterrole
1 |
vim heapster-clusterrole.yaml |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "true" labels: kubernetes.io/bootstrapping: rbac-defaults name: system:heapster rules: - apiGroups: - "" resources: - events - namespaces - nodes - pods - nodes/stats verbs: - create - get - list - watch - apiGroups: - extensions resources: - deployments verbs: - get - list - watch |
3.2 创建ClusterRoleBinding
1 2 3 4 5 6 7 8 9 10 11 12 |
kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: heapster roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:heapster subjects: - kind: ServiceAccount name: heapster namespace: kube-system |
3.3、heapster Deployment 合集
1 2 3 4 5 6 7 8 |
1. 修改 - --source=kubernetes:https://kubernetes.default 为 - --source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250&insecure=true 2.修改容器源 registry.cn-shanghai.aliyuncs.com/shooer/heapster-amd64:v1.5.4 3.添加指定节点运行 nodeSelector: dashboard: kubernetes-dashboard #指定节点运行 |
1 |
vim heapster.yaml |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
--- apiVersion: v1 kind: ServiceAccount metadata: name: heapster namespace: kube-system --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "true" labels: kubernetes.io/bootstrapping: rbac-defaults name: system:heapster rules: - apiGroups: - "" resources: - events - namespaces - nodes - pods - nodes/stats verbs: - create - get - list - watch - apiGroups: - extensions resources: - deployments verbs: - get - list - watch --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1beta1 metadata: name: heapster roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: system:heapster subjects: - kind: ServiceAccount name: heapster namespace: kube-system --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: heapster namespace: kube-system spec: replicas: 1 template: metadata: labels: task: monitoring k8s-app: heapster spec: nodeSelector: dashboard: kubernetes-dashboard #添加指定节点运行kubectl label node k8s-node-01 dashboard=kubernetes-dashboard serviceAccountName: heapster containers: - name: heapster image: registry.cn-shanghai.aliyuncs.com/shooer/heapster-amd64:v1.5.4 imagePullPolicy: IfNotPresent command: - /heapster - --source=kubernetes:https://kubernetes.default?kubeletHttps=true&kubeletPort=10250&insecure=true - --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086 --- apiVersion: v1 kind: Service metadata: labels: task: monitoring # For use as a Cluster add-on (https://github.com/kubernetes/kubernetes/tree/master/cluster/addons) # If you are NOT using this as an addon, you should comment out this line. kubernetes.io/cluster-service: 'true' kubernetes.io/name: Heapster name: heapster namespace: kube-system spec: ports: - port: 80 targetPort: 8082 selector: k8s-app: heapster |
3.4、执行配置好的yaml 文件
1 |
kubectl apply -f heapster.yaml |
3.5、验证heapster 状态
1 2 3 4 5 6 7 8 |
[root@k8s-master-01 influxdb]# kubectl get pod -n kube-system | grep heapster heapster-747d84c47f-mgct6 1/1 Running 0 2d8h [root@k8s-master-01 influxdb]# kubectl get service -n kube-system | grep heapster heapster ClusterIP 10.103.129.154 <none> 80/TCP 2d8h [root@k8s-master-01 influxdb]# curl http://10.103.129.154/ 404 page not found 返回404 正常 等待一段时间打开:kubernetes-dashboard 查看容器cpu内存使用由图表(前提已安装metrics-server) |

出现图表证明heapster 安装 成功
- 本文固定链接: https://www.yoyoask.com/?p=7281
- 转载请注明: shooter 于 SHOOTER 发表