1.kube-prometheus安装
1.1 下载
访问地址:https://github.com/prometheus-operator/kube-prometheus/releases
点击Source code (tar.gz)进行下载,并上传到k8s服务器master节点
1.2解压
tar zxvf kube-prometheus-0.11.0.tar.gz
1.3进入kube-prometheus-0.11.0/manifests目录
cd kube-prometheus-0.11.0
1.4部署(目录可直接部署kube-prometheus)
# create namespace and CRDs
kubectl create -f manifests/setup
# wait for CRD creation to complete
until kubectl get servicemonitors --all-namespaces ; do date; sleep 1; echo ""; done
# create monitoring components
kubectl create -f manifests/
注意:如果报镜像无法下载。
解决办法修改为国内镜像改完后重新执行kubectl apply -f manifests/
1.修改manifests/kubeStateMetrics-deployment.yaml的kube-state-metrics:2.5.0镜像
vi manifests/kubeStateMetrics-deployment.yaml
#image: k8s.gcr.io/kube-state-metrics/kube-state-metrics:v2.5.0
image: registry.cn-hangzhou.aliyuncs.com/my-name1/kube-state-metrics:2.5.0
2.修改manifests/prometheusAdapter-deployment.yaml的prometheus-adapter:v0.9.1镜像
vi manifests/prometheusAdapter-deployment.yaml
#image: k8s.gcr.io/prometheus-adapter/prometheus-adapter:v0.9.1
image: registry.cn-hangzhou.aliyuncs.com/my-name1/prometheus-adapter:v0.9.1
1.5查看
kubectl get pods -n monitoring
1.6使用nodeport方式把grafana的端口暴露出来
修改grafana的service,将clusterip改为nodeport
kubectl edit svc grafana -n monitoring
1.7查看上一步nodeport端口
kubectl get svc -n monitoring
1.8访问grafana
使用步骤1.7的端口来访问grafana
账号admin
密码admin
1.9 导入import模板
1.10选择数据源
默认已经添加了prometheus数据源,直接选择,点击import
1.11查看k8s监控