To deploy the Telegraf Kubernetes Plugin Setup for Windows And Linux containers using the YAML file, you have to perform the following actions.

Procedure

  • Deploy the following YAML files on your Kubernetes cluster:
    Telegraf for Linux
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: vrops-mp-user
      namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: vrops-mp-user
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: cluster-admin
    subjects:
      - kind: ServiceAccount
        name: vrops-mp-user
        namespace: kube-system
    ---
    apiVersion: apps/v1 # apps/v1beta2 in Kube 1.8, extensions/v1beta1 in Kube < 1.8
    kind: DaemonSet
    metadata:
      name: vrops-telegraf-k8s
      namespace: kube-system
      labels:
        app: vrops-telegraf-k8s
      annotations:
        seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
    spec:
      selector:
        matchLabels:
          app: vrops-telegraf-k8s
      template:
        metadata:
          labels:
            app: vrops-telegraf-k8s
            version: v1.0
        spec:
          serviceAccountName: vrops-mp-user
          tolerations:
          - key: node-role.kubernetes.io/master
            effect: NoSchedule
          containers:
          - name: vrops-telegraf-k8s-container
            image: telegraf:1.16.0
            resources:
              requests:
                memory: 250Mi
                cpu: 250m
              limits:
                cpu: 400m
            volumeMounts:
            - name: telegraf-d
              mountPath: /etc/telegraf
            ports:
              - name: http
                containerPort: 9273 #Port exposed
                hostPort : 31196 #Host's port - Port to expose your telegraf DaemonS Set on each node
                protocol: TCP
            env:
            - name: METRIC_SOURCE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: NODE_HOSTNAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: NODE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
          automountServiceAccountToken: true
          terminationGracePeriodSeconds: 30
          volumes:
          - name: telegraf-d
            projected:
              sources:
              - configMap:
                  name: vrops-telegraf-k8s-config
    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: vrops-telegraf-k8s-config
      namespace: kube-system
    data:
      telegraf.conf: |
        # Configuration for telegraf agent
        [global_tags]
        namespace = "$NAMESPACE"
        [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
        ##################################################################
        #                            OUTPUT PLUGINS                      #
        ##################################################################
        # Configuration for the Prometheus client to spawn
        [[outputs.prometheus_client]]
        ## Address to listen on
        listen = ":9273"
        ##################################################################
        #                            INPUT PLUGINS                       #
        ##################################################################
        [[inputs.kubernetes]]
         ## URL for the kubelet
        url = "https://$NODE_IP:10250"
        insecure_skip_verify = true
    Telegraf for Windows
    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: vrops-mp-user
      namespace: kube-system
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: vrops-mp-user
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: cluster-admin
    subjects:
      - kind: ServiceAccount
        name: vrops-mp-user
        namespace: kube-system
    ---
    apiVersion: apps/v1 # apps/v1beta2 in Kube 1.8, extensions/v1beta1 in Kube < 1.8
    kind: DaemonSet
    metadata:
      name: vrops-telegraf-k8s-win
      namespace: kube-system
      labels:
        app: vrops-telegraf-k8s-win
      annotations:
        seccomp.security.alpha.kubernetes.io/pod: 'docker/default'
    spec:
      selector:
        matchLabels:
          app: vrops-telegraf-k8s-win
      template:
        metadata:
          labels:
            app: vrops-telegraf-k8s-win
            version: v1.0
        spec:
          serviceAccountName: vrops-mp-user
          containers:
          - name: vrops-telegraf-k8s-container-win
            image: projects.registry.vmware.com/vrops_metric_exporters/telegraf-win@sha256:be76abe7efb53d4af999302af08e014a80651ad06491fabd38f5ed927124bf4a
            resources:
              requests:
                memory: 250Mi
                cpu: 250m
              limits:
                cpu: 400m
            volumeMounts:
            - name: telegraf-d
              mountPath: C:\Program Files\Telegraf\
            ports:
              - name: http
                containerPort: 9273 #Port exposed
                hostPort : 31197 #Host's port - Port to expose your telegraf DaemonSet on each node
                protocol: TCP
            env:
            - name: METRIC_SOURCE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: POD_NAME
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            - name: NODE_HOSTNAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: NODE_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.hostIP
          automountServiceAccountToken: true
          terminationGracePeriodSeconds: 30
          volumes:
          - name: telegraf-d
            projected:
              sources:
              - configMap:
                  name: vrops-telegraf-k8s-config-win
          nodeSelector:
            kubernetes.io/os: windows
          tolerations:
          - key: "windows"
            operator: "Equal"
            value: "2019"
            effect: "NoSchedule"
    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: vrops-telegraf-k8s-config-win
      namespace: kube-system
    data:
      telegraf.conf: |
        # Configuration for telegraf agent
        [global_tags]
        namespace = "$NAMESPACE"
        [agent]
        interval = "60s"
        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
        ##################################################################
        #                            OUTPUT PLUGINS                      #
        ##################################################################
        # Configuration for the Prometheus client to spawn
        [[outputs.prometheus_client]]
        ## Address to listen on
        listen = ":9273"
        ##################################################################
        #                            INPUT PLUGINS                       #
        ##################################################################
        [[inputs.kubernetes]]
         ## URL for the kubelet
        url = "https://$NODE_IP:10250"
        bearer_token = "C:/var/run/secrets/kubernetes.io/serviceaccount/token"
        insecure_skip_verify = true
    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: vrops-telegraf-k8s-win
      namespace: kube-system
      labels:
        app: vrops-telegraf-k8s-win
    spec:
      externalTrafficPolicy: Local
      ports:
        - port: 9273
          targetPort: 9273
          nodePort: 31197
      selector:
        app: vrops-telegraf-k8s-win
      type: NodePort
    ---