在Rancher管理的本地k8s集群上部署kube Prometheus组件

kube-prometheus安装与配置

1.kube-prometheus下载,解压,进入目录

1
2
3
wgets https://github.com/prometheus-operator/kube-prometheus/archive/refs/tags/v0.13.0.tar.gz 
tar -xf v0.13.0.tar.gz 
cd kube-prometheus-0.13.0/manifests/

2.修改prometheus、grafana、alertmanager的ingress文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#下面这个是prometheus-ingress.yaml,grafana-ingress.yaml和alertmanager-ingress.yaml内容类似
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: prometheus-k8s-ingress
  namespace: monitoring
  annotations:
    field.cattle.io/publicEndpoints: >-
      [{"addresses":["192.168.1.181","192.168.1.182","192.168.1.183","192.168.1.184","192.168.1.185"],"port":443,"protocol":"HTTPS","serviceName":"monitoring:prometheus-k8s","ingressName":"monitoring:prometheus-k8s-ingress","hostname":"prometheus.ga.skyvault.cn","path":"/","allNodes":false}]
    kubernetes.io/ingress.class: "nginx"
    prometheus.io/http_probe: "true"
spec:
  ingressClassName: nginx
  rules:
  - host: prometheus.ga.skyvault.cn
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: prometheus-k8s
            port:
              number: 9090
  tls:
    - hosts:
        - prometheus.ga.skyvault.cn
      secretName: skyvault-cn-tls-certificate
status:
  loadBalancer:
    ingress:
      - ip: 192.168.1.181
      - ip: 192.168.1.182
      - ip: 192.168.1.183
      - ip: 192.168.1.184
      - ip: 192.168.1.185

3.镜像可能拉取不到,需要修改拉取的源

将镜像源改成私有镜像仓库

优化安装了psycopg2的python镜像大小

下面这个Dockerfile是程序原本的Dockerfile

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
FROM python:3.10-slim-buster

WORKDIR /app
    
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple --no-cache-dir \
    && pip3 install torch==2.3.1+cpu --no-cache-dir -f https://download.pytorch.org/whl/torch_stable.html

COPY . .

CMD ["python3", "main.py", "web"]

现在要在镜像中安装psycopg2来使用postgresql