Skip to content

Instantly share code, notes, and snippets.

@itskingori
Created October 17, 2019 10:08
Show Gist options
  • Save itskingori/b72a006b7242b3a1f3519d8b791c5cd7 to your computer and use it in GitHub Desktop.
Save itskingori/b72a006b7242b3a1f3519d8b791c5cd7 to your computer and use it in GitHub Desktop.
Setting up Telegraf on Kubernetes
---
apiVersion: v1
kind: ConfigMap
metadata:
name: telegraf
namespace: default
labels:
app: telegraf
data:
telegraf.conf: |-
[global_tags]
infrastructure = "kubernetes"
[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 10000
collection_jitter = "5s"
flush_interval = "10s"
flush_jitter = "5s"
precision = ""
debug = false
quiet = false
logfile = ""
hostname = "$NODE_NAME"
omit_hostname = false
[[outputs.influxdb]]
urls = ["http://$INFLUXDB_HOST:$INFLUXDB_PORT"]
database = "$INFLUXDB_DATABASE"
retention_policy = ""
timeout = "5s"
[[inputs.kubernetes]]
url = "http://$NODE_NAME:10255"
bearer_token = "$SERVICE_ACCOUNT_TOKEN_PATH"
[[inputs.cpu]]
percpu = true
totalcpu = true
fielddrop = ["time_*"]
[[inputs.disk]]
ignore_fs = ["tmpfs", "devtmpfs"]
[[inputs.diskio]]
skip_serial_number = true
[[inputs.kernel]]
[[inputs.mem]]
[[inputs.net]]
[[inputs.processes]]
[[inputs.swap]]
[[inputs.system]]
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: telegraf
namespace: default
labels:
app: telegraf
spec:
selector:
matchLabels:
app: telegraf
template:
metadata:
labels:
app: telegraf
spec:
serviceAccount: telegraf
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
- key: zappi.it/dedicated
effect: NoSchedule
operator: Exists
containers:
- name: telegraf
image: telegraf:1.8.3-alpine
env:
- name: INFLUXDB_HOST
value: "influxdb.default.svc.cluster.local"
- name: INFLUXDB_PORT
value: "8086"
- name: INFLUXDB_DATABASE
value: "telegraf"
- name: "SERVICE_ACCOUNT_TOKEN_PATH"
value: "/var/run/secrets/kubernetes.io/serviceaccount/token"
- name: "HOST_PROC"
value: "/hostfs/proc"
- name: "HOST_SYS"
value: "/hostfs/sys"
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
- name: telegraf-configuration
mountPath: /etc/telegraf/telegraf.conf
subPath: telegraf.conf
readOnly: true
- name: host-proc
mountPath: /hostfs/proc
readOnly: true
- name: host-sys
mountPath: /hostfs/sys
readOnly: true
- name: host-run-utmp
mountPath: /var/run/utmp
readOnly: true
resources:
requests:
memory: "64Mi"
cpu: "15m"
limits:
memory: "72Mi"
cpu: "30m"
volumes:
- name: telegraf-configuration
configMap:
name: telegraf
- name: host-proc
hostPath:
path: /proc
- name: host-sys
hostPath:
path: /sys
- name: host-run-utmp
hostPath:
path: /var/run/utmp
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: telegraf
namespace: default
labels:
app: telegraf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment