Kubernetes-Heapster搭建

k8s-Heapster监控

基于CentOS7 k8s集群

Master

镜像下载

1
2
3
docker pull ist0ne/heapster-grafana-amd64
docker pull ist0ne/heapster-amd64
docker pull ist0ne/heapster-influxdb-amd64:v1.1.1

下载heapster

1
2
3
wget https://github.com/kubernetes/heapster/archive/v1.3.0.tar.gz
tar xf v1.3.0.tar.gz
cd heapster-1.3.0/deploy/kube-config/influxdb/

配置文件

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
cat > grafana-deployment.yaml <EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: monitoring-grafana
namespace: kube-system
spec:
replicas: 1
template:
metadata:
labels:
task: monitoring
k8s-app: grafana
spec:
containers:
- name: grafana
#修改镜像
image: docker.io/ist0ne/heapster-grafana-amd64:latest
ports:
- containerPort: 3000
protocol: TCP
volumeMounts:
- mountPath: /var
name: grafana-storage
env:
- name: INFLUXDB_HOST
value: monitoring-influxdb
- name: GRAFANA_PORT
value: "3000"
# The following env variables are required to make Grafana accessible via
# the kubernetes api-server proxy. On production clusters, we recommend
# removing these env variables, setup auth for grafana, and expose the grafana
# service using a LoadBalancer or a public IP.
- 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
# If you're only using the API Server proxy, set this value instead:
# value: /api/v1/proxy/namespaces/kube-system/services/monitoring-grafana/
value: /
volumes:
- name: grafana-storage
emptyDir: {}
EOF

修改配置

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
cat > heapster-deployment.yaml <EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: heapster
namespace: kube-system
spec:
replicas: 1
template:
metadata:
labels:
task: monitoring
k8s-app: heapster
spec:
containers:
- name: heapster
#修改镜像
image: docker.io/ist0ne/heapster-amd64:latest
imagePullPolicy: IfNotPresent
command:
- /heapster
#修改为apiserver地址
- --source=kubernetes:http://192.168.1.90:8080?inClusterConfig=false
- --sink=influxdb:http://monitoring-influxdb:8086
EOF

修改配置

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
cat > influxdb-deployment.yaml <EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: monitoring-influxdb
namespace: kube-system
spec:
replicas: 1
template:
metadata:
labels:
task: monitoring
k8s-app: influxdb
spec:
containers:
- name: influxdb
#修改镜像
image: docker.io/ist0ne/heapster-influxdb-amd64:v1.1.1
volumeMounts:
- mountPath: /data
name: influxdb-storage
volumes:
- name: influxdb-storage
emptyDir: {}
EOF

创建启动

1
2
kubectl create -f /root/heapster-1.3.0/deploy/kube-config/influxdb/influxdb/
kubectl delete -f /root/heapster-1.3.0/deploy/kube-config/influxdb/influxdb/

测试

1
2
3
4
5
6
7
8
9
kubectl get pods --all-namespaces
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default busybox 1/1 Running 6 6h
kube-system heapster-3793345097-cr2kh 1/1 Running 0 6h
kube-system kube-dns-495361171-9mhfj 4/4 Running 0 7h
kube-system kubernetes-dashboard-2899419805-686b7 1/1 Running 1 1d
kube-system monitoring-grafana-4241701950-3w2tw 1/1 Running 0 1d
kube-system monitoring-influxdb-2174575918-8v835 1/1 Running 0 1d

打开浏览器http://192.168.1.90:8080/ui查看状态即可