k8s部署prometheus

部署pvc

修改nfs-deployment.yaml文件中的信息,然后应用YAML文件

bash 复制代码
cat > /opt/k8s/prometheus/prometheus-pvc.yaml <<EOF
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prometheus-data-pvc
spec:
  accessModes:
    - ReadWriteMany
  storageClassName: "nfs-storage"
  resources:
    requests:
      storage: 5Gi
EOF
bash 复制代码
kubectl apply -f prometheus-pvc.yaml 
kubectl get pvc

部署ConfigMap

上传文件prometheus.yml 、alert.mysql.rules.yml 、alert.node.rules.yml到/opt/k8s/prometheus/file/下

bash 复制代码
kubectl create configmap prometheus-config \
  --from-file=prometheus.yml=/opt/k8s/prometheus/file/prometheus.yml \
  --from-file=alert.mysql.rules.yml=/opt/k8s/prometheus/file/alert.mysql.rules.yml \
  --from-file=alert.node.rules.yml=/opt/k8s/prometheus/file/alert.node.rules.yml

如需修改可使用kubectl edit 或者以下方式

删除现有的ConfigMap
kubectl delete configmap prometheus-config
使用新的文件重新创建ConfigMap
kubectl create configmap prometheus-config

--from-file=prometheus.yml=/path/to/new/prometheus.yml

--from-file=alert.mysql.rules.yml=/path/to/new/alert.mysql.rules.yml

--from-file=alert.node.rules.yml=/path/to/new/alert.node.rules.yml

部署Deployment

修改prometheus-Deployment.yaml文件中的信息,然后应用YAML文件

bash 复制代码
cat > /opt/k8s/prometheus/prometheus-Deployment.yaml <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prometheus-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus
  template:
    metadata:
      labels:
        app: prometheus
    spec:
      containers:
      - name: prometheus
        image: prom/prometheus
        ports:
        - containerPort: 9090
        volumeMounts:
        - name: prometheus-config-volume
          mountPath: /etc/prometheus
          readOnly: true
        - name: prometheus-data
          mountPath: /prometheus
      volumes:
      - name: prometheus-config-volume
        configMap:
          name: prometheus-config
      - name: prometheus-data
        persistentVolumeClaim:
          claimName: prometheus-data-pvc
EOF
bash 复制代码
kubectl apply -f prometheus-Deployment.yaml 
kubectl get Deployment

部署Service

修改prometheus-Service.yaml文件中的信息,然后应用YAML文件

bash 复制代码
cat > /opt/k8s/prometheus/prometheus-Service.yaml <<EOF
apiVersion: v1
kind: Service
metadata:
  name: prometheus-service
spec:
  type: NodePort
  ports:
  - port: 9090
    targetPort: 9090
    nodePort: 30090
  selector:
    app: prometheus
EOF
bash 复制代码
kubectl apply -f prometheus-Service.yaml 
kubectl get Service
相关推荐
心理之旅8 小时前
高校文献检索系统
运维·服务器·容器
大佐不会说日语~9 小时前
使用Docker Compose 部署时网络冲突问题排查与解决
运维·网络·spring boot·docker·容器
曾几何时`12 小时前
Docker容器化部署编译运行模块
运维·docker·容器
直饮水观察哨14 小时前
商用净水器亲测对比,哪个更专业?
容器
塔克拉玛攻城狮14 小时前
最新!银河麒麟v11 kubeadm部署k8s v1.35.0高可用集群
kubernetes·银河麒麟
Suchadar15 小时前
Docker基础命令(二)——数据卷管理端口映射与容器互联
运维·docker·容器
firstacui15 小时前
Docker容器网络管理与容器数据卷管理
运维·docker·容器
王锋(oxwangfeng)15 小时前
Apache Flink 在 Kubernetes 上的高效部署与优化实践
flink·kubernetes·apache
努力搬砖的咸鱼17 小时前
部署你的第一个应用到 K8s
微服务·云原生·容器·kubernetes
故乡de云17 小时前
2026年谷歌云价格走势深度分析:企业如何在高成本时代保持竞争力?
运维·kubernetes·云计算