3.7.11 FilebeatのKubernetesマニフェスト作成
Elastic Stackを使用してトラブルシュート情報を収集する場合は、次の手順を実施してください。
- 重要
-
ElasticsearchのTLSによる暗号化通信について
ElasticsearchのTLSによる暗号化通信を有効にする場合、FilebeatでTLSによる暗号化通信の設定が必要です。詳細については、Elasticsearchの公式ドキュメントを参照してください。
(1) Filebeatのマニフェスト作成
Elasticsearchの公式ドキュメントを参考に、ConfigMapおよびDaemonSet以外のKubernetesマニフェストを作成してください。パラメタおよび設定値の詳細については、Elasticsearchの公式ドキュメントを参照してください。
(2) ConfigMapの作成
メッセージログ収集を設定し、Elasticsearchをメッセージログの永続化サービスとして利用するため、KubernetesマニフェストのConfigMapを作成してください。次に記述例を示します。
apiVersion: v1
kind: ConfigMap
metadata:
name: filebeat-config
namespace: my-namespace
data:
filebeat.yml: |-
filebeat.autodiscover:
providers:
- type: kubernetes
templates:
- condition: …1
or:
- equals:
kubernetes.namespace: my-namespace
config:
- type: container
paths:
- /var/log/containers/*-${data.kubernetes.container.id}.log
queue:
disk:
max_size: 10GB
read_ahead: 512
processors:
- add_kubernetes_metadata:
in_cluster: true
output.logstash: …2
hosts: ["logstash:5044"]
記述例の番号は、説明の番号と対応しています。
この例では、各KubernetesオブジェクトのNamespace名(metadata.namespaceフィールド)は、「my-namespace」としています。
<説明>
-
「- condition:」の行から「kubernetes.namespace: my-namespace」の行で、メッセージログの収集対象とするNamespace名を設定します。
複数のNamespaceからメッセージログを収集する場合は、次のように設定を追記します。
- condition: or: - equals: kubernetes.namespace: my-namespace - equals: kubernetes.namespace: my-namespace-2 -
「output.logstash:」の行から「hosts: ["logstash:5044"]」の行で、Logstashへメッセージログを送信するための設定をします。
(3) DaemonSetの作成
メッセージログ収集の設定のため、KubernetesマニフェストのDaemonSetを作成してください。DaemonSetを用いることで、クラスタ内のすべてのノード上にFilebeatのPodが1台ずつ起動し、各ノードのメッセージログを収集します。次に記述例を示します。
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: filebeat
namespace: my-namespace
labels:
app.kubernetes.io/name: filebeat
spec:
selector:
matchLabels:
app.kubernetes.io/name: filebeat
template:
metadata:
labels:
app.kubernetes.io/name: filebeat
spec:
serviceAccountName: filebeat
affinity: …1
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- node-1
- node-2
- node-3
containers:
- name: filebeat
image: myregistry.example.com/myproject/filebeat:V.R.S
args:
- "-e"
- "-E"
- "http.enabled=true"
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
securityContext:
runAsUser: 0
resources:
requests:
cpu: 100m
memory: 200Mi
limits:
memory: 200Mi
volumeMounts:
- name: config
mountPath: /usr/share/filebeat/filebeat.yml
subPath: filebeat.yml
readOnly: true
- name: varlogcontainers
mountPath: /var/log/containers
readOnly: true
- name: varlogpods
mountPath: /var/log/pods
readOnly: true
- name: varrundockersock
mountPath: /var/run/docker.sock
readOnly: true
volumes:
- name: config
configMap:
name: filebeat-config
defaultMode: 0600
- name: varlogcontainers
hostPath:
path: /var/log/containers
- name: varlogpods
hostPath:
path: /var/log/pods
- name: varrundockersock
hostPath:
path: /var/run/docker.sock
記述例の番号は、説明の番号と対応しています。
この例では、各KubernetesオブジェクトのNamespace名(metadata.namespaceフィールド)は、「my-namespace」としています。
<説明>
-
「affinity:」の行から「- node-3」の行の設定は省略できます。Filebeatを起動させたいノードを明示的に指定する場合に設定します。この設定を省略した場合、DaemonSetの動作によって、クラスタ内のすべてのノードでFilebeatのPodが自動的に作成されます。