我们上一章其实监控还缺少很多东西,我们可以通过部署已经写好整合包
作为案例来编写适合自己环境的监控指标收集,我找到了两个版本在这里演示下
方法1 通过yaml文件进行部署
https://github.com/coreos/kube-prometheus
先将之前我们部署的停掉
kubectl delete -f .
1、拉取软件包
wget https://gitee.com/hackerwjz/kube-prometheus/repository/archive/main.zip
//gitee.com/hackerwjz/kube-prometheus/repository/archive/release-0.9.zip
根据自己集群的版本去拉取,我这里是1.22.2所以拉取main包
unzip main.zip
cd kube-prometheus-main/manifests/setup/
kubectl apply -f .
cd ..
2、暴露端口访问
vi prometheus-service.yaml
type: NodePort #添加
ports:
- name: web
port: 9090
targetPort: web
nodePort: 30003 #添加
vi grafana-service.yaml
spec:
type: NodePort #添加
ports:
- name: http
port: 3000
targetPort: http
nodePort: 30004 #添加
vi alertmanager-service.yaml
spec:
type: NodePort #添加
ports:
- name: web
port: 9093
targetPort: web
nodePort: 30005 #i提那就啊
4、添加scheduler 和controller-manager的svc
vi prometheus-kubeSchedulerService.yaml
apiVersion: v1
kind: Service
metadata:
namespace: kube-system
name: kube-scheduler
labels:
k8s-app: kube-scheduler
spec:
selector:
component: kube-scheduler
ports:
- name: http-metrics
port: 10251
targetPort: 10251
protocol: TCP
vi prometheus-kubeControllerManagerService.yaml
apiVersion: v1
kind: Service
metadata:
namespace: kube-system
name: kube-controller-manager
labels:
k8s-app: kube-controller-manager
spec:
selector:
component: kube-controller-manager
ports:
- name: http-metrics
port: 10252
targetPort: 10252
protocol: TCP
5、替换镜像
有两个镜像不方便拉取,这里直接修改一下
vi prometheus-adapter-deployment.yaml
39 image: directxman12/k8s-prometheus-adapter-amd64:v0.7.0
vi kube-state-metrics-deployment.yaml
34 image: bitnami/kube-state-metrics:2.3.0
6、启动服务
cd /apps/install_yaml/kube-prometheus/kube-prometheus-main/manifests
kubectl apply -f .
7、查看
kubectl -n monitoring get pod
访问3个端口30003、30004、30005
报警规则啥的都有现成的可以参考
还有一些现成的模板和告警
方法2 通过helm工具部署
项目地址
https://github.com/prometheus-community/helm-charts/tree/main/charts/kube-prometheus-stack
停止上面部署的监控
kubectl delete -f .
kubectl delete -f ./setup
安装
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
手动拉取chars包
//github.com/prometheus-community/helm-charts/releases/download/kube-prometheus-stack-32.2.1/kube-prometheus-stack-32.2.1.tgz
wget 101.43.4.210/kube-prometheus-stack-32.2.1.tgz
tar -zxvf kube-prometheus-stack-32.2.1.tgz
sed -i 's#k8s.gcr.io/ingress-nginx#registry.aliyuncs.com/google_containers#g' kube-prometheus-stack/values.yaml
helm install prometheus-stack ./kube-prometheus-stack
这里会卡住,因为镜像拉不下来他会一直等到完成了再显示
quay.io/prometheus/prometheus:v2.33.1
quay.io/prometheus-operator/prometheus-config-reloader:v0.54.0
quay.io/kiwigrid/k8s-sidecar:1.15.1
grafana/grafana:8.3.5
quay.io/prometheus-operator/prometheus-operator:v0.54.0
k8s.gcr.io/kube-state-metrics/kube-state-metrics:v2.3.0
quay.io/prometheus/node-exporter:v1.3.1
quay.io镜像加速
https://tool.chinaz.com/speedtest/quay.io #这里查一个快点的ip
vi /etc/hosts
3.219.111.229 quay.io
拉取metrics-stats镜像
docker pull bitnami/kube-state-metrics:2.3.0
docker tag bitnami/kube-state-metrics:2.3.0 k8s.gcr.io/kube-state-metrics/kube-state-metrics:v2.3.0
留个镜像备份
wget 101.43.4.210/prometheus-operator.tar.gz
获取密码
kubectl get secret test-grafana -o yaml | grep admin-password | grep -v '{}' | awk '{print $2}' | base64 -d
我不太清楚operator怎么这么调访问,这边就先edit直接改了,看看效果
这边也是和上面的一样已经全部都配置好了的。。。用到再研究吧啊( •̀ ω •́ )✧