一、环境

centos7
k8s version1.6.2
prometheus-operator version:0.11.3

二、下载

prometheus-operator version:0.11.3支持最低版本kubernetes1.6.2

prometheus-operator下载页面 https://github.com/coreos/prometheus-operator/releases?after=v0.15.0

三、安装

下载完成后进入下载目录

解压

tar -zxf prometheus-operator-0.11.3.tar.gz

进入目录

cd prometheus-operator-0.11.3

kubectl安装
kubectl执行

kubectl apply -f bundle.yaml

安装prometheus-operator相关插件

cd contrib/kube-prometheus
#执行安装脚本
./hack/cluster-monitoring/deploy

在此安装完成

参考 kubernetes之hyperkube方式安装文档-部署k8s集群监控prometheus-operator(五)https://blog.csdn.net/qq_21816375/article/details/80755336

安装时依赖的docker镜像

有网络的情况下可以直接拉取

#需要拉取的镜像
quay.io/coreos/prometheus-operator:v0.11.3

grafana/grafana:4.4.1
quay.io/coreos/grafana-watcher:v0.0.6

quay.io/coreos/kube-state-metrics:v0.5.0

quay.io/prometheus/node-exporter:v0.14.0

quay.io/prometheus/prometheus:v1.7.0
quay.io/coreos/prometheus-config-reloader:v0.0.2
quay.io/prometheus/alertmanager:v0.7.1

对应的镜像说明

yaml文件中出现的镜像

#grafana
grafana/grafana:4.4.1
quay.io/coreos/grafana-watcher:v0.0.6

#kube-state-metrics
quay.io/coreos/kube-state-metrics:v0.5.0

#node-exporter
quay.io/prometheus/node-exporter:v0.14.0

#prometheus-operator
quay.io/coreos/prometheus-operator:v0.11.3

yaml文件中未出现的镜像名,但是部署时有使用到的

# prometheus:v1.7.0需要的镜像
quay.io/prometheus/prometheus:v1.7.0
quay.io/coreos/prometheus-config-reloader:v0.0.2
#prometheus alertmanager
quay.io/prometheus/alertmanager:v0.7.1

保存需要的镜像

docker save -o prometheus-operator-images.tar.gz quay.io/coreos/prometheus-operator:v0.11.3 quay.io/coreos/grafana-watcher:v0.0.6 grafana/grafana:4.4.1 quay.io/coreos/prometheus-config-reloader:v0.0.2  quay.io/prometheus/alertmanager:v0.7.1 quay.io/prometheus/prometheus:v1.7.0 quay.io/coreos/kube-state-metrics:v0.5.0 quay.io/prometheus/node-exporter:v0.14.0

四、查看

1.查看pod

kubectl -n monitoring get pod

[root@docker225 kube-prometheus]# kubectl -n monitoring get pod
NAME                                  READY     STATUS    RESTARTS   AGE
alertmanager-main-0                   2/2       Running   0          1y
alertmanager-main-1                   2/2       Running   0          19h
alertmanager-main-2                   2/2       Running   0          19h
grafana-1482444427-wp5nz              2/2       Running   0          32m
kube-state-metrics-1587421894-hs01m   1/1       Running   0          1y
node-exporter-zbf01                   1/1       Running   0          1y
prometheus-k8s-0                      2/2       Running   0          1y
prometheus-k8s-1                      2/2       Running   0          19h
prometheus-operator-277826456-q7t8h   1/1       Running   2          1y

2.查看对应服务端口

查看对应服务端口是否打开kubectl -n monitoring get svc

[root@docker225 kube-prometheus]# kubectl -n monitoring get svc
NAME                    CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
alertmanager-main       10.254.197.166   <nodes>       9093:30903/TCP      1y
alertmanager-operated   None             <none>        9093/TCP,6783/TCP   1y
grafana                 10.254.22.200    <nodes>       3000:30902/TCP      33m
kube-state-metrics      10.254.59.234    <none>        8080/TCP            1y
node-exporter           None             <none>        9100/TCP            1y
prometheus-k8s          10.254.219.93    <nodes>       9090:30900/TCP      1y
prometheus-operated     None             <none>        9090/TCP            1y
prometheus-operator     10.254.191.143   <none>        8080/TCP            1y

下面所有页面能正常访问即可

访问 grafana http://{masterIP}:30902
访问 prometheus http://{masterIP}:30900
访问alertmanager http://{masterIP}:30902

五、安装碰到的问题

1.镜像拉取问题-ImagePullBackOff

需要访问外网pull镜像,否则需要导入镜像到docker或者私服中

#导出镜像,可以导出多个镜像
docker save -o xxx.tar.gz  image1 image2...
#导入镜像
docker load -i xxx.tar.gz

kubectl describe pod可以查看需要的镜像

2. calico没有对应monitoring的grafana信息

重新安装grafana即可解决

k8s安装prometheus-operator网络问题

3. 其他碰到的问题

docker search错误

docker search 报错

[root@docker225 prometheus-operator-0.11.3]# docker search mysql
Error response from daemon: Get https://index.docker.io/v1/search?q=mysql&n=25: x509: certificate has expired or is not yet valid

问题原因:服务器时间不正确,同步时间后正常
解决方法:
date -s “xxxx-xx-xx 17:xx:xx” 同步时间即可

六、其他

1. prometheus-operator与kubernetes1.6.2版本问题

kubernetes1.6.2最高支持的prometheus-operator为0.11.3
prometheus-operator为0.18.0最低要求kubernetes1.8.0

具体的版本已github上的说明为准
prometheus-operator github地址:https://github.com/coreos/prometheus-operator

2.使用到的命令

k8s

pod

查看所有空间下的pod
kubectl get pod --all-namespaces

 [root@docker225 ~]# kubectl get pod --all-namespaces
    NAMESPACE     NAME                                        READY     STATUS             RESTARTS   AGE
    app-test1     app-test4-service1-4-4-3832218445-jm9vz     1/1       Running            0          12d
    default       prometheus-operator-2021280488-2trck        0/1       ImagePullBackOff   0          52m
    kube-system   calico-node-f25vf                           2/2       Running            4          12d
    kube-system   calico-policy-controller-2698340612-d4r6d   1/1       Running            2          12d
    kube-system   heapster-v1.3.0-2713982671-0n9bm            2/2       Running            0          11d
    kube-system   kube-dns-3412393464-2hrk2                   3/3       Running            7          12d
    kube-system   monitoring-influxdb-grafana-v4-dz9wj        2/2       Running            0          11d

查看默认空间(default)的pod
kubectl get pod

查看指定空间的pod
kubectl -n kube-system get pod 或 kubectl get pod -n kube-system

查看指定的Pod描述
kubectl describe pod [pod name]
kubectl describe pod my-alpine

Logo

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

更多推荐