Kubernetes EFK

Posted 傲娇小野猫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kubernetes EFK相关的知识,希望对你有一定的参考价值。

Kubernetes EFK

Elasticsearch + Fluentd + kibana 的构建:

Elasticsearch-rc 配置文件:

apiVersion: v1kind: ReplicationControllermetadata:  name: elasticsearch-logging-v1  namespace: kube-system  labels:    k8s-app: elasticsearch-logging    version: v1    kubernetes.io/cluster-service"true"spec:  replicas: 2  selector:    k8s-app: elasticsearch-logging    version: v1  template:    metadata:      labels:        k8s-app: elasticsearch-logging        version: v1        kubernetes.io/cluster-service"true"    spec:      containers:      - image: gcr.io/google-containers/elasticsearch:v2.4.1        name: elasticsearch-logging        resources:          # need more cpu upon initialization, therefore burstable class          limits:            cpu: 1000m          requests:            cpu: 100m        ports:        - containerPort: 9200          name: db          protocol: TCP        - containerPort: 9300          name: transport          protocol: TCP        volumeMounts:        - name: es-persistent-storage          mountPath: /data      volumes:      - name: es-persistent-storage        emptyDir:


Elasticsearch-svc 配置文件:

apiVersion: v1kind: Servicemetadata:  name: elasticsearch-logging  namespace: kube-system  labels:    k8s-app: elasticsearch-logging    kubernetes.io/cluster-service"true"    kubernetes.io/name"Elasticsearch"spec:  ports:  - port: 9200    name: http    protocol: TCP    targetPort: db  selector:    k8s-app: elasticsearch-logging


kibana-rc 配置文件:

apiVersion: extensions/v1beta1kind: Deploymentmetadata:  name: kibana-logging  namespace: kube-system  labels:    k8s-app: kibana-logging    kubernetes.io/cluster-service"true"spec:  replicas: 1  selector:    matchLabels:      k8s-app: kibana-logging  template:    metadata:      labels:        k8s-app: kibana-logging    spec:      containers:      - name: kibana-logging        image: gcr.io/google-containers/kibana:v4.6.1        resources:          # keep request = limit to keep this container in guaranteed class          limits:            cpu: 100m          requests:            cpu: 100m        env:          - name: "ELASTICSEARCH_URL"            value: "​​http://elasticsearch-logging:9200​​"        ports:        - containerPort: 5601          name: ui          protocol: TCP


kibana-svc 配置文件:

apiVersion: v1kind: Servicemetadata:  name: kibana-logging  namespace: kube-system  labels:    k8s-app: kibana-logging    kubernetes.io/cluster-service"true"    kubernetes.io/name"Kibana"spec:  ports:  - port: 5601    name: http    protocol: TCP    targetPort: ui  selector:    k8s-app: kibana-logging


fluentd-configmap 配置文件:

fluentd-configmap.yml 展开源码


fluentd-daemonset 配置文件:

apiVersion: extensions/v1beta1kind: DaemonSetmetadata:  name: fluentd-elasticsearch  namespace: kube-system  labels:    k8s-app: fluentd-loggingspec:  template:    metadata:      labels:        name: fluentd-elasticsearch    spec:      containers:      - name: fluentd-elasticsearch        image: gcr.io/google-containers/fluentd-elasticsearch:1.20        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/td-agent/"          name: config-volume      terminationGracePeriodSeconds: 30      volumes:      - name: varlog        hostPath:          path: /var/log      - name: varlibdockercontainers        hostPath:          path: /var/lib/docker/containers      - name: config-volume        configMap:          name: fluentd


正常启动后就会看到日志。

以上是关于Kubernetes EFK的主要内容,如果未能解决你的问题,请参考以下文章

Kubernetes EFK

Kubernetes 集群日志 和 EFK 架构日志方案

云原生(四十) | Kubernetes篇之整合EFK

Kubernetes实战总结 - EFK部署(v7.6.0)

Kubernetes 企业项目实战04基于 K8s 构建 EFK+logstash+kafka 日志平台(上)

09-5.部署 EFK 插件