loki.source.kubernetes
loki.source.kubernetes
使用 Kubernetes API 从 Kubernetes 容器中尾随日志。
注意
此组件收集 Kubernetes Pod 中的日志。您不能使用此组件收集 Kubernetes 节点中的日志。
此组件相比 loki.source.file
具有以下优势:
- 它无需特权容器即可工作。
- 它无需 root 用户即可工作。
- 它无需访问 Kubernetes 节点的文件系统即可工作。
- 它不需要 DaemonSet 来收集日志,因此一个 Alloy 实例可以收集整个集群的日志。
注意
由于
loki.source.kubernetes
使用 Kubernetes API 尾随日志,因此它比loki.source.file
使用更多的网络流量和 Kubelet 的 CPU 消耗。
您可以通过为多个 loki.source.kubernetes
组件指定不同的标签来使用它们。
用法
loki.source.kubernetes "<LABEL>" {
targets = <TARGET_LIST>
forward_to = <RECEIVER_LIST>
}
参数
该组件为每个给定的 targets
启动一个新的读取器,并将日志条目分发到 forward_to
中传递的接收器列表。
您可以配合 loki.source.kubernetes
使用以下参数:
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
forward_to | list(LogsReceiver) | 发送日志条目的接收器列表。 | 是 | |
targets | list(map(string)) | 要读取的文件列表。 | 是 |
targets
中的每个目标必须包含以下标签:
__meta_kubernetes_namespace
或__pod_namespace__
用于指定要尾随日志的 Pod 的命名空间。__meta_kubernetes_pod_container_name
或__pod_container_name__
用于指定要尾随日志的 Pod 中的容器。__meta_kubernetes_pod_name
或__pod_name__
用于指定要尾随日志的 Pod 的名称。__meta_kubernetes_pod_uid
或__pod_uid__
用于指定要尾随日志的 Pod 的 UID。
默认情况下,当使用 discovery.kubernetes
输出时,所有这些标签都存在。
对于 targets
中的每个唯一目标,都会启动一个日志尾随器。如果日志流在容器永久终止之前返回,日志尾随器会以指数退避方式重新连接到 Kubernetes。
块
您可以配合 loki.source.kubernetes
使用以下块:
块 | 描述 | 必需 |
---|---|---|
client | 配置用于尾随日志的 Kubernetes 客户端。 | 否 |
client > authorization | 配置端点的通用授权。 | 否 |
client > basic_auth | 配置 basic_auth 以进行端点认证。 | 否 |
client > oauth2 | 配置 OAuth 2.0 以进行端点认证。 | 否 |
client > oauth2 > tls_config | 配置连接到端点的 TLS 设置。 | 否 |
client > tls_config | 配置连接到端点的 TLS 设置。 | 否 |
clustering | 配置组件以在 Alloy 以集群模式运行时使用。 | 否 |
The > symbol indicates deeper levels of nesting. For example, client
> basic_auth
refers to a basic_auth
block defined inside a client
block.
client
>
符号表示更深的嵌套级别。例如,client
> basic_auth
指的是在 client
块内部定义的 basic_auth
块。
The client
block configures the Kubernetes client used to tail logs from containers. If the client
block isn’t provided, the default in-cluster configuration with the service account of the running Alloy Pod is used.
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
| string | The following arguments are supported | 否 | |
支持以下参数 | string | api_server | 否 | |
api_server | URL of the Kubernetes API server. | Kubernetes API 服务器的 URL。 | 否 | |
bearer_token_file | bearer_token_file | File containing a bearer token to authenticate with. | 包含用于认证的持有者令牌的文件。 | 否 |
bearer_token | bearer_token_file | bearer_token | 包含用于认证的持有者令牌的文件。 | 否 |
secret | secret | Bearer token to authenticate with. | 否 | |
用于认证的持有者令牌。 | string | enable_http2 | 否 | |
enable_http2 | string | bool | 否 | |
bool | secret | Whether HTTP2 is supported for requests. | 否 | |
请求是否支持 HTTP2。 | bearer_token_file | true | true | 否 |
follow_redirects | string | follow_redirects | 否 |
Whether redirects returned by the server should be followed.
- 是否应遵循服务器返回的重定向。
- http_headers
- http_headers
- map(list(secret))
- map(list(secret))
Custom HTTP headers to be sent along with each request. The map key is the header name.
要随每个请求发送的自定义 HTTP 头。映射键是头名称。
kubeconfig_file
kubeconfig_file
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
Path of the | string | 用于连接到 Kubernetes 的 kubeconfig 文件路径。 | 否 | |
no_proxy | URL of the Kubernetes API server. | no_proxy | 否 | |
Comma-separated list of IP addresses, CIDR notations, and domain names to exclude from proxying. | string | 要从代理中排除的 IP 地址、CIDR 表示法和域名的逗号分隔列表。 | 否 |
proxy_connect_header
proxy_connect_header
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
Specifies headers to send to proxies during CONNECT requests. | string | 指定在 CONNECT 请求期间发送到代理的头。 | 否 | |
proxy_from_environment | URL of the Kubernetes API server. | proxy_from_environment | 否 | |
Use the proxy URL indicated by environment variables. | string | 使用环境变量指示的代理 URL。 | 否 |
false
false
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
proxy_url | string | proxy_url | 否 | |
HTTP proxy to send requests through. | string | 用于发送请求的 HTTP 代理。 | 否 | |
At most, one of the following can be provided | URL of the Kubernetes API server. | 以下参数中最多只能提供一个 | 否 | |
|
| basic_auth block | 否 | |
follow_redirects | string | follow_redirects | 否 | |
enable_http2 | string | bool | 否 | |
请求是否支持 HTTP2。 | bearer_token_file | true | true | 否 |
bool | secret | Whether HTTP2 is supported for requests. | 否 | |
|
| bearer_token_file 参数 | 否 | |
| string | bearer_token 参数 | 否 |
oauth2
block
oauth2
块
Custom HTTP headers to be sent along with each request. The map key is the header name.
要随每个请求发送的自定义 HTTP 头。映射键是头名称。
kubeconfig_file
no_proxy
can contain IPs, CIDR notations, and domain names. IP and domain names can contain port numbers. proxy_url
must be configured if no_proxy
is configured.
no_proxy
can contain IPs, CIDR notations, and domain names. IP and domain names can contain port numbers. proxy_url
must be configured if no_proxy
is configured.名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
| string | proxy_from_environment uses the environment variables HTTP_PROXY, HTTPS_PROXY, and NO_PROXY (or the lowercase versions thereof). Requests use the proxy from the environment variable matching their scheme, unless excluded by NO_PROXY. proxy_url and no_proxy must not be configured if proxy_from_environment is configured. | 否 | |
| string | proxy_connect_header should only be configured if proxy_url or proxy_from_environment are configured. | 否 | |
仅当配置了 | string | authorization | 否 | |
authorization | string | credentials_file | 否 | |
credentials_file | bearer_token_file | File containing the secret value. | 否 | |
包含 Secret 值的文件。 | string | credentials | 否 | |
credentials | URL of the Kubernetes API server. | Secret value. | 否 | |
Secret 值。 | string | type | 否 | |
type | string | Authorization type, for example, “Bearer”. | 否 |
认证类型,例如,“Bearer”。
credential
andcredentials_file
are mutually exclusive, and only one can be provided inside anauthorization
block.credential
和credentials_file
相互排斥,且在authorization
块内只能提供其中一个。- basic_auth
basic_auth
password_file
- password_file
- File containing the basic auth password.
- 包含基本认证密码的文件。
- password
clustering
名称 | 类型 | 描述 | 默认值 | 必需 |
---|---|---|---|---|
password | bearer_token_file | Basic auth password. | 是 |
基本认证密码。
username
username
Basic auth username.
基本认证用户名。
password
andpassword_file
are mutually exclusive, and only one can be provided inside abasic_auth
block.password
和password_file
相互排斥,且在basic_auth
块内只能提供其中一个。oauth2
oauth2
client_id
client_id
OAuth2 client ID.
OAuth2 客户端 ID。
client_secret_file
client_secret_file
File containing the OAuth2 client secret.
包含 OAuth2 客户端 Secret 的文件。
client_secret
client_secret
OAuth2 client secret.
OAuth2 客户端 Secret。
- endpoint_params
- endpoint_params
- map(string)
- map(string)
Optional parameters to append to the token URL.
要添加到令牌 URL 的可选参数。
scopes
scopes
discovery.kubernetes "pods" {
role = "pod"
}
loki.source.kubernetes "pods" {
targets = discovery.kubernetes.pods.targets
forward_to = [loki.write.local.receiver]
}
loki.write "local" {
endpoint {
url = sys.env("<LOKI_URL>")
}
}
兼容组件
list(string)
- list(string)
- List of scopes to authenticate with.
注意
用于认证的范围列表。