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

相关推荐
mengge.cloud17 小时前
prometheus+k8s+弹性伸缩,综合项目
云原生·容器·kubernetes·prometheus
xbzb21 小时前
从零容器化部署 ECShop:Harbor 私有仓库 + 自定义 PHP 镜像 + LNMP 三容器
容器·php·harbor·镜像·仓库·ecshop
那明眸似水21 小时前
云原生项目三:Docker秒级启动NextCloud个人网盘存储办公系统
linux·运维·docker·云原生·容器
腾飞开源1 天前
03_Kubernetes 核心概念拆解:从 Spec/Status 收敛到工作负载控制器的设计逻辑
云原生·容器·kubernetes
知已难寻1 天前
Docker 入门:容器技术与 Docker 基础
java·运维·服务器·docker·云原生·容器
xbzb2 天前
镜像到底存在哪:/var/lib/docker 的四级映射与 daemon.json 配置
docker·容器·json·镜像·daemon.json·四级
kuroomi2 天前
Git入门
git·kubernetes
闲云野鹤在人间2 天前
Prometheus入门|搭建Prometheus+Node‑Exporter+Grafana完整主机监控平台
grafana·prometheus
方便面不加香菜2 天前
Docker Volume -- 管理卷Volume详解
运维·docker·容器
江湖有缘2 天前
Docker实战 | 使用Docker部署lemonitor镜像站点列表程序
运维·docker·容器