logstash 启用logstash-input-kubernetes
时间: 2023-10-22 21:10:33 浏览: 96
kubernetes-ingress
要启用 logstash-input-kubernetes 插件,你需要安装 Logstash,并在 Logstash 配置文件中添加以下内容:
```
input {
kubernetes {
# 配置 kubernetes API 地址
api_url => "https://kubernetes.default.svc.cluster.local"
# 指定要监听的资源类型和名称,例如 Pod
resource => "pod"
# 指定要监听的命名空间
namespace => "default"
# 指定要监听的标签
labels => "app=logstash"
# 配置证书和令牌
ssl_ca => "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
ssl_certificate => "/var/run/secrets/kubernetes.io/serviceaccount/tls.crt"
ssl_key => "/var/run/secrets/kubernetes.io/serviceaccount/tls.key"
bearer_token_file => "/var/run/secrets/kubernetes.io/serviceaccount/token"
}
}
output {
# 配置输出到 Elasticsearch,也可以输出到其他目标
elasticsearch {
hosts => ["https://elasticsearch:9200"]
index => "logstash-kubernetes-%{+YYYY.MM.dd}"
# 配置证书和令牌
ssl_ca => "/usr/share/logstash/config/certs/ca.crt"
ssl_certificate_verification => true
user => "elastic"
password => "${ELASTIC_PASSWORD}"
}
}
```
这样 Logstash 就会监听 Kubernetes 中所有标记为 `app=logstash` 的 Pod,并将其日志输出到 Elasticsearch 中。你需要根据自己的实际情况来修改这个配置文件。
阅读全文