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 adapter
mv *-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/
查看pod
kubectl 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/
查看pod
kubectl get pods -n monitoring
查看service
kubectl get svc -n monitoring
发现全部是prometheus和grafana都是可以集群内部访问
6 使集群外可以访问prometheus 和 grafana
有两种方案可以实现此功能
1) nodeport方式
2)ingress-nginx方式
我么这边为了测试 选择nodeport方式
修改prometheus
# vim prometheus/prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
prometheus: k8s
name: prometheus-k8s
namespace: monitoring
spec:
ports:
- name: web
port: 9090
targetPort: web
type:
NodePort
selector:
app: prometheus
prometheus: k8s
sessionAffinity: ClientIP
~
增加nodeport
kubectl apply -f prometheus/prometheus-service.yaml
修改grafana
# vim grafana/grafana-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: grafana
name: grafana
namespace: monitoring
spec:
ports:
- name: http
port: 3000
targetPort: http
type:
NodePort
selector:
app: grafana
kubectl apply -f grafana/grafana-service.yaml
查看sevice主要是查看nodeport端口我们可以访问
# kubectl get svc -n monitoring
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
alertmanager-main ClusterIP 10.99.60.117 <none> 9093/TCP 67m
alertmanager-operated ClusterIP None <none> 9093/TCP,6783/TCP 67m
grafana NodePort 10.105.159.125 <none> 3000:31746/TCP 67m
kube-state-metrics ClusterIP None <none> 8443/TCP,9443/TCP 67m
node-exporter ClusterIP None <none> 9100/TCP 67m
prometheus-adapter ClusterIP 10.102.146.18 <none> 443/TCP 67m
prometheus-k8s NodePort 10.107.201.125 <none> 9090:32040/TCP 67m
prometheus-operated ClusterIP None <none> 9090/TCP 67m
prometheus-operator ClusterIP None
~
7 访问grafana web页面
http://masterip:31746
8 未完。。。。(主要是持久化存储)和无法访问的pod
所有评论(0)