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

相关推荐
就叫飞六吧28 分钟前
K8s 端口暴露:集群统一暴露 vs 单 Pod 暴露
云原生·容器·kubernetes
执笔为剑42 分钟前
docker环境升级数据库
数据库·docker·容器
于眠牧北2 小时前
ubuntu22.04安装docker以及安装过程中报错解决方法
运维·docker·容器
AI成长日志5 小时前
【agent专栏】Agent服务化与性能优化——Docker容器化、并发处理、成本控制
docker·容器·性能优化
indexsunny5 小时前
互联网大厂Java面试实战:微服务与Spring Boot在电商场景下的应用解析
java·spring boot·redis·docker·微服务·kubernetes·oauth2
江湖有缘5 小时前
从零开始:在Docker中一键部署Umbrel个人云系统
运维·docker·容器
岁岁种桃花儿5 小时前
kubenetes从入门到上天系列第十五篇:Kubernetes的持久化存储PC和PVC
云原生·容器·kubernetes
returnthem5 小时前
Docker数据卷
运维·docker·容器
mengchanmian5 小时前
docker 国内云服务器开源镜像
运维·docker·容器
糟糕喔5 小时前
k8s运维-configmap和secret(4)
运维·容器·kubernetes