1.准备工作
思路: 在OpenShift容器平台上以daemonset方式部署Fluentd收集各节点中的日志。更改其配置让日志输出到外部Elasticsearch中,最终通过Kibana展示。
资料:
Fluentd官方配置文档:https://docs.fluentd.org/v0.12/articles/kubernetes-fluentd
Fluentd-k8s项目地址:https://github.com/fluent/fluentd-kubernetes-daemonset(yaml模板文件)
2.部署Fluentd
默认yaml文件,创建之前先创建configmap。
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: fluentd
namespace: kube-system ---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRole
metadata:
name: fluentd
namespace: kube-system
rules:
- apiGroups:
- ""
resources:
- pods
- namespaces
verbs:
- get
- list
- watch ---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: fluentd
roleRef:
kind: ClusterRole
name: fluentd
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: fluentd
namespace: kube-system
---
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: fluentd
namespace: kube-system
labels:
k8s-app: fluentd-logging
version: v1
kubernetes.io/cluster-service: "true"
spec:
template:
metadata:
labels:
k8s-app: fluentd-logging
version: v1
kubernetes.io/cluster-service: "true"
spec:
serviceAccount: fluentd
serviceAccountName: fluentd
tolerations:
- key: node-role.kubernetes.io/master
effect: NoSchedule
containers:
- name: fluentd
image: docker.io/fluent/fluentd-kubernetes-daemonset:elasticsearch
env:
- name: FLUENT_ELASTICSEARCH_HOST
value: "192.168.0.129"
- name: FLUENT_ELASTICSEARCH_PORT
value: "9200"
- name: FLUENT_ELASTICSEARCH_SCHEME
value: "http"
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
- mountPath: /etc/fluent/
name: config
readOnly: true
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
- configMap:
defaultMode: 420
name: fluentd-logging
name: config
#创建daemonset
oc create -f fluentd-daemonset-elasticsearch.yaml
登录控制台查看,默认在kube-system空间中。