To deploy Redis Telegraf Input Plugin using the YAML file, you have to perform the following actions.

Procedure

  • Deploy the following yaml in kubernetes cluster.
    Note: Ensure that omit_hostname is set to true under agent and podname label is set under global_tags.
    apiVersion: v1
    kind: ConfigMap
    metadata:
     name: telegraf-config
    data:
      telegraf.conf: |+
        [global_tags]
        podname = "$POD_NAME"
        [agent]
        interval = "10s"
        round_interval = true
        metric_batch_size = 1000
        metric_buffer_limit = 10000
        collection_jitter = "0s"
        flush_interval = "10s"
        flush_jitter = "0s"
        precision = ""
        quiet = false
        hostname = ""
        omit_hostname = true
        [[outputs.prometheus_client]]
          listen = ":9273"
        [[inputs.redis]]
          servers = ["tcp://localhost:6379"]
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: redis
    spec:
      replicas: 1
      selector:
        matchLabels:
          app: redis
      template:
        metadata:
          labels:
            app: redis
          annotations:
            telegraf.influxdata.com/inputs: |+
              [[inputs.redis]]
                servers = ["tcp://localhost:6379"]
            telegraf.influxdata.com/class: app
        spec:
          containers:
          - name: redis
            image: redis:4
            resources:
              requests:
                cpu: 100m
                memory: 100Mi
            ports:
            - containerPort: 6379
          - name: telegraf
            image: telegraf:1.16.0
            env:
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            volumeMounts:
              - name: telegraf-config-volume
                mountPath: /etc/telegraf/telegraf.conf
                subPath: telegraf.conf
                readOnly: true
          volumes:
            - name: telegraf-config-volume
              configMap:
                name: telegraf-config
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: redis
    spec:
      type: NodePort
      selector:
        app: redis
      ports:
      - name: prom
        protocol: TCP
        port: 9273
        targetPort: 9273
        nodePort: 30008