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
相关推荐
Dontla1 小时前
Docker run --add-host参数解析(在容器启动时向/etc/hosts文件中添加自定义的主机名与IP映射)(适用于临时调试或测试)
tcp/ip·docker·容器
西西小飞龙1 小时前
Docker和K8S中pod、services、container的介绍和关系
docker·容器·kubernetes
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
飞火流星0202713 小时前
docker安装etcd:docker离线安装etcd、docker在线安装etcd、etcd镜像下载、etcd配置详解、etcd常用命令、安装常见问题总结
docker·容器·etcd
you来有去14 小时前
记录一下在k3s快速创建gitlab
java·kubernetes·gitlab
magrich14 小时前
Docker usage on ubuntu
ubuntu·docker·容器
格桑阿sir15 小时前
Kubernetes控制平面组件:API Server Node 授权机制 详解
kubernetes·kubelet·authorization·apiserver·node授权机制·noderestriction·资源拦截
程序员没睡醒19 小时前
【小白友好】Docker 入门详解:从零开始学“应用集装箱”
docker·容器·eureka