<p><strong>what do I want to do?</strong></p>
<p>I'm trying to deploy telegraf in my Kubernetes cluster so that I can use Telegraf's <strong>Prometheus</strong> input plugin to read the data (metrics) from a particular URL and write the metrics in a file using telegraf's output <strong>file</strong> plugin.</p>
<p><strong>what did I do?</strong></p>
<p>I used the telegraf <a href="https://github.com/influxdata/helm-charts/tree/master/charts/telegraf" rel="nofollow noreferrer">helm chart</a> to deploy telegraf on kubernetes.
I changed the following config changes.
<strong>The original telegraf yaml file:</strong></p>
<pre><code>config:
  agent:
    interval: &quot;10s&quot;
    round_interval: true
    metric_batch_size: 1000
    metric_buffer_limit: 10000
    collection_jitter: &quot;0s&quot;
    flush_interval: &quot;10s&quot;
    flush_jitter: &quot;0s&quot;
    precision: &quot;&quot;
    debug: false
    quiet: false
    logfile: &quot;&quot;
    hostname: &quot;$HOSTNAME&quot;
    omit_hostname: false
  processors:
    - enum:
        mapping:
          field: &quot;status&quot;
          dest: &quot;status_code&quot;
          value_mappings:
            healthy: 1
            problem: 2
            critical: 3
  outputs:
    - influxdb:
        urls:
          - &quot;http://influxdb.monitoring.svc:8086&quot;
        database: &quot;telegraf&quot;
  inputs:
    - statsd:
        service_address: &quot;:8125&quot;
        percentiles:
          - 50
          - 95
          - 99
        metric_separator: &quot;_&quot;
        allowed_pending_messages: 10000
        percentile_limit: 1000
</code></pre>
<p><strong>The changes I made to it:</strong></p>
<pre><code>config:
  outputs:
    - file:
        files:
          - &quot;stdout&quot;
          - &quot;metrics.out&quot; 
        data_format: influx  
  inputs:
    - prometheus:
        - urls:
            url: &quot;http://ipaddr:80/metrics&quot;
</code></pre>
<p>And when I applied the helm chart along with the changes I got
<strong>Error: Service &quot;telegraf&quot; is invalid: spec.ports: Required value</strong> and my deployment failed.</p>
<pre><code>chandhana@Azure:~/clouddrive/PromExpose$ helm install telegraf influxdata/telegraf -f telegraf-values.yaml
Error: Service &quot;telegraf&quot; is invalid: spec.ports: Required value
</code></pre>
<p>Please do help me if I'm making any mistakes on the changed YAML configuration since I didn't find any resource for yaml format of telegraf's input and output plugin.
Additional link for reference:
<a href="https://github.com/influxdata/telegraf/blob/master/etc/telegraf.conf" rel="nofollow noreferrer">telegraf .conf file</a></p>

<p>You forgot to enable metrics in <a href="https://github.com/influxdata/helm-charts/blob/master/charts/telegraf/values.yaml#L170-L173" rel="nofollow noreferrer">values.yaml</a>, its disabled by default.
Correct part is</p>
<pre><code>metrics:
  health:
    enabled: true
  collect_memstats: false
</code></pre>
<p>Change your <code>telegraf-values.yaml</code> to</p>
<pre><code>config:
  agent:
    interval: &quot;10s&quot;
    round_interval: true
    metric_batch_size: 1000
    metric_buffer_limit: 10000
    collection_jitter: &quot;0s&quot;
    flush_interval: &quot;10s&quot;
    flush_jitter: &quot;0s&quot;
    precision: &quot;&quot;
    debug: false
    quiet: false
    logfile: &quot;&quot;
    hostname: &quot;$HOSTNAME&quot;
    omit_hostname: false
  processors:
    - enum:
        mapping:
          field: &quot;status&quot;
          dest: &quot;status_code&quot;
          value_mappings:
            healthy: 1
            problem: 2
            critical: 3
  outputs:
    - file:
        files:
          - &quot;stdout&quot;
          - &quot;metrics.out&quot; 
        data_format: influx 
  inputs:
    - prometheus:
        - urls:
            url: &quot;http://ipaddr:80/metrics&quot;

metrics:
  health:
    enabled: true
  collect_memstats: false
</code></pre>
<p>Result:</p>
<pre><code>helm install telegraf influxdata/telegraf -f values.yaml
NAME: telegraf
LAST DEPLOYED: Fri Jun 25 10:35:05 2021
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
To open a shell session in the container running Telegraf run the following:

  kubectl exec -i -t --namespace default $(kubectl get pods --namespace default -l app.kubernetes.io/name=telegraf -o jsonpath='{.items[0].metadata.name}') /bin/sh

To view the logs for a Telegraf pod, run the following:

  kubectl logs -f --namespace default $(kubectl get pods --namespace default -l app.kubernetes.io/name=telegraf -o jsonpath='{ .items[0].metadata.name }')
</code></pre>
