1. 程式人生 > >Kubernetes - - k8s - v1.12.3 持久化EFK安裝

Kubernetes - - k8s - v1.12.3 持久化EFK安裝

1,映象下載

1.1 所有節點下載映象

docker pull kibana:5.6.4
docker tag kibana:5.6.4 docker.elastic.co/kibana/kibana:5.6.4

docker pull xiaoqshuo/fluentd-elasticsearch:v2.0.4
docker pull xiaoqshuo/elasticsearch:v5.6.4

docker tag xiaoqshuo/fluentd-elasticsearch:v2.0.4 k8s.gcr.io/fluentd-elasticsearch:v2.0.4
docker tag xiaoqshuo/elasticsearch:v5.6.4 k8s.gcr.io/elasticsearch:v5.6.4
  • master01下載對應的k8s原始碼包
wget https://github.com/kubernetes/kubernetes/releases/download/v1.12.3/kubernetes.tar.gz
  • 對節點進行label
[[email protected] fluentd-elasticsearch]# pwd
/opt/k8-ha-install/kubernetes/cluster/addons/fluentd-elasticsearch

[[email protected] fluentd-elasticsearch]# kubectl label node beta.kubernetes.io/fluentd-ds-ready=true --all
node/k8s-master01 labeled
node/k8s-node01 labeled
node/k8s-node02 labeled

[
[email protected]
fluentd-elasticsearch]# kubectl get nodes --show-labels | grep beta.kubernetes.io/fluentd-ds-ready k8s-master01 Ready master 27h v1.12.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-master01,node-role.kubernetes.io/master= k8s-node01 Ready master 27h v1.12.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-node01,node-role.kubernetes.io/master= k8s-node02 Ready master 27h v1.12.3 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/fluentd-ds-ready=true,beta.kubernetes.io/os=linux,kubernetes.io/hostname=k8s-node02,node-role.kubernetes.io/master=

2,持久化卷

  • 採用NFS作為後端儲存,NAS、GFS、CEPH同理
  • 所有節點
yum install nfs-utils -y

2.1 NFS -- > 伺服器:k8s-node01

  • 在NFS伺服器上建立es的儲存目錄(使用動態儲存可以自動建立pv,無需此步驟)
[[email protected] es]# pwd
/nfs/es

[[email protected] es]# mkdir es{0..2}

[[email protected] es]# ls
es0  es1  es2
  • 啟動 nfs
systemctl start rpcbind && systemctl enable rpcbind
systemctl start nfs && systemctl enable nfs
  • 配置NFS
[[email protected] ~]# more /etc/exports
/nfs/es/ 192.168.2.0/24(rw,sync,no_subtree_check,no_root_squash)
  • 配置生效
[[email protected] es]# exportfs -rv
exporting 192.168.2.0/24:/nfs/es
  • 檢視nfs掛載點
[[email protected] es]# showmount -e localhost
Export list for localhost:
/nfs/es 192.168.2.0/24
  • 測試掛載
[[email protected] ~]#mkdir -p /nfs/es
[[email protected] ~]# mount -t nfs k8s-node01:/nfs/es /nfs/es

3,建立叢集

  • 使用靜態pv建立es叢集
  • 檔案地址:https://github.com/xiaoqshuo/k8s-cluster/tree/master/k8s-efk
  • :配置了3個pv,只啟了2個例項
[[email protected] k8s-cluster]# kubectl apply -f k8s-efk/
namespace/logging created
service/elasticsearch-logging created
serviceaccount/elasticsearch-logging created
clusterrole.rbac.authorization.k8s.io/elasticsearch-logging created
clusterrolebinding.rbac.authorization.k8s.io/elasticsearch-logging created
statefulset.apps/elasticsearch-logging created
persistentvolume/pv-es-0 created
persistentvolume/pv-es-1 created
persistentvolume/pv-es-2 created
configmap/fluentd-es-config-v0.1.4 created
serviceaccount/fluentd-es created
clusterrole.rbac.authorization.k8s.io/fluentd-es created
clusterrolebinding.rbac.authorization.k8s.io/fluentd-es created
daemonset.apps/fluentd-es-v2.0.4 created
deployment.apps/kibana-logging created
service/kibana-logging created
  • 檢視pv、pvc、pods
[[email protected] k8s-efk]# kubectl get pv
NAME      CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM                                                   STORAGECLASS       REASON   AGE
pv-es-0   4Gi        RWX            Recycle          Bound       logging/elasticsearch-logging-elasticsearch-logging-0   es-storage-class            8s
pv-es-1   4Gi        RWX            Recycle          Available                                                           es-storage-class            8s
pv-es-2   4Gi        RWX            Recycle          Bound       logging/elasticsearch-logging-elasticsearch-logging-1   es-storage-class            8s


[[email protected] k8s-efk]# kubectl get pod -n logging
NAME                              READY   STATUS    RESTARTS   AGE
elasticsearch-logging-0           1/1     Running   0          35s
elasticsearch-logging-1           1/1     Running   0          32s
fluentd-es-v2.0.4-595tq           1/1     Running   0          34s
fluentd-es-v2.0.4-8x8bj           1/1     Running   0          34s
fluentd-es-v2.0.4-fxjp4           1/1     Running   0          34s
kibana-logging-8458f5d886-vfkzc   1/1     Running   0          34s