当前位置: 首页 > article >正文

k8s 部署 prometheus

创建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: 'prometheus'
        static_configs:
          - targets: ['localhost:9090', '10.0.2.13:31672']

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:
      # hostNetwork: true
      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

访问

http://10.0.2.12:30090/

10.0.2.12为宿主机ip,30090为Service映射的port


http://www.kler.cn/a/327946.html

相关文章:

  • Android中级控件
  • Fivetran+Milvus:AI搜索新时代的数据迁移利器
  • 学习记录:js算法(五十):二叉树的右视图
  • 【Preference Learning】Reasoning with Language Model is Planning with World Model
  • mysql学习教程,从入门到精通,SQL 表、列别名(Aliases)(30)
  • Spring Boot框架在甘肃非遗文化网站设计中的运用
  • ubuntu配置python环境
  • 深度学习基础及技巧
  • Linux性能调优技巧
  • 汽车零部件开发流程关键阶段
  • PowerShell无法执行yarn命令
  • Qt_线程介绍与使用
  • Wpf Image 展示方式 图片处理 显示
  • 828华为云征文|华为云 Flexus X 实例初体验
  • 选择更轻松:山海鲸可视化与PowerBI的深度对比
  • MATLAB在无线通信标准与协议支持中的作用
  • 打造未来社交:区块链社交DAO的颠覆性开发之路
  • 2.1 HuggingFists系统架构(一)
  • Go 项目开发常用设计模式
  • OpenCV图像文件读写(1)检查 OpenCV 是否支持某种图像格式的读取功能函数haveImageReader()的使用