kubernetes集群监控方案有许多种组合对其进行监控,但是在1.12版本后通常选择prometheus-operator + grafana 进行监控下面我们进行部署监控
1 下载项目
git clone https://github.com/coreos/kube-prometheus.git是因为今年prometheus-operator项目搬到了coreos/kube-prometheus
2 排版
cd kube-prometheus/manifests/mkdir -p operator node-exporter alertmanager grafana kube-state-metrics prometheus serviceMonitor adaptermv *-serviceMonitor* serviceMonitor/mv 0prometheus-operator* operator/mv grafana-* grafana/mv kube-state-metrics-* kube-state-metrics/mv alertmanager-* alertmanager/mv node-exporter-* node-exporter/mv prometheus-adapter* adapter/mv prometheus-* prometheus/
3 创建namespace
kubectl apply -f 00namespace-namespace.yaml
4 创建operator
kubectl apply -f operator/查看podkubectl get pods -n monitoring等pod创建起来在进行下一步
5 创建其他CRD
kubectl apply -f adapter/kubectl apply -f alertmanager/kubectl apply -f node-exporter/kubectl apply -f kube-state-metrics/kubectl apply -f grafana/kubectl apply -f prometheus/kubectl apply -f serviceMonitor/查看podkubectl get pods -n monitoring查看servicekubectl get svc -n monitoring发现全部是prometheus和grafana都是可以集群内部访问
6 使集群外可以访问prometheus 和 grafana
有两种方案可以实现此功能1) nodeport方式2)ingress-nginx方式我么这边为了测试 选择nodeport方式修改prometheus# vim prometheus/prometheus-service.yaml apiVersion: v1kind: Servicemetadata: labels: prometheus: k8s name: prometheus-k8s namespace: monitoringspec: ports: - name: web port: 9090 targetPort: web type: NodePort selector: app: prometheus prometheus: k8s sessionAffinity: ClientIP~ 增加nodeportkubectl apply -f prometheus/prometheus-service.yaml 修改grafana# vim grafana/grafana-service.yaml apiVersion: v1kind: Servicemetadata: labels: app: grafana name: grafana namespace: monitoringspec: ports: - name: http port: 3000 targetPort: http type: NodePort selector: app: grafanakubectl apply -f grafana/grafana-service.yaml查看sevice主要是查看nodeport端口我们可以访问# kubectl get svc -n monitoringNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEalertmanager-main ClusterIP 10.99.60.1179093/TCP 67malertmanager-operated ClusterIP None 9093/TCP,6783/TCP 67mgrafana NodePort 10.105.159.125 3000:31746/TCP 67mkube-state-metrics ClusterIP None 8443/TCP,9443/TCP 67mnode-exporter ClusterIP None 9100/TCP 67mprometheus-adapter ClusterIP 10.102.146.18 443/TCP 67mprometheus-k8s NodePort 10.107.201.125 9090:32040/TCP 67mprometheus-operated ClusterIP None 9090/TCP 67mprometheus-operator ClusterIP None ~
7 访问grafana web页面
http://masterip:31746
8 未完。。。。(主要是持久化存储)和无法访问的pod