K8S 部署promethus+grafana 监控vmware ESXI —— 筑梦之路

直接上yaml文件内容

# cat vmware-cm.yaml

apiVersion: v1
kind: ConfigMap
metadata:
  namespace: vcenter
  name: vmware-exporter-config
data:
  VSPHERE_USER: "[email protected]"
  VSPHERE_HOST: "192.168.20.150"
  VSPHERE_PASSWORD: "admin"
  VSPHERE_IGNORE_SSL: "True"
  VSPHERE_COLLECT_HOSTS: "True"
  VSPHERE_COLLECT_DATASTORES: "True"
  VSPHERE_COLLECT_VMS: "True"

# cat vmware-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: vmware-exporter
  namespace: vcenter
spec:
  selector:
    matchLabels:
      app: vmware-exporter
  template:
    metadata:
      labels:
        app: vmware-exporter
        release: vmware-exporter
      annotations:
        prometheus.io/path: "/metrics"
        prometheus.io/port: "9272"
        prometheus.io/scrape: "true"
    spec:
      containers:
      - name: vmware-exporter
        image: vmware_exporter:v0.18.3
        imagePullPolicy: Always
        ports:
        - containerPort: 9272
          name: http
        envFrom:
        - configMapRef:
            name: vmware-exporter-config

# cat vmware-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: vmware-exporter-svc
  namespace: vcenter
spec:
  selector:
    app: vmware-exporter
  type: NodePort
  ports:
    - protocol: TCP
      port: 9272
      targetPort: 9272
      nodePort: 19272
# cat promethus-pvc.yaml

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: prometheus-pv-data
spec:
  capacity:
    storage: 100G
  volumeMode: Filesystem
  storageClassName: prometheus-class
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  nfs:
    path: /data/prometheus/data
    server: 192.168.20.100
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: prometheus-pvc-data
  namespace: vcenter
spec:
  storageClassName: prometheus-class
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
     requests:
       storage: 100G

# cat promethus-cm.yaml

kind: ConfigMap
apiVersion: v1
metadata:
  labels:
    app: prometheus
  name: prometheus-config
  namespace: vcenter
data:
  prometheus.yml: |
    global:
      scrape_interval: 1m
      scrape_timeout: 10s
      evaluation_interval: 1m
    scrape_configs:
    - job_name: 'vmware_vcenter'
      metrics_path: '/metrics'
      static_configs:
        - targets:
          - 'vcenter.scriptjc.com'
      relabel_configs:
        - source_labels: [__address__]
          target_label: __param_target
        - source_labels: [__param_target]
          target_label: instance
        - target_label: __address__
          replacement: 192.168.20.150:19272

# cat promethus-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: prometheus-svc
  namespace: vcenter
  labels:
    app: prometheus
spec:
  ports:
    - port: 9090
      targetPort: 9090
      protocol: TCP
      nodePort: 19090
  selector:
    app: prometheus
  type: NodePort

# cat promethus-sa.yaml

apiVersion: v1
kind: ServiceAccount
metadata:
  name: prometheus
  namespace: vcenter
  labels:
    app: prometheus

# cat promethus-cr.yaml

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: prometheus
rules:
  - apiGroups: [""] # "" indicates the core API group
    resources:
      - nodes
      - nodes/proxy
      - services
      - endpoints
      - pods
    verbs:
      - get
      - watch
      - list
  - apiGroups:
      - extensions
    resources:
      - ingresses
    verbs:
      - get
      - watch
      - list
  - nonResourceURLs: ["/metrics"]
    verbs:
      - get

# cat promethus-crb.yaml

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: prometheus
subjects:
  - kind: ServiceAccount
    name: prometheus
    namespace: vcenter
roleRef:
  kind: ClusterRole
  name: prometheus
  apiGroup: rbac.authorization.k8s.io
grafana 部署

# cat  grafana-svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: vcenter
  labels:
    app: grafana
    component: core
spec:
  type: NodePort
  ports:
    - port: 3000
  selector:
    app: grafana
    component: core

# cat grafana-deploy.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana-core
  namespace: vcenter
  labels:
    app: grafana
    component: core
spec:
  replicas: 1
  selector:
    matchLabels:
      app: grafana
  template:
    metadata:
      labels:
        app: grafana
        component: core
    spec:
      containers:
      - image: grafana/grafana:4.2.0
        name: grafana-core
        imagePullPolicy: IfNotPresent
        # env:
        resources:
          # keep request = limit to keep this container in guaranteed class
          limits:
            cpu: 100m
            memory: 100Mi
          requests:
            cpu: 100m
            memory: 100Mi
        env:
          # The following env variables set up basic auth twith the default admin user and admin password.
          - name: GF_AUTH_BASIC_ENABLED
            value: "true"
          - name: GF_AUTH_ANONYMOUS_ENABLED
            value: "false"
          # - name: GF_AUTH_ANONYMOUS_ORG_ROLE
          #   value: Admin
          # does not really work, because of template variables in exported dashboards:
          # - name: GF_DASHBOARDS_JSON_ENABLED
          #   value: "true"
        readinessProbe:
          httpGet:
            path: /login
            port: 3000
          # initialDelaySeconds: 30
          # timeoutSeconds: 1
        volumeMounts:
        - name: grafana-persistent-storage
          mountPath: /var
      volumes:
      - name: grafana-persistent-storage
        emptyDir: {}

# cat grafana-ingrss.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
   name: grafana
   namespace: vcenter
spec:
   rules:
   - host: k8s.grafana
     http:
       paths:
       - path: /
         backend:
          serviceName: grafana
          servicePort: 3000

grafana 模板ID:11243

参考资料:

prometheus监控exsi vcenter,监控kvm libvirt-脚本小站

猜你喜欢

转载自blog.csdn.net/qq_34777982/article/details/125411577