本篇笔记记录了在树莓派上运行的Kubernetes集群中采用手工方式一步步搭建Prometheus系统的过程,从而实现对于Kubernetes资源的监控能力。虽然有更加快捷的部署方式,但是通过这些步骤,可以加深对于Kubernetes核心资源和Prometheus监控概念的理解。
硬件环境信息:PaspberryPi4B 8GB内存,64G SD存储
操作系统信息:Ubuntu 20.04.1 LTS ARM64版本
部署前提:预先部署好Kubernetes 1.25版本
正文开始:
Step1: 创建prometheus的configmap YAML文件prometheus-cm.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: prometheus-config
namespace: default
data:
prometheus.yml: |
global:
scrape_interval: 15s
scrape_timeout: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
Step2:在K8S中创建configmap资源
kubectl apply -f prometheus-cm.yaml
Step3:创建prometheus的deployment文件
apiVersion: apps/v1
kind: Deployment
metadata:
name: prometheus
namespace: default
labels:
app: prometheus
spec:
selector:
matchLabels:
app: prometheus
template:
metadata:
labels:
app: prometheus
spec:
serviceAccountName: prometheus
containers:
- image: prom/prometheus:v2.24.1
name: prometheus
securityContext:
runAsUser: 0
args:
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheu