文档文档

Kubernetes 输入插件

此插件通过 Kubelet API 收集关于 Kubernetes 实例中运行的 Pod 和容器的指标。

此插件必须作为 daemonset 的一部分在 Kubernetes 安装中运行。Telegraf 必须在集群中的每个节点上运行。

您应该配置此插件以连接到本地运行的 kubelet。

此插件会产生高基数数据,如果不加以控制,将对数据库造成高负载。请务必过滤生成的指标或配置您的数据库以避免基数问题!

发布于: Telegraf v1.1.0 标签: containers 操作系统支持: all

全局配置选项

插件支持其他全局和插件配置设置,用于修改指标、标签和字段,创建别名以及配置插件顺序等任务。更多详情请参阅 CONFIGURATION.md

配置

# Read metrics from the kubernetes kubelet api
[[inputs.kubernetes]]
  ## URL for the kubelet, if empty read metrics from all nodes in the cluster
  url = "http://127.0.0.1:10255"

  ## Use bearer token for authorization. ('bearer_token' takes priority)
  ## If both of these are empty, we'll use the default serviceaccount:
  ## at: /var/run/secrets/kubernetes.io/serviceaccount/token
  ##
  ## To re-read the token at each interval, please use a file with the
  ## bearer_token option. If given a string, Telegraf will always use that
  ## token.
  # bearer_token = "/var/run/secrets/kubernetes.io/serviceaccount/token"
  ## OR
  # bearer_token_string = "abc_123"

  ## Kubernetes Node Metric Name
  ## The default Kubernetes node metric name (kubernetes_node) is the same
  ## for the kubernetes and kube_inventory plugins. To avoid conflicts, set this
  ## option to a different value.
  # node_metric_name = "kubernetes_node"

  ## Pod labels to be added as tags.  An empty array for both include and
  ## exclude will include all labels.
  # label_include = []
  # label_exclude = ["*"]

  ## Set response_timeout (default 5 seconds)
  # response_timeout = "5s"

  ## Optional TLS Config
  # tls_ca = /path/to/cafile
  # tls_cert = /path/to/certfile
  # tls_key = /path/to/keyfile
  ## Use TLS but skip chain & host verification
  # insecure_skip_verify = false

宿主机 IP

要查找您正在运行的宿主机的 IP 地址,您可以发出类似以下的命令

curl -s $API_URL/api/v1/namespaces/$POD_NAMESPACE/pods/$HOSTNAME \
  --header "Authorization: Bearer $TOKEN" \
  --insecure | jq -r '.status.hostIP'

此示例使用 downward API 来传递 $POD_NAMESPACE,而 $HOSTNAME 是由 kubernetes API 设置的 pod 的主机名。有关生成 bearer token 以探索 Kubernetes API 的完整示例,请参阅 Kubernetes 文档

Daemon-set

有关将 Telegraf 作为 daemon-set 运行的建议,请参阅 Monitoring Kubernetes Architecture 博客文章 或查看以下 Helm charts

Metrics

  • kubernetes_node

    • 标签 (tags)
      • node_name
    • 字段 (fields)
      • cpu_usage_nanocores
      • cpu_usage_core_nanoseconds
      • memory_available_bytes
      • memory_usage_bytes
      • memory_working_set_bytes
      • memory_rss_bytes
      • memory_page_faults
      • memory_major_page_faults
      • network_rx_bytes
      • network_rx_errors
      • network_tx_bytes
      • network_tx_errors
      • fs_available_bytes
      • fs_capacity_bytes
      • fs_used_bytes
      • runtime_image_fs_available_bytes
      • runtime_image_fs_capacity_bytes
      • runtime_image_fs_used_bytes
  • kubernetes_pod_container

    • 标签 (tags)
      • container_name
      • namespace
      • node_name
      • pod_name
    • 字段 (fields)
      • cpu_usage_nanocores
      • cpu_usage_core_nanoseconds
      • memory_usage_bytes
      • memory_working_set_bytes
      • memory_rss_bytes
      • memory_page_faults
      • memory_major_page_faults
      • rootfs_available_bytes
      • rootfs_capacity_bytes
      • rootfs_used_bytes
      • logsfs_available_bytes
      • logsfs_capacity_bytes
      • logsfs_used_bytes
  • kubernetes_pod_volume

    • 标签 (tags)
      • volume_name
      • namespace
      • node_name
      • pod_name
    • 字段 (fields)
      • available_bytes
      • capacity_bytes
      • used_bytes
  • kubernetes_pod_network

    • 标签 (tags)
      • namespace
      • node_name
      • pod_name
    • 字段 (fields)
      • rx_bytes
      • rx_errors
      • tx_bytes
      • tx_errors

示例输出

kubernetes_node
kubernetes_pod_container,container_name=deis-controller,namespace=deis,node_name=ip-10-0-0-0.ec2.internal,pod_name=deis-controller-3058870187-xazsr cpu_usage_core_nanoseconds=2432835i,cpu_usage_nanocores=0i,logsfs_available_bytes=121128271872i,logsfs_capacity_bytes=153567944704i,logsfs_used_bytes=20787200i,memory_major_page_faults=0i,memory_page_faults=175i,memory_rss_bytes=0i,memory_usage_bytes=0i,memory_working_set_bytes=0i,rootfs_available_bytes=121128271872i,rootfs_capacity_bytes=153567944704i,rootfs_used_bytes=1110016i 1476477530000000000
kubernetes_pod_network,namespace=deis,node_name=ip-10-0-0-0.ec2.internal,pod_name=deis-controller-3058870187-xazsr rx_bytes=120671099i,rx_errors=0i,tx_bytes=102451983i,tx_errors=0i 1476477530000000000
kubernetes_pod_volume,volume_name=default-token-f7wts,namespace=default,node_name=ip-172-17-0-1.internal,pod_name=storage-7 available_bytes=8415240192i,capacity_bytes=8415252480i,used_bytes=12288i 1546910783000000000
kubernetes_system_container

此页面是否有帮助?

感谢您的反馈!


InfluxDB 3.8 新特性

InfluxDB 3.8 和 InfluxDB 3 Explorer 1.6 的主要增强功能。

查看博客文章

InfluxDB 3.8 现已适用于 Core 和 Enterprise 版本,同时发布了 InfluxDB 3 Explorer UI 的 1.6 版本。本次发布着重于操作成熟度,以及如何更轻松地部署、管理和可靠地运行 InfluxDB。

更多信息,请查看

InfluxDB Docker 的 latest 标签将指向 InfluxDB 3 Core

在 **2026 年 2 月 3 日**,InfluxDB Docker 镜像的 latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。

如果使用 Docker 来安装和运行 InfluxDB,latest 标签将指向 InfluxDB 3 Core。为避免意外升级,请在您的 Docker 部署中使用特定的版本标签。例如,如果使用 Docker 运行 InfluxDB v2,请将 latest 版本标签替换为 Docker pull 命令中的特定版本标签 — 例如

docker pull influxdb:2