您好,登錄后才能下訂單哦!
這篇文章給大家分享的是有關(guān)Kubernetes中EFK怎么用的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
一:前言
1.在安裝Kubernetes集群的時(shí)候我們有下載過壓縮包https://dl.k8s.io/v1.8.5/kubernetes-client-linux-amd64.tar.gz
解壓縮后 在目錄cluster\addons 下有各插件的yaml文件,大部分情況僅需少量改動(dòng)即可使用。
2.在搭建Kubernetes的集群過程中,涉及到很多鏡像的下載,建議可以在阿里云購(gòu)買一個(gè)香港所在地的ECS服務(wù)器,鏡像下載完成后通過docker save -o 將鏡像導(dǎo)出,在通過docker load 導(dǎo)入鏡像或者上傳鏡像到個(gè)人鏡像倉(cāng)庫(kù)。
3.Kubernetes從1.8版本開始,EFK的安裝中,elasticsearch-logging采用StatefulSet類型,但存在bug,會(huì)導(dǎo)致elasticsearch-logging-0 POD 一直無法成功創(chuàng)建。 所以建議還是采用1.8之前的版本采用ReplicationController。
4.要成功安裝EFK,一定要先安裝kube-dns前面的文章已有介紹。
5.EFK安裝過程中elasticsearch和kibana版本要兼容。這里采用的鏡像如下:
gcr.io/google_containers/elasticsearch:v2.4.1-2
gcr.io/google_containers/fluentd-elasticsearch:1.22
gcr.io/google_containers/kibana:v4.6.1-1
二:yaml文件
efk-rbac.yaml
點(diǎn)擊(此處)折疊或打開
apiVersion: v1
kind: ServiceAccount
metadata:
name: efk
namespace: kube-system
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: efk
subjects:
- kind: ServiceAccount
name: efk
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin
apiGroup: rbac.authorization.k8s.io
es-controller.yaml
點(diǎn)擊(此處)折疊或打開
apiVersion: v1
kind: ReplicationController
metadata:
name: elasticsearch-logging-v1
namespace: kube-system
labels:
k8s-app: elasticsearch-logging
version: v1
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
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:
serviceAccountName: efk
containers:
- image: gcr.io/google_containers/elasticsearch:v2.4.1-2
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
env:
- name: "NAMESPACE"
valueFrom:
fieldRef:
fieldPath: metadata.namespace
volumes:
- name: es-persistent-storage
emptyDir: {}
es-service.yaml
點(diǎn)擊(此處)折疊或打開
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-logging
namespace: kube-system
labels:
k8s-app: elasticsearch-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/name: "Elasticsearch"
spec:
ports:
- port: 9200
protocol: TCP
targetPort: db
selector:
k8s-app: elasticsearch-logging
fluentd-es-ds.yaml
點(diǎn)擊(此處)折疊或打開
apiVersion: extensions/v1beta1
kind: DaemonSet
metadata:
name: fluentd-es-v1.22
namespace: kube-system
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
version: v1.22
spec:
template:
metadata:
labels:
k8s-app: fluentd-es
kubernetes.io/cluster-service: "true"
version: v1.22
# This annotation ensures that fluentd does not get evicted if the node
# supports critical pod annotation based priority scheme.
# Note that this does not guarantee admission on the nodes (#40573).
annotations:
scheduler.alpha.kubernetes.io/critical-pod: ''
spec:
serviceAccountName: efk
containers:
- name: fluentd-es
image: gcr.io/google_containers/fluentd-elasticsearch:1.22
command:
- '/bin/sh'
- '-c'
- '/usr/sbin/td-agent 2>&1 >> /var/log/fluentd.log'
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
volumeMounts:
- name: varlog
mountPath: /var/log
- name: varlibdockercontainers
mountPath: /var/lib/docker/containers
readOnly: true
nodeSelector:
beta.kubernetes.io/fluentd-ds-ready: "true"
tolerations:
- key : "node.alpha.kubernetes.io/ismaster"
effect: "NoSchedule"
terminationGracePeriodSeconds: 30
volumes:
- name: varlog
hostPath:
path: /var/log
- name: varlibdockercontainers
hostPath:
path: /var/lib/docker/containers
kibana-controller.yaml 此處需要特殊說明,綠色標(biāo)識(shí)的部分KIBANA_BASE_URL 的value要設(shè)置為空,默認(rèn)值會(huì)導(dǎo)致Kibana訪問出現(xiàn)問題。
點(diǎn)擊(此處)折疊或打開
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: kibana-logging
namespace: kube-system
labels:
k8s-app: kibana-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
spec:
replicas: 1
selector:
matchLabels:
k8s-app: kibana-logging
template:
metadata:
labels:
k8s-app: kibana-logging
spec:
serviceAccountName: efk
containers:
- name: kibana-logging
image: gcr.io/google_containers/kibana:v4.6.1-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"
- name: "KIBANA_BASE_URL"
value: ""
ports:
- containerPort: 5601
name: ui
protocol: TCP
kibana-service.yaml
點(diǎn)擊(此處)折疊或打開
apiVersion: v1
kind: Service
metadata:
name: kibana-logging
namespace: kube-system
labels:
k8s-app: kibana-logging
kubernetes.io/cluster-service: "true"
addonmanager.kubernetes.io/mode: Reconcile
kubernetes.io/name: "Kibana"
spec:
ports:
- port: 5601
protocol: TCP
targetPort: ui
selector:
k8s-app: kibana-logging
三:?jiǎn)?dòng)與驗(yàn)證
1. 創(chuàng)建資源
kubectl create -f .
2.通過 kubectl logs -f 查看相關(guān)pod的日志,確認(rèn)是否正常啟動(dòng)。 其中kibana-logging-* POD 啟動(dòng)需要一定的時(shí)間。
3.elasticsearch驗(yàn)證(可以通過kube proxy創(chuàng)建代理)
http://IP:PORT/_cat/nodes?v
點(diǎn)擊(此處)折疊或打開
host ip heap.percent ram.percent load node.role master name
10.1.88.4 10.1.88.4 9 87 0.45 d m elasticsearch-logging-v1-hnfv2
10.1.67.4 10.1.67.4 6 91 0.03 d * elasticsearch-logging-v1-zmtdl
http://IP:PORT/_cat/indices?v
點(diǎn)擊(此處)折疊或打開
health status index pri rep docs.count docs.deleted store.size pri.store.size
green open logstash-2018.04.07 5 1 515 0 1.1mb 584.4kb
green open .kibana 1 1 2 0 22.2kb 9.7kb
green open logstash-2018.04.06 5 1 15364 0 7.3mb 3.6mb
4.kibana驗(yàn)證
http://IP:PORT/app/kibana#/discover?_g
四:備注
要成功搭建EFK,需要注意一下幾點(diǎn):
1.確保已經(jīng)成功安裝了kube-dns
2.當(dāng)前版本elasticsearch-logging采用ReplicationController
3.elasticsearch和kibana的版本要兼容
4.KIBANA_BASE_URL value設(shè)置為“”
感謝各位的閱讀!關(guān)于“Kubernetes中EFK怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。