创建namespace
prometheus-namespace.yaml
| apiVersion: v1 |
| kind: Namespace |
| metadata: |
| name: ns-prometheus |
拉取镜像
| docker pull swr.cn-north-4.myhuaweicloud.com/ddn-k8s/quay.io/prometheus/prometheus:v2.54.0 |
prometheus配置文件configmap
prometheus-configmap.yaml
| apiVersion: v1 |
| kind: ConfigMap |
| metadata: |
| name: prometheus-config |
| namespace: ns-prometheus |
| data: |
| prometheus.yml: |- |
| # Prometheus配置内容 |
| global: |
| scrape_interval: 15s |
| evaluation_interval: 15s |
| scrape_configs: |
| - job_name: |
| static_configs: |
| - targets: [ |
localhost:9090
为prometheus服务自己本身的metrics;10.0.2.13:31672
为node exporter的metrics。targets是一个数组可以增加多个。
prometheus 的 Deployment
prometheus-deployment.yaml
| apiVersion: apps/v1 |
| kind: Deployment |
| metadata: |
| name: prometheus |
| namespace: ns-prometheus |
| spec: |
| replicas: 1 |
| selector: |
| matchLabels: |
| name: prometheus |
| template: |
| metadata: |
| labels: |
| name: prometheus |
| spec: |
| |
| containers: |
| - name: prometheus |
| image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/quay.io/prometheus/prometheus:v2.54.0 |
| args: |
| - --config.file=/etc/prometheus/prometheus.yml |
| ports: |
| - containerPort: 9090 |
| volumeMounts: |
| - mountPath: /etc/prometheus |
| name: prometheus-config |
| volumes: |
| - name: prometheus-config |
| configMap: |
| name: prometheus-config |
使用Service模式部署可以注释hostNetwork: true
prometheus 的 Service
prometheus-service.yaml
| apiVersion: v1 |
| kind: Service |
| metadata: |
| name: prometheus-service |
| namespace: ns-prometheus |
| spec: |
| selector: |
| name: prometheus |
| ports: |
| - protocol: TCP |
| port: 9090 |
| targetPort: 9090 |
| nodePort: 30090 |
| type: NodePort |
启动
| kubectl apply -f prometheus-namespace.yaml |
| kubectl apply -f prometheus-configmap.yaml |
| kubectl apply -f . |
查看
| kubectl get pod -n ns-prometheus |
| kubectl get svc -n ns-prometheus |
访问
10.0.2.12
为宿主机ip,30090
为Service映射的port
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异