k8s部署单实例VictoriaMetrics完整教程

2022-03-23 00:00:00 集群 专区 部署 的是 默认

上一篇文章,我们讲述了如何利用VictoriaMetrics作为Prometheus的长期存储,来实现大规模k8s集群的监控。本文主要讲述部署单实例VictoriaMetric到k8s集群中。

部署VictoriaMetrics

本文中,我们只会部署一个单实例的VictoriaMetrics。我们会在以后的文章中部署集群版本。

完整的yaml如下:

---
    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: victoriametrics
      namespace: kube-system
      annotations:
        volume.beta.kubernetes.io/aws-block-storage-additional-resource-tags: "project=victoriametrics"
    spec:
      accessModes:
        - ReadWriteOnce
      resources:
        requests:
          storage: 100Gi
---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      labels:
        app: victoriametrics
      name: victoriametrics
      namespace: kube-system
    spec:
      serviceName: pvictoriametrics
      selector:
        matchLabels:
          app: victoriametrics
      replicas: 1
      template:
        metadata:
          labels:
            app: victoriametrics
        spec:
          containers:    
          - args:
            - --storageDataPath=/storage
            - --httpListenAddr=:8428
            - --retentionPeriod=1
            image: victoriametrics/victoria-metrics
            imagePullPolicy: IfNotPresent
            name: victoriametrics
            ports:
            - containerPort: 8428
              protocol: TCP
            readinessProbe:
              httpGet:
                path: /health
                port: 8428
              initialDelaySeconds: 30
              timeoutSeconds: 30
            livenessProbe:
              httpGet:
                path: /health
                port: 8428
              initialDelaySeconds: 120
              timeoutSeconds: 30
            resources:
              limits:
                cpu: 2000m
                memory: 2000Mi
              requests:
                cpu: 2000m
                memory: 2000Mi
            volumeMounts:
            - mountPath: /storage
              name: storage-volume
          restartPolicy: Always
          priorityClassName: system-cluster-critical
          volumes:
          - name: storage-volume
            persistentVolumeClaim:
              claimName: victoriametrics
---
  apiVersion: v1
  kind: Service
  metadata:
    labels:
      app: victoriametrics
    name: victoriametrics
    namespace: kube-system
  spec:
    ports:
    - name: http
      port: 8428
      protocol: TCP
      targetPort: 8428
    selector:
      app: victoriametrics
    type: ClusterIP

相关文章