Deploy on Kubernetes

Grafana Metrics Enterprise DocumentationGetting StartedDeploy / Kubernetes

Create the services for Metrics Enterprise

Those two services are the necessary for the StatefulSet for the Metrics Enterprise. Copy the following content into services.yaml:

---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: metrics-enterprise-discovery
  name: metrics-enterprise-discovery
spec:
  clusterIP: None
  ports:
  - name: metrics-enterprise-grpc
    port: 9095
    targetPort: 9095
  - name: metrics-enterprise-gossip
    port: 7946
    targetPort: 7946
  publishNotReadyAddresses: true
  selector:
    name: metrics-enterprise
---
apiVersion: v1
kind: Service
metadata:
  labels:
    name: metrics-enterprise
  name: metrics-enterprise
spec:
  ports:
  - name: metrics-enterprise-http-metrics
    port: 80
    targetPort: 80
  selector:
    name: metrics-enterprise
$ kubectl apply -f services.yaml

Create a secret with the Metrics Enterprise configuration and license

This command will take the previously created config and license file and store it as a Kubernetes secret:

$ kubectl create secret generic metrics-enterprise-config --from-file=license.jwt --from-file=metrics-enterprise.yaml --dry-run=client -o yaml | kubectl apply -f -

Bootstrap cluster (necessary at first run)

This job will run the bootstrap command until it succeeds, copy it into the local file bootstrap-job.yaml:

apiVersion: batch/v1
kind: Job
metadata:
  name: metrics-enterprise-bootstrap
spec:
  template:
    spec:
      containers:
      - name: metrics-enterprise-bootstrap
        image: grafana/metrics-enterprise:v1.0.2
        args:
        - -config.file=/etc/metrics-enterprise/metrics-enterprise.yaml
        - -bootstrap.license.path=/etc/metrics-enterprise/license.jwt
        - -log.level=warn
        - -target=bootstrap
        volumeMounts:
        - mountPath: /etc/metrics-enterprise
          name: metrics-enterprise-config
      volumes:
      - secret:
          secretName: metrics-enterprise-config
        name: metrics-enterprise-config
      restartPolicy: Never
$ # Create Kubernetes job
$ kubectl apply -f bootstrap-job.yaml

$ # Check the status of the pod and once it is 'Completed' check the logs for the bootstrap token
$ kubectl logs job.batch/metrics-enterprise-bootstrap
Token created:  Ym9vdHN0cmFwLXRva2VuOmA3PzkxOF0zfVx0MTlzMVteTTcjczNAPQ==

Deploy the metrics-enterprise statefulset

And now finally you can take this Kubernetes StatefulSet and copy it to statefulset.yaml, which will deploy the Metrics Enterprise cluster:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    name: metrics-enterprise
  name: metrics-enterprise
spec:
  replicas: 3
  selector:
    matchLabels:
      name: metrics-enterprise
  serviceName: metrics-enterprise
  template:
    metadata:
      labels:
        name: metrics-enterprise
    spec:
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchLabels:
                name: metrics-enterprise
            topologyKey: kubernetes.io/hostname
      containers:
      - args:
        - -config.file=/etc/metrics-enterprise/metrics-enterprise.yaml
        - -log.level=warn
        - -memberlist.join=metrics-enterprise-discovery:7946
        - -querier.frontend-address=metrics-enterprise-discovery:9095
        - -ingester.tokens-file-path=/data/tokens
        image: grafana/metrics-enterprise:v1.0.2
        imagePullPolicy: IfNotPresent
        name: metrics-enterprise
        ports:
        - containerPort: 80
          name: http-metrics
        - containerPort: 9095
          name: grpc
        - containerPort: 7946
          name: gossip
        readinessProbe:
          httpGet:
            path: /ready
            port: 80
          initialDelaySeconds: 15
          timeoutSeconds: 1
        resources:
          limits:
            memory: 24Gi
          requests:
            cpu: "4"
            memory: 12Gi
        volumeMounts:
        - mountPath: /data
          name: data
        - mountPath: /etc/metrics-enterprise
          name: metrics-enterprise-config
      securityContext:
        runAsUser: 0
      terminationGracePeriodSeconds: 600
      volumes:
      - secret:
          secretName: metrics-enterprise-config
        name: metrics-enterprise-config
  updateStrategy:
    type: RollingUpdate
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 100Gi
$ kubectl apply -f statefulset.yaml

Setup Metrics Enterprise in Grafana

The next step is to integrate our Metrics Enterprise backend with Grafana. This will give us a UI to interact with the Admin API.