k8s部署prometheus
  EeGZtZT5Jsfk 2023年11月02日 35 0

部署到一个k8s集群

git clone -b release-0.12 https://github.com/prometheus-operator/kube-prometheus.git
cd kube-prometheus
grep "image:" ./manifests/ -R

国内无法下载的镜像:

以8s.gcr.io开头 k8s.gcr.io/kube-state-metrics/kube-state-metrics:v2.5.0 k8s.gcr.io/prometheus-adapter/prometheus-adapter:v0.9.1

apply如果报  too long: must have at most 262144b bytes 字节太长。则create命令创建
manifests # kubectl create -f setup/
manifests # kubctl apply -f .
kubectl get pods -n monitoring
kubectl get configmap -n monitoring # 配置文件

爆露prometheus端口

manifests # vim prometheus-service.yaml
spec:
type: NodePort
ports:
• name: web
targetPort: web
nodePort:	39090
manifests # kubectl apply -f prometheus-service.yaml
manifests # kubectl get svc -n monitoring

爆露grafana端口

manifests # vim grafana-service.yaml
spec:
type: NodePort
ports:
• name: web
targetPort: web
nodePort:	33000
manifests # kubectl apply -f prometheus-service.yaml
manifests # kubectl apply -f grafana-service.yaml
manifests # kubectl get svc -n monitoring

获取 NodeIp

export NODE_IP=$(kubectl get nodes -o jsonpath="{.items[0].status.addresses[0].address}")

获取 NodePort

export NODE_PORT=$(kubectl -n monitoring get services prometheus-k8s -o jsonpath="{.spec.ports[0].nodePort}")

获取 Address

echo http://NODE_PORT地址: http://NODE_PORT
用户名: admin
密码: kubepi调整访问策略
kubectl delete -f prometheusAdapter.networkPolicy.yaml
kubectl delete -f grafanaAdapter.networkPolicy.yaml
kubectl get networkpolicies.networking.k8s.io -n monitoring
pllicyTypes:

二进制部署prometheus:

prometheus.io/download/  # prometheus官网地址
mkdir /apps
cd //usr/local/src
wget -c https://github.com/prometheus/prometheus/releases/download/v2.42.0/prometheus-2.42.0.linux-amd64.tar.gz
tar xf prometheus-2.42.0.linux-amd64.tar.gz
mv prometheus-2 .42.0.linux-amd64 /apps
ln -sv /apps/prometheus-2 .42.0.linux-amd64 /apps/prometheus
cd /apps/prometheus
./prometheus --web.enable-lifecycle

重启

--web.enable-lifecycle 改配置文件直接reload不需要重启

具体步骤如下:

  1. 在Prometheus的配置文件(prometheus.yml)中开启HTTP服务的生命周期接口(--web.enable-lifecycle)。
  2. 向Prometheus发送POST请求,执行热加载操作,例如:
curl -X POST http://localhost:9090/-/reload

这将会重新加载配置文件,并立即生效。

请注意,使用生命周期接口时需要谨慎。任何具有访问权限的人都可以使用该接口重新加载配置文件,因此需要采取相应的安全措施以避免滥用。

服务配置

vim /etc/systemd/system/prometheus.service
[unit]
Description=prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target

[Service]
Restart=on-failure
WorkingDirectory=/apps/prometheus/                # promtehus指定数据存储路径
ExecStart=/apps/prometheus/prometheus --config.file=/apps/prometheus/prometheus.yml  --web.enable-lifecycle  --storage.tsdb.path="/data/prometheus"

[Install]
WantedBy=multi-user.target

systemctl daemon-reload  
systemctl restart prometheus
systemctl enable prometheus
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

EeGZtZT5Jsfk