记录安装prometheus + grafana
1.从github 下载prometheus
git clone https://github.com/coreos/kube-prometheus.git
cd kube-prometheus/manifests
2.修改grafana-service.yaml文件,使用nodepode方式访问grafana
vi grafana-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
app: grafana
name: grafana
namespace: monitoring
spec:
type: NodePort #新增
ports:
- name: http
port: 3000
targetPort: http
nodePort: 30100 # 新增
selector:
app: grafana
3.修改prometheus-service.yaml, 使用nodepode方式访问
vi prometheus-service.yaml
apiVersion: v1
kind: Service
metadata:
labels:
prometheus: k8s
name: prometheus-k8s
namespace: monitoring
spec:
type: NodePort # 新增
ports:
- name: web
port: 9090
targetPort: web
nodePort: 30200 # 新增
selector:
app: prometheus
prometheus: k8s
sessionAffinity: ClientIP
4.修改alertmanager-service.yaml, 改为nodeport
apiVersion: v1
kind: Service
metadata:
labels:
alertmanager: main
name: alertmanager-main
namespace: monitoring
spec:
type: NodePort
ports:
- name: web
port: 9093
targetPort: web
nodePort: 30300
selector:
alertmanager: main
app: alertmanager
sessionAffinity: ClientIP
5.部署
该命令多运行几次
kubectl apply -f manifests/
6.查看pod是否正常运行
kubectl get pod -n monitoring
如果有镜像加载失败,需要手动加载
7.手动加载镜像gcr.io-->registry.aliyuncs.com
docker pull quay-mirror.qiniu.com/prometheus/alertmanager:v0.18.0
docker tag quay-mirror.qiniu.com/prometheus/alertmanager:v0.18.0 quay.io/prometheus/alertmanager:v0.18.0
docker pull quay-mirror.qiniu.com/prometheus/node-exporter:v0.18.1
docker tag quay-mirror.qiniu.com/prometheus/node-exporter:v0.18.1 quay.io/prometheus/node-exporter:v0.18.1
docker pull quay-mirror.qiniu.com/coreos/k8s-prometheus-adapter-amd64:v0.5.0
docker tag quay-mirror.qiniu.com/coreos/k8s-prometheus-adapter-amd64:v0.5.0 quay.io/coreos/k8s-prometheus-adapter-amd64:v0.5.0
docker pull quay-mirror.qiniu.com/prometheus/prometheus:v2.11.0
docker tag quay-mirror.qiniu.com/prometheus/prometheus:v2.11.0 quay.io/prometheus/prometheus:v2.11.0
docker pull quay-mirror.qiniu.com/coreos/prometheus-operator:v0.34.0
docker tag quay-mirror.qiniu.com/coreos/prometheus-operator:v0.34.0 quay.io/coreos/prometheus-operator:v0.34.0
8.再次查看pod是否正常运行
kubectl get pod -n monitoring
kubectl get svc --all-namespaces
9.访问prometheus界面
http://192.168.188.130:30200/
sum by (pod_name)(rate(container_cpu_usage_seconds_total{image!="",pod_name!=""}[1m]))
10.访问grafana
http://192.168.188.130:30100/
第一次登陆会要求修改密码
admin/admin