# 集中式日志记录(Kubernetes 集群之前)
apiVersion: logging.k8s.io/v1beta1
kind: ClusterLogging
metadata:
name: cluster-logging-intake
spec:
fluentd:
baseImage: k8s.gcr.io/fluentd-elasticsearch
resources:
limits:
memory: 200Mi
cpu: 100m
requests:
memory: 100Mi
cpu: 50m
logfile:
storage: 1Gi
# 分布式日志记录(Kubernetes 集群内)
apiVersion: logging.k8s.io/v1beta1
kind: ClusterLogging
metadata:
name: cluster-logging-distributed
spec:
logStore: elasticsearch
elasticsearch:
node:
resources:
limits:
memory: 1Gi
cpu: 500m
requests:
memory: 1Gi
cpu: 500m
config:
cluster.name: ${ELASTICSEARCH_CLUSTER_NAME}
node.name: "${POD_NAME}.${POD_NAMESPACE}.svc"
network.host: 0.0.0.0
discovery.seed_hosts: ${ELASTICSEARCH_SERVICE_ENDPOINT}
# 分布式日志记录(Kubernetes 集群外)
apiVersion: logging.k8s.io/v1beta1
kind: ClusterLogging
metadata:
name: cluster-logging-distributed-external
spec:
logStore: elasticsearch
elasticsearchConfig:
clusterName: ${ELASTICSEARCH_CLUSTER_NAME}
host: ${ELASTICSEARCH_HOST}
port: ${ELASTICSEARCH_PORT}
这个代码实例展示了如何使用Kubernetes的ClusterLogging资源来定义集中式和分布式日志记录。它演示了如何为Fluentd日志收集器设置资源限制,以及如何为Elasticsearch设置配置选项。代码还展示了如何引用环境变量以便在不同环境中灵活配置。