有没有办法从容器到底层 k8s 节点进行 syslog?
Is there a way to syslog from container to underlying k8s node?
我想将系统日志从容器发送到主机节点 -
目标节点上运行的 fluentd (@127.0.0.1:5140) - https://docs.fluentd.org/input/syslog
例如,从 hello-server 到节点(托管所有这些命名空间)的系统日志
我想将 hello-server 容器的系统日志输出到节点 (@127.0.0.1:5140) 上的 fluentd 运行。
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default hello-server-7d8589854c-r4xfr 1/1 Running 0 21h
kube-system event-exporter-v0.2.4-5f7d5d7dd4-lgzg5 2/2 Running 0 6d6h
kube-system fluentd-gcp-scaler-7b895cbc89-bnb4z 1/1 Running 0 6d6h
kube-system fluentd-gcp-v3.2.0-4qcbs 2/2 Running 0 6d6h
kube-system fluentd-gcp-v3.2.0-jxnbn 2/2 Running 0 6d6h
kube-system fluentd-gcp-v3.2.0-k58x6 2/2 Running 0 6d6h
kube-system heapster-v1.6.0-beta.1-7778b45899-t8rz9 3/3 Running 0 6d6h
kube-system kube-dns-autoscaler-76fcd5f658-7hkgn 1/1 Running 0 6d6h
kube-system kube-dns-b46cc9485-279ws 4/4 Running 0 6d6h
kube-system kube-dns-b46cc9485-fbrm2 4/4 Running 0 6d6h
kube-system kube-proxy-gke-test-default-pool-040c0485-7zzj 1/1 Running 0 6d6h
kube-system kube-proxy-gke-test-default-pool-040c0485-ln02 1/1 Running 0 6d6h
kube-system kube-proxy-gke-test-default-pool-040c0485-w6kq 1/1 Running 0 6d6h
kube-system l7-default-backend-6f8697844f-bxn4z 1/1 Running 0 6d6h
kube-system metrics-server-v0.3.1-5b4d6d8d98-k7tz9 2/2 Running 0 6d6h
kube-system prometheus-to-sd-2g7jc 1/1 Running 0 6d6h
kube-system prometheus-to-sd-dck2n 1/1 Running 0 6d6h
kube-system prometheus-to-sd-hsc69 1/1 Running 0 6d6h
出于某种原因,k8s 不允许我们使用内置的系统日志驱动程序 docker run --log-driver syslog
。
此外,k8s 不允许我使用 --network="host"
连接底层主机
有没有人试过类似的东西?也许远程 syslog 比尝试在每个节点上使用底层 syslog 运行 更容易?
你实际看到的是 Stackdriver Logging Agent. According to the documentation at https://kubernetes.io/docs/tasks/debug-application-cluster/logging-stackdriver/#prerequisites:
If you’re using GKE and Stackdriver Logging is enabled in your cluster, you cannot change its configuration, because it’s managed and supported by GKE. However, you can disable the default integration and deploy your own.
然后文档给出了一个使用自定义 ConfigMap 来运行您自己的 fluentd DaemonSet 的示例。您需要 运行 自己的流利程度,以便您可以根据 https://docs.fluentd.org/input/syslog.
配置系统日志输入
然后,由于 fluentd 运行ning 作为一个 DaemonSet,您将配置一个服务以将其公开给其他 pods 并允许然后连接到它。如果您 运行 从 https://github.com/fluent/fluentd-kubernetes-daemonset 连接官方上游 DaemonSet,那么服务可能如下所示:
apiVersion: v1
kind: Service
namespace: kube-system
metadata:
name: fluentd
spec:
selector:
k8s-app: fluentd-logging
ports:
- protocol: UDP
port: 5140
targetPort: 5140
然后您的应用程序可以登录到 fluentd.kube-system:5140
(请参阅在 https://kubernetes.io/docs/concepts/services-networking/service/#dns 处使用 DNS)。
我想将系统日志从容器发送到主机节点 -
目标节点上运行的 fluentd (@127.0.0.1:5140) - https://docs.fluentd.org/input/syslog
例如,从 hello-server 到节点(托管所有这些命名空间)的系统日志
我想将 hello-server 容器的系统日志输出到节点 (@127.0.0.1:5140) 上的 fluentd 运行。
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
default hello-server-7d8589854c-r4xfr 1/1 Running 0 21h
kube-system event-exporter-v0.2.4-5f7d5d7dd4-lgzg5 2/2 Running 0 6d6h
kube-system fluentd-gcp-scaler-7b895cbc89-bnb4z 1/1 Running 0 6d6h
kube-system fluentd-gcp-v3.2.0-4qcbs 2/2 Running 0 6d6h
kube-system fluentd-gcp-v3.2.0-jxnbn 2/2 Running 0 6d6h
kube-system fluentd-gcp-v3.2.0-k58x6 2/2 Running 0 6d6h
kube-system heapster-v1.6.0-beta.1-7778b45899-t8rz9 3/3 Running 0 6d6h
kube-system kube-dns-autoscaler-76fcd5f658-7hkgn 1/1 Running 0 6d6h
kube-system kube-dns-b46cc9485-279ws 4/4 Running 0 6d6h
kube-system kube-dns-b46cc9485-fbrm2 4/4 Running 0 6d6h
kube-system kube-proxy-gke-test-default-pool-040c0485-7zzj 1/1 Running 0 6d6h
kube-system kube-proxy-gke-test-default-pool-040c0485-ln02 1/1 Running 0 6d6h
kube-system kube-proxy-gke-test-default-pool-040c0485-w6kq 1/1 Running 0 6d6h
kube-system l7-default-backend-6f8697844f-bxn4z 1/1 Running 0 6d6h
kube-system metrics-server-v0.3.1-5b4d6d8d98-k7tz9 2/2 Running 0 6d6h
kube-system prometheus-to-sd-2g7jc 1/1 Running 0 6d6h
kube-system prometheus-to-sd-dck2n 1/1 Running 0 6d6h
kube-system prometheus-to-sd-hsc69 1/1 Running 0 6d6h
出于某种原因,k8s 不允许我们使用内置的系统日志驱动程序 docker run --log-driver syslog
。
此外,k8s 不允许我使用 --network="host"
连接底层主机有没有人试过类似的东西?也许远程 syslog 比尝试在每个节点上使用底层 syslog 运行 更容易?
你实际看到的是 Stackdriver Logging Agent. According to the documentation at https://kubernetes.io/docs/tasks/debug-application-cluster/logging-stackdriver/#prerequisites:
If you’re using GKE and Stackdriver Logging is enabled in your cluster, you cannot change its configuration, because it’s managed and supported by GKE. However, you can disable the default integration and deploy your own.
然后文档给出了一个使用自定义 ConfigMap 来运行您自己的 fluentd DaemonSet 的示例。您需要 运行 自己的流利程度,以便您可以根据 https://docs.fluentd.org/input/syslog.
配置系统日志输入然后,由于 fluentd 运行ning 作为一个 DaemonSet,您将配置一个服务以将其公开给其他 pods 并允许然后连接到它。如果您 运行 从 https://github.com/fluent/fluentd-kubernetes-daemonset 连接官方上游 DaemonSet,那么服务可能如下所示:
apiVersion: v1
kind: Service
namespace: kube-system
metadata:
name: fluentd
spec:
selector:
k8s-app: fluentd-logging
ports:
- protocol: UDP
port: 5140
targetPort: 5140
然后您的应用程序可以登录到 fluentd.kube-system:5140
(请参阅在 https://kubernetes.io/docs/concepts/services-networking/service/#dns 处使用 DNS)。