二十 HeapSter 监控(废弃中)
kubectl top 是 k8s 内置查看 POD 监控信息的命令,它是从 HeapSter 中取得数据,而 HeapSter 是运行在 K8S 集群级别的监控软件。
kubectl 有一个内置插件,叫 cAdvisor 它用来收集 node 节点和节点上的 POD 上的资源使用量,HeapSter 可以收集 cAdvisor 在每个节点上采集的数据,这些数据想要持续存储,那么就必须将数据放在 influx DB 的数据库中,然后可以使用 Grafana 配置 influx DB 为数据源,然后展示。
https://github.com/kubernetes-retired/heapster
复制代码
20.1 安装 influx DB
influx DB 是一个时序数据库,它需要一个持久存储来保存数据,所以要注意的是在它的清单文件中应该将官方默认的 emptyDir 修改为具有持久存储能力的存储卷。
apiVersion: apps/v1 # 此处修改为 apps/v1,由于修改了此处所以还需要修改标签选择器
kind: Deployment
metadata:
name: monitoring-influxdb
namespace: kube-system
spec:
replicas: 1
selector: # 添加标签
matchLables: # 添加标签
task: monitoring # 添加标签
k8s-app: influxdb # 添加标签
template:
metadata:
labels:
task: monitoring
k8s-app: influxdb
spec:
containers:
- name: influxdb
image: k8s.gcr.io/heapster-influxdb-amd64:v1.5.2
volumeMounts:
- mountPath: /data
name: influxdb-storage
volumes:
- name: influxdb-storage
emptyDir: {} # 此处应该修改为具有持久存储能力的
---
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
复制代码
$ kubectl get svc -n kube-system
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kube-dns ClusterIP 10.96.0.10 <none> 53/UDP,53/TCP,9153/TCP 9d
kubernetes-dashboard NodePort 10.109.5.194 <none> 443:30894/TCP 3d14h
monitoring-influxdb ClusterIP 10.104.173.236 <none> 8086/TCP 18s
$ kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
.....
monitoring-influxdb-866db5f944-d7rkd 1/1 Running 0 69s
复制代码
20.2 安装 HeapSter
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: v1
kind: ServiceAccount
metadata:
name: heapster
namespace: kube-system
---
apiVersion: apps/v1 # 修改此处的为 apps/v1,修改此处以后还需要添加 selector
kind: Deployment
metadata:
name: heapster
namespace: kube-system
spec:
replicas: 1
selector: # 因为修改 api 版本所以需要添加
matchLabels: # 添加
task: monitoring # 添加
k8s-app: heapster # 添加
template:
metadata:
labels:
task: monitoring
k8s-app: heapster
spec:
serviceAccountName: heapster
containers:
- name: heapster
image: k8s.gcr.io/heapster-amd64:v1.5.4
imagePullPolicy: IfNotPresent
command:
- /heapster
- --source=kubernetes:https://kubernetes.default
- --sink=influxdb:http://monitoring-influxdb.kube-system.svc:8086
---
apiVersion: v1
kind: Service
metadata:
labels:
task: monitoring
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: Heapster
name: heapster
namespace: kube-system
spec:
ports:
- port: 80
targetPort: 8082
selector:
k8s-app: heapster
复制代码
NAME READY STATUS RESTARTS AGE
...
heapster-5d4bf58946-6dmgf 1/1 Running 0 113s
monitoring-influxdb-866db5f944-d7rkd 1/1 Running 0 23m
复制代码
20.3 安装 Grafana
apiVersion: apps/v1 # 修改此处为 apps/v1
kind: Deployment
metadata:
name: monitoring-grafana
namespace: kube-system
spec:
replicas: 1
selector: # 由于修改了 api 版本,所以增加此处
matchLabels: # 标签选择器
task: monitoring # 标签选择器
k8s-app: grafana # 标签选择器
template:
metadata:
labels:
task: monitoring
k8s-app: grafana
spec:
containers:
- name: grafana
image: k8s.gcr.io/heapster-grafana-amd64:v5.0.4
ports:
- containerPort: 3000
protocol: TCP
volumeMounts:
- mountPath: /etc/ssl/certs
name: ca-certificates
readOnly: true
- mountPath: /var
name: grafana-storage
env:
- name: INFLUXDB_HOST
value: monitoring-influxdb
- name: GF_SERVER_HTTP_PORT
value: "3000"
- name: GF_AUTH_BASIC_ENABLED
value: "false"
- name: GF_AUTH_ANONYMOUS_ENABLED
value: "true"
- name: GF_AUTH_ANONYMOUS_ORG_ROLE
value: Admin
- name: GF_SERVER_ROOT_URL
value: /
volumes:
- name: ca-certificates
hostPath:
path: /etc/ssl/certs # 注意配置 ssl 证书
- name: grafana-storage
emptyDir: {} # 注意配置持久存储
---
apiVersion: v1
kind: Service
metadata:
labels:
kubernetes.io/cluster-service: 'true'
kubernetes.io/name: monitoring-grafana
name: monitoring-grafana
namespace: kube-system
spec:
type: NodePort # 如果需要通过外部访问可以打开,可以关闭 heapster 的此项
ports:
- port: 80
targetPort: 3000
selector:
k8s-app: grafana
复制代码
其他
自己将手记发在:https://github.com/redhatxl/awesome-kubernetes-notes欢迎一键三连
评论