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

相关推荐
白露与泡影44 分钟前
springboot + nacos + k8s 优雅停机
spring boot·后端·kubernetes
_板栗_1 小时前
k8s 中 cpu 核数的理解
云原生·容器·kubernetes
谷新龙0011 小时前
docker compose搭建elk 8.6.2
elk·docker·容器
小李飞刀李寻欢1 小时前
使用kubeadm部署Kubernetes(k8s)集群的步骤
linux·服务器·ubuntu·kubernetes·k8s
David爱编程1 小时前
容器性能优化实战指南——防止“吃爆”服务器就靠这些招!
后端·docker·容器
藥瓿锻2 小时前
2024 CKS题库+详尽解析| 1. kube-bench 修复不安全项
运维·安全·docker·云原生·容器·kubernetes·cks
容器魔方3 小时前
科大讯飞基于Volcano实现AI基础设施突破,赢得CNCF最终用户案例研究竞赛
云原生·容器·云计算
德育处主任3 小时前
亚马逊云 Lambda 容器化部署教程
后端·容器
xixingzhe23 小时前
docker compose安装Prometheus、Grafana
docker·grafana·prometheus
程序员阿超的博客5 小时前
云原生核心技术 (10/12): K8s 终极实战:从零部署一个 Spring Boot + MySQL + Redis 应用
spring boot·云原生·kubernetes