k8s prometheus-operator

1,225次阅读
没有评论

共计 5328 个字符,预计需要花费 14 分钟才能阅读完成。

k8s prometheus-operator

不得不说operator这玩意是真滴香

Prometheus operator简介

Prometheus operator部署

从git仓库上获取安装yaml

[root@k8s-master ~]#
 mkdir prometheus
[root@k8s-master ~]# cd prometheus
[root@k8s-master prometheus]# git clone https://github.com/prometheus-operator/kube-prometheus.git
[root@k8s-master prometheus]# cd kube-prometheus/
# 切换到合适自己集群的版本,我的k8s是1.18.9
[root@k8s-master kube-prometheus]# git checkout release-0.5
[root@k8s-master kube-prometheus]# ll
total 128
-rwxr-xr-x 1 root root   610 Aug 18 21:11 build.sh
-rw-r--r-- 1 root root  3039 Aug 18 21:11 code-of-conduct.md
-rw-r--r-- 1 root root  1422 Aug 18 21:11 DCO
drwxr-xr-x 2 root root   321 Aug 18 21:11 docs
-rw-r--r-- 1 root root  1623 Aug 18 21:11 example.jsonnet
drwxr-xr-x 6 root root  4096 Aug 18 21:11 examples
drwxr-xr-x 4 root root    54 Aug 18 21:11 experimental
-rw-r--r-- 1 root root  1290 Aug 18 21:11 go.mod
-rw-r--r-- 1 root root 16389 Aug 18 21:11 go.sum
drwxr-xr-x 3 root root    68 Aug 18 21:11 hack
drwxr-xr-x 3 root root    29 Aug 18 20:59 jsonnet
-rw-r--r-- 1 root root   206 Aug 18 20:59 jsonnetfile.json
-rw-r--r-- 1 root root  3811 Aug 18 21:11 jsonnetfile.lock.json
-rw-r--r-- 1 root root  3458 Aug 18 21:11 kustomization.yaml
-rw-r--r-- 1 root root 11325 Aug 18 20:59 LICENSE
-rw-r--r-- 1 root root  1447 Aug 18 21:11 Makefile
drwxr-xr-x 3 root root  4096 Aug 18 21:12 manifests
-rw-r--r-- 1 root root   126 Aug 18 21:11 NOTICE
-rw-r--r-- 1 root root   178 Aug 18 21:11 OWNERS
-rw-r--r-- 1 root root 32795 Aug 18 21:11 README.md
drwxr-xr-x 2 root root   104 Aug 18 21:11 scripts
-rw-r--r-- 1 root root   928 Aug 18 21:11 sync-to-internal-registry.jsonnet
drwxr-xr-x 3 root root    17 Aug 18 20:59 tests
-rwxr-xr-x 1 root root   808 Aug 18 21:11 test.sh

调整镜像仓库地址

[root@k8s-master kube-prometheus]# cd manifests/
[root@k8s-master manifests]# pwd
/root/prometheus/kube-prometheus/manifests
[root@k8s-master manifests]# sed -i 's/quay.io/quay.mirrors.ustc.edu.cn/g' setup/prometheus-operator-deployment.yaml
[root@k8s-master manifests]# sed -i 's/quay.io/quay.mirrors.ustc.edu.cn/g' prometheus-prometheus.yaml
[root@k8s-master manifests]# sed -i 's/quay.io/quay.mirrors.ustc.edu.cn/g' alertmanager-alertmanager.yaml
[root@k8s-master manifests]# sed -i 's/quay.io/quay.mirrors.ustc.edu.cn/g' kube-state-metrics-deployment.yaml
[root@k8s-master manifests]# sed -i 's/quay.io/quay.mirrors.ustc.edu.cn/g' node-exporter-daemonset.yaml
[root@k8s-master manifests]# sed -i 's/quay.io/quay.mirrors.ustc.edu.cn/g' prometheus-adapter-deployment.yaml

安装prometheus-operator

[root@k8s-master prometheus]# kubectl apply -f setup/
[root@k8s-master prometheus]# kubectl get pod -n monitoring
[root@k8s-master manifests]# kubectl get pod -n monitoring
NAME                                   READY   STATUS    RESTARTS   AGE
prometheus-operator-5cd4d464cc-w6rfh   2/2     Running   7          7d

# 此时查看crd资源声明
[root@k8s-master manifests]# kubectl api-resources | grep monitoring
alertmanagers                                  monitoring.coreos.com          true         Alertmanager
podmonitors                                    monitoring.coreos.com          true         PodMonitor
prometheuses                                   monitoring.coreos.com          true         Prometheus
prometheusrules                                monitoring.coreos.com          true         PrometheusRule
servicemonitors                                monitoring.coreos.com          true         ServiceMonitor
thanosrulers                                   monitoring.coreos.com          true         ThanosRuler

