kubernetes 之容器监控
[root@manager ~]# git clone https://github.com/kubernetes/heapster.git
[root@manager ~]# cd heapster/deploy/kube-config/influxdb/
[root@manager influxdb]# ll
total 12
-rw-r--r-- 1 root root 2276 Jan 31 16:21 grafana.yaml
-rw-r--r-- 1 root root 1100 Jan 31 16:21 heapster.yaml
-rw-r--r-- 1 root root 960 Jan 31 16:21 influxdb.yaml
[root@manager influxdb]# cat influxdb.yaml 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: registry.cn-shenzhen.aliyuncs.com/rancher_cn/heapster-influxdb-amd64:v1.3.3 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
[root@manager influxdb]# kubectl create -f influxdb.yaml
deployment "monitoring-influxdb" created
service "monitoring-influxdb" created
[root@manager influxdb]#
[root@manager influxdb]# kubectl get pods --namespace=kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE
kube-dns-56d46f58f-6hhsl 3/3 Running 3 2h 10.0.71.3 192.168.10.222
kube-dns-56d46f58f-lnr86 3/3 Running 3 2h 10.0.91.4 192.168.10.221
kube-dns-56d46f58f-nbbxp 3/3 Running 3 2h 10.0.91.3 192.168.10.221
kubernetes-dashboard-7cbd9bccdc-g2kbc 1/1 Running 1 1h 10.0.71.4 192.168.10.222
monitoring-influxdb-577c9dbddb-tpdp9 1/1 Running 0 10s 10.0.71.5 192.168.10.222
[root@manager influxdb]# cat grafana.yaml 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: registry.cn-shenzhen.aliyuncs.com/rancher_cn/heapster-grafana-amd64:v4.4.3 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" # 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/namespaces/kube-system/services/monitoring-grafana/proxy value: / volumes: - name: ca-certificates hostPath: path: /etc/ssl/certs - name: grafana-storage emptyDir: {} --- apiVersion: v1 kind: Service metadata: labels: # 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-grafana name: monitoring-grafana namespace: kube-system spec: # In a production setup, we recommend accessing Grafana through an external Loadbalancer # or through a public IP. # type: LoadBalancer # You could also use NodePort to expose the service at a randomly-generated port # type: NodePort ports: - port: 80 targetPort: 3000 selector: k8s-app: grafana [root@manager influxdb]#
[root@manager influxdb]# kubectl create -f grafana.yaml
deployment "monitoring-grafana" created
service "monitoring-grafana" created
[root@manager influxdb]# kubectl get pods --namespace=kube-system -o wide
NAME READY STATUS RESTARTS AGE IP NODE
kube-dns-56d46f58f-6hhsl 3/3 Running 3 2h 10.0.71.3 192.168.10.222
kube-dns-56d46f58f-lnr86 3/3 Running 3 2h 10.0.91.4 192.168.10.221
kube-dns-56d46f58f-nbbxp 3/3 Running 3 2h 10.0.91.3 192.168.10.221
kubernetes-dashboard-7cbd9bccdc-g2kbc 1/1 Running 1 1h 10.0.71.4 192.168.10.222
monitoring-grafana-74b966d696-rwgbn 1/1 Running 0 40s 10.0.71.6 192.168.10.222
monitoring-influxdb-577c9dbddb-tpdp9 1/1 Running 0 2m 10.0.71.5 192.168.10.222
[root@manager influxdb]# cat heapster.yaml apiVersion: v1 kind: ServiceAccount metadata: 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: serviceAccountName: heapster containers: - name: heapster image: registry.cn-hangzhou.aliyuncs.com/outman_google_containers/heapster-amd64:v1.4.0 imagePullPolicy: IfNotPresent command: - /heapster - --source=kubernetes:http://192.168.10.220:8080?inClusterConfig=false&useServiceAccount=true&auth= - --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 [root@manager influxdb]# kubectl create -f heapster.yaml serviceaccount "heapster" created deployment "heapster" created service "heapster" created [root@manager influxdb]# [root@manager influxdb]# kubectl get pods --namespace=kube-system -o wide NAME READY STATUS RESTARTS AGE IP NODE heapster-69cb687966-9s45g 1/1 Running 0 14s 10.0.71.7 192.168.10.222 kube-dns-56d46f58f-6hhsl 3/3 Running 3 2h 10.0.71.3 192.168.10.222 kube-dns-56d46f58f-lnr86 3/3 Running 3 2h 10.0.91.4 192.168.10.221 kube-dns-56d46f58f-nbbxp 3/3 Running 3 2h 10.0.91.3 192.168.10.221 kubernetes-dashboard-7cbd9bccdc-g2kbc 1/1 Running 1 1h 10.0.71.4 192.168.10.222 monitoring-grafana-74b966d696-rwgbn 1/1 Running 0 6m 10.0.71.6 192.168.10.222 monitoring-influxdb-577c9dbddb-tpdp9 1/1 Running 0 8m 10.0.71.5 192.168.10.222