k8s环境下安装部署prometheus(普罗米修斯)

环境准备

1、安装部署git环境

yum install git

2、安装部署k8s

点击跳转

3、私有镜像仓库

点击跳转

部署

1、在github库中下载最新源代码

git clone https://github.com/coreos/kube-prometheus

2、查看原配置文件

cd kube-prometheus/manifests
ls

3、重新分类梳理

mkdir -p operator node-exporter alertmanager grafana kube-state-metrics prometheus serviceMonitor adapter
mv *-serviceMonitor* serviceMonitor/
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/

4、镜像问题

其中k8s.gcr.io/addon-resizer:1.8.4镜像被墙,无法下载,所以需要先通过阿里云下载下来,再传入本地镜像仓库

# docker pull registry.cn-beijing.aliyuncs.com/minminmsn/addon-resizer:1.8.4
# docker tag registry.cn-beijing.aliyuncs.com/minminmsn/addon-resizer:1.8.4 192.168.1.69:5000/addon-resizer:1.8.4 
# docker rmi registry.cn-beijing.aliyuncs.com/minminmsn/addon-resizer:1.8.4
# docker push 192.168.1.69:5000/addon-resizer:1.8.4

再进入配置文件中修改镜像为镜像仓库中的Image名

vi kube-state-metrics/kube-state-metrics-deployment.yaml

把其中的镜像源k8s.gcr.io/addon-resizer:1.8.4 改为192.168.1.69:5000/addon-resizer:1.8.4

5、dashboard访问设置(可视化管理)

nodePort方式访问,端口号32000

vi grafana/grafana-service

替换为以下内容

apiVersion: v1
kind: Service
metadata:
  labels:
    app: grafana
  name: grafana
  namespace: monitoring
spec:
  type: NodePort
  ports:
  - name: http
    port: 3000
    nodePort: 3200
    targetPort: http
  selector:
    app: grafana

如设置其他nodeport,执行第六步时报错

The Service "grafana" is invalid: spec.ports[0].nodePort: Invalid value: 50000: provided port is not in the valid range. The range of valid ports is 30000-32767

因为nodeport在k8s中默认nodeport范围是30000-32767超出范围则会报错,解决方案为在k8sapi配置文件中添加参数指定nodeport范围

/etc/kubernetes/manifests/kube-apiserver.yaml

添加

- --service-node-port-range=30000-40000

6、应用部署

全部复制执行

kubectl apply -f .
kubectl apply -f operator/
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/

最后检查一下

kubectl get pods -n monitoring

都run起来了就OK了

NAME                                   READY   STATUS    RESTARTS   AGE
alertmanager-main-0                    2/2     Running   0          98m
alertmanager-main-1                    2/2     Running   0          97m
alertmanager-main-2                    2/2     Running   0          97m
grafana-558647b59-jxj86                1/1     Running   0          95m
kube-state-metrics-594d866c6c-jrxr6    4/4     Running   0          97m
node-exporter-bxcbs                    2/2     Running   0          99m
node-exporter-mb7np                    2/2     Running   0          99m
node-exporter-wn45c                    2/2     Running   0          99m
prometheus-adapter-74fc6495d7-v8k2g    1/1     Running   0          115m
prometheus-k8s-0                       3/3     Running   1          98m
prometheus-k8s-1                       3/3     Running   1          98m
prometheus-operator-69bd579bf9-v6tqn   1/1     Running   0          117m

7、访问

使用浏览器访问Ip:32000,初始账号:admin 密码:admin

参考文档:https://cloud.tencent.com/developer/article/1444005

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