k8s安装prometheus
我本地安装的k8s是1.19.9这个版本,需要找到对应的安装版本
kube-prometheus stack | Kubernetes 1.19 | Kubernetes 1.20 | Kubernetes 1.21 | Kubernetes 1.22 | Kubernetes 1.23 |
release-0.7 | ✔ | ✔ | ✗ | ✗ | ✗ |
release-0.8 | ✗ | ✔ | ✔ | ✗ | ✗ |
release-0.9 | ✗ | ✗ | ✔ | ✔ | ✗ |
release-1.0 | ✗ | ✗ | ✗ | ✔ | ✔ |
main | ✗ | ✗ | ✗ | ✔ | ✔ |
目前我这个版本对应的是prometheus release-0.7这个版本,那么我们就直接打开
https://github.com/prometheus-operator/kube-prometheus/tree/release-0.7
克隆代码
git clone https://github.com/prometheus-operator/kube-prometheus.git cd kube-prometheus
我们做一些简单的修改来配置可以直接访问prometheus
vi manifests/prometheus-service.yaml
主要是添加一个nodeport端口,最后整个yaml大概如下:
apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/component: prometheus app.kubernetes.io/instance: k8s app.kubernetes.io/name: prometheus app.kubernetes.io/part-of: kube-prometheus app.kubernetes.io/version: 2.36.2 name: prometheus-k8s namespace: monitoring spec: ports: - name: web port: 9090 targetPort: web nodePort: 30090 - name: reloader-web port: 8080 targetPort: reloader-web selector: app.kubernetes.io/component: prometheus app.kubernetes.io/instance: k8s app.kubernetes.io/name: prometheus app.kubernetes.io/part-of: kube-prometheus sessionAffinity: ClientIP
接着我们修改报警管理
vi manifests/alertmanager-service.yaml apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/component: alert-router app.kubernetes.io/instance: main app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus app.kubernetes.io/version: 0.24.0 name: alertmanager-main namespace: monitoring spec: ports: - name: web port: 9093 targetPort: web nodePort: 30093 - name: reloader-web port: 8080 targetPort: reloader-web selector: app.kubernetes.io/component: alert-router app.kubernetes.io/instance: main app.kubernetes.io/name: alertmanager app.kubernetes.io/part-of: kube-prometheus sessionAffinity: ClientIP
然后我们修改下grafana的yaml文件
vi manifests/grafana-service.yaml apiVersion: v1 kind: Service metadata: labels: app.kubernetes.io/component: grafana app.kubernetes.io/name: grafana app.kubernetes.io/part-of: kube-prometheus app.kubernetes.io/version: 9.0.1 name: grafana namespace: monitoring spec: ports: - name: http port: 3000 targetPort: http nodePort: 30099 selector: app.kubernetes.io/component: grafana app.kubernetes.io/name: grafana app.kubernetes.io/part-of: kube-prometheus
改好以后我们就开始安装了
kubectl create -f manifests/setup until kubectl get servicemonitors --all-namespaces; do date; sleep 1; echo ""; done kubectl create -f manifests/
然后我们观察相关pod,全部启动就可以直接使用节点IP加30099端口访问prometheus