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
相关推荐
Nontee8 小时前
K3s vs K8s:差的不是功能,是交付方式
云原生·容器·kubernetes
做运维的阿瑞8 小时前
Docker常见故障全方位排查指南
运维·docker·云原生·容器
木子欢儿9 小时前
Zabbix 7.4 Alpine 版 Docker Compose 部署
android·运维·docker·容器·zabbix
朱包林9 小时前
iTerm2终端配置指南
linux·javascript·python·云原生·容器·kubernetes·云计算
打工仔折腾 AI9 小时前
极空间用 Docker 部署 Photopea:网页版 PS 的私有化实践
运维·后端·python·docker·容器·langchain·ai agent 实战
工具人555510 小时前
Docker 最新超详细版教程
运维·docker·容器
小陈运维12 小时前
微WEB文件服务 Docker 部署指南
前端·docker·容器
做运维的阿瑞12 小时前
利用GitHub配置镜像加速,解决 Docker镜像拉取问题
运维·docker·容器·github
小陈运维13 小时前
使用kubeadm初始化IPV4/IPV6集群
linux·docker·云原生·容器·kubernetes