prometheus operator介绍:
由coreOS基于prometheus开发专用于kubernetes监控
监测每个附件,都要为此监控创建一个service
prometheus-operator框架.png
部署prometheus,准备工作
#下载部署yaml
git clone https://github.com/coreos/prometheus-operator.git
#创建namespace
kubectl create ns monitoring
#准备镜像
docker pull quay.io/coreos/prometheus-config-reloader:v0.20.0
docker pull quay.io/coreos/hyperkube:v1.7.6_coreos.0
docker pull quay.io/coreos/configmap-reload:v0.0.1
docker pull quay.io/coreos/prometheus-operator:v0.20.0
docker pull quay.io/prometheus/prometheus:v2.2.1
docker pull quay.io/prometheus/alertmanager:v0.15.1
docker pull quay.io/coreos/grafana-watcher:v0.0.8
docker pull quay.io/prometheus/node-exporter:v0.15.2
docker pull docker.io/grafana/grafana:5.0.0
docker tag docker.io/grafana/grafana:5.0.0 grafana/grafana:5.0.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-state-metrics:v1.2.0
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-state-metrics:v1.2.0 gcr.io/google_containers/kube-state-metrics:v1.2.0
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/addon-resizer:1.7
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/addon-resizer:1.7 gcr.io/google_containers/addon-resizer:1.7
部署prometheus
#以下所有操作均在monitoring命名空间里做
helm install --name prometheus-operator prometheus-operator
mkdir -p kube-prometheus/charts
helm package -d helm/kube-prometheus/charts helm/alertmanager helm/grafana helm/prometheus helm/exporter-kube-dns helm/exporter-kube-scheduler helm/exporter- kubelets helm/exporter-node helm/exporter-kube-controller-manager helm/exporter-kube-etcd helm/exporter-kube-state helm/exporter-coredns helm/exporter-kubernetes
helm install helm/kube-prometheus --name kube-prometheus
helm install --name alertmanager alertmanager
helm install --name grafana grafana
#把svc 的 alertmanager ;grafana-grafana ;kube-prometheus类型设置为NodePort
#模板的使用 https://grafana.com/dashboards/315
#访问服务prometheus grafana-grafana的所在的nodeip:grafana-grafana svc的端口
[root@k8s-master weavescope]#kubectl get pods -n monitoring -o wide
NAME READY STATUS RESTARTS AGE IP NODE
prometheus-d7pqn 1/1 Running 0 6m 192.168.26.51 k8s-node1
grafana-grafana-hhcsr 1/1 Running 0 6m 192.168.26.51 k8s-node1
kube-prometheus-xblx5 1/1 Running 0 6m 192.168.26.52 k8s-node2
#发现grafana-grafana在 k8s-node1节点192.168.26.51
#查看端口
[root@k8s-master1 k8s_weavescope]# kubectl get svc -n monitoring -o wide
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE SELECTOR
grafana-grafana NodePort 10.98.204.58 <none> 80:30995/TCP 9m
浏览器访问k8s-node1ip:端口
192.168.26.51:30995