使用operator部署prometheus套件

[root@k8s-master manifests]# kubectl apply -f .
[root@k8s-master manifests]# kubectl get all -n monitoring
NAME                                       READY   STATUS    RESTARTS   AGE
pod/alertmanager-main-0                    2/2     Running   6          6d22h
pod/grafana-5c55845445-26qcl               1/1     Running   3          7d
pod/kube-state-metrics-75f946484-l4b5f     3/3     Running   13         7d
pod/node-exporter-2tp5j                    2/2     Running   7          7d
pod/node-exporter-ppxl5                    2/2     Running   6          7d
pod/prometheus-adapter-7d68d6f886-v5jfj    1/1     Running   5          7d
pod/prometheus-k8s-0                       3/3     Running   10         7d
pod/prometheus-operator-5cd4d464cc-w6rfh   2/2     Running   7          7d

NAME                            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
service/alertmanager-main       NodePort    10.96.30.40     <none>        9093:32213/TCP               7d
service/alertmanager-operated   ClusterIP   None            <none>        9093/TCP,9094/TCP,9094/UDP   7d
service/grafana                 NodePort    10.96.236.242   <none>        3000:32381/TCP               7d
service/kube-state-metrics      ClusterIP   None            <none>        8443/TCP,9443/TCP            7d
service/node-exporter           ClusterIP   None            <none>        9100/TCP                     7d
service/prometheus-adapter      ClusterIP   10.96.213.238   <none>        443/TCP                      7d
service/prometheus-k8s          NodePort    10.96.42.82     <none>        9090:30197/TCP               7d
service/prometheus-operated     ClusterIP   None            <none>        9090/TCP                     7d
service/prometheus-operator     ClusterIP   None            <none>        8443/TCP                     7d

NAME                           DESIRED   CURRENT   READY   UP-TO-DATE   AVAILABLE   NODE SELECTOR            AGE
daemonset.apps/node-exporter   2         2         2       2            2           kubernetes.io/os=linux   7d

NAME                                  READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/grafana               1/1     1            1           7d
deployment.apps/kube-state-metrics    1/1     1            1           7d
deployment.apps/prometheus-adapter    1/1     1            1           7d
deployment.apps/prometheus-operator   1/1     1            1           7d

NAME                                             DESIRED   CURRENT   READY   AGE
replicaset.apps/grafana-5c55845445               1         1         1       7d
replicaset.apps/kube-state-metrics-75f946484     1         1         1       7d
replicaset.apps/prometheus-adapter-7d68d6f886    1         1         1       7d
replicaset.apps/prometheus-operator-5cd4d464cc   1         1         1       7d

NAME                                 READY   AGE
statefulset.apps/alertmanager-main   1/1     7d
statefulset.apps/prometheus-k8s      1/1     7d

使用NodePort方式暴露服务测试访问

/# 修改type为NodePort即可
[root@k8s-master manifests]# kubectl edit svc -n monitoring grafana
[root@k8s-master manifests]# kubectl edit svc -n monitoring prometheus-k8s
[root@k8s-master manifests]# kubectl edit svc -n monitoring alertmanager-main

[root@k8s-master manifests]# kubectl get svc -n monitoring
NAME                    TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                      AGE
alertmanager-main       NodePort    10.96.30.40     <none>        9093:32213/TCP               7d
alertmanager-operated   ClusterIP   None            <none>        9093/TCP,9094/TCP,9094/UDP   7d
grafana                 NodePort    10.96.236.242   <none>        3000:32381/TCP               7d
kube-state-metrics      ClusterIP   None            <none>        8443/TCP,9443/TCP            7d
node-exporter           ClusterIP   None            <none>        9100/TCP                     7d
prometheus-adapter      ClusterIP   10.96.213.238   <none>        443/TCP                      7d
prometheus-k8s          NodePort    10.96.42.82     <none>        9090:30197/TCP               7d
prometheus-operated     ClusterIP   None            <none>        9090/TCP                     7d
prometheus-operator     ClusterIP   None            <none>        8443/TCP                     7d

请根据自己集群分配得NodePort访问以下三个服务 prometheus /altermanager /grafana

k8s prometheus-operator
k8s prometheus-operator
k8s prometheus-operator

正文完
 
xadocker
版权声明:本站原创文章,由 xadocker 2020-08-22发表,共计5328字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)