kubernetes 部署prometheus筆記 (一)

做個筆記,免得以後忘記

1. 以glusterfs作爲後端存儲,創建glusterfs volume.

2. 創建namespace monitoring-namespaces.yaml:

apiVersion: v1
kind: Namespace
metadata:
  name: monitoring
kubectl create -f monitoring-namespaces.yaml

3. 創建glusterfs endpoint, monitoring-endpoints.json:

{
  "kind": "Endpoints",
  "apiVersion": "v1",
  "metadata": {
    "name": "glusterfs-monitoring",
    "namespace": "monitoring"
  },
  "subsets": [
    {
      "addresses": [
        {
          "ip": "10.0.115.14"
        }
      ],
      "ports": [
        {
          "port": 24007
        }
      ]
    },
    {
      "addresses": [
        {
          "ip": "10.0.115.15"
        }
      ],
      "ports": [
        {
          "port": 24007
        }
      ]
    }
  ]
}

kubectl create -f monitoring-endpoints.json

4. 創建PV,monitoring-pv.yaml:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: gluster-monitoring-volume
  namespace: monitoring
spec:
  capacity:
    storage: 500Gi
  accessModes:
    - ReadWriteMany
  glusterfs:
    endpoints: "glusterfs-monitoring"
    path: "monitoring-volume" -- glusterfs volume名稱
    readOnly: false

5. 創建pvc, glusterfs-prometheus-pvc.yaml:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: gluster-prometheus
  namespace: monitoring
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 100Gi

可看到pvc的狀態是bound,

root@node10:~/prometheus# kubectl get pvc -n monitoring
NAME                 STATUS    VOLUME                      CAPACITY   ACCESS MODES   STORAGECLASS   AGE
gluster-prometheus   Bound     gluster-monitoring-volume   500Gi      RWX                           1h

6. 準備prometheus.yaml:

kind: Deployment
metadata:
  name: prometheus-deployment
  namespace: monitoring
spec:
  replicas: 1
  selector:
    matchLabels:
      app: prometheus-server
  template:
    metadata:
      labels:
        app: prometheus-server
    spec:
      securityContext:
        runAsUser: 0
      containers:
        - name: prometheus
          image: prom/prometheus:v2.2.0
          args:
            - "--config.file=/etc/prometheus/prometheus.yml"
            - "--storage.tsdb.path=/prometheus/"
          ports:
            - containerPort: 9090
          volumeMounts:
            - name: gluster-volume
              mountPath: /prometheus/
      volumes:
        - name: gluster-volume
          persistentVolumeClaim:
            claimName: gluster-prometheus

7. 創建service,暴露訪問端口prometheus-service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: prometheus-service
  namespace: monitoring
spec:
  selector:
    app: prometheus-server
  type: NodePort
  ports:
    - port: 8080
      targetPort: 9090
      nodePort: 30000


即可通過nodeIP:30000訪問grafana dashboard了.

注意事項:

1.err="Opening storage failed open DB in /prometheus/: open /prometheus/673409682: permission denied",報這個錯誤的解決辦法是在prometheus.yaml中加上

securityContext:
        runAsUser: 0
2. pv,pvc,pod要在同一個namespace下
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章