Kubernetes LocalPV構築Elasticsearch 7.6.2-非ECK方式
11622 ワード
最近K 8 Sを振り回してESをインストールして、ECKはとても便利で、しかし多くの细かい点をも遮って、やはり多く他の方式から恨んで、1回LocalPVを使ってESをインストールする过程を记录することを望みます.
環境 Kubernetes 1.18.2クラスタ-2ノード:1 master+1 node Kuboardのチュートリアルをお勧めします:https://kuboard.cn/install/install-k8s.html ES 7.6.2バージョン Local PVについて volumeClaimTemplatesにstorageClassNameと明記するだけで、kubernetes.io/no-provisioner方式を採用し、一致する名称によって自動的に利用可能なPV を申請する
の準備を nodeノードのhostnameはzqw 02 zqw 02にログインし、ローカルボリューム を作成ディレクトリ認可
ESクラスタのネーミングスペースの作成 ns.yaml 実行ファイル
storage provisionerの作成 stc.yaml 実行ファイル
PVリソースプールの作成(需要個数を満たすことができる) PVリソースファイル を作成する PVリソースファイル を実行する.
ESクラスタサービスの作成実行ファイル
ES StatefulSetの作成実行ファイル
けんさサービスの表示 クラスタ状態 PVC/PVを確認する場合
PV-PVCの対応関係には一定のランダム選択性が見られますが、もちろんnodeは固定されています
リファレンス
https://hacpai.com/article/1586757433779
環境
の準備を
mkdir -p /mnt/localpv/es7-0 /mnt/localpv/es7-1 /mnt/localpv/es7-2
chmod -R 777 /mnt/localpv/
ESクラスタのネーミングスペースの作成
[root@zqw01 es1]# cat ns.yaml
apiVersion: v1
kind: Namespace
metadata:
name: logging
kubectl create -f ns.yml
storage provisionerの作成
[root@zqw01 es1]# cat stc.yaml
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
namespace: logging
name: local-storage
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
kubectl create -f stc.yaml
PVリソースプールの作成(需要個数を満たすことができる)
[root@zqw01 es1]# cat lp0.yaml lp1.yaml lp2.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-storage-pv-0
labels:
name: local-storage-pv-0
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /mnt/localpv/es7-0
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- zqw02
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-storage-pv-1
labels:
name: local-storage-pv-1
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /mnt/localpv/es7-1
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- zqw02
---
apiVersion: v1
kind: PersistentVolume
metadata:
name: local-storage-pv-2
labels:
name: local-storage-pv-2
spec:
capacity:
storage: 20Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: local-storage
local:
path: /mnt/localpv/es7-2
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: kubernetes.io/hostname
operator: In
values:
- zqw02
kubectl create -f lp0.yml
kubectl create -f lp1.yml
kubectl create -f lp2.yml
ESクラスタサービスの作成
[root@zqw01 es1]# cat svc.yaml
kind: Service
apiVersion: v1
metadata:
name: elasticsearch7
namespace: logging
labels:
app: elasticsearch7
spec:
selector:
app: elasticsearch7
type: NodePort
ports:
- port: 9200
name: rest
nodePort: 32000
- port: 9300
name: inter-node
kubectl create -f svc.yaml
ES StatefulSetの作成
[root@zqw01 es1]# cat sts.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: es7-cluster
namespace: logging
spec:
serviceName: elasticsearch7
replicas: 3
selector:
matchLabels:
app: elasticsearch7
template:
metadata:
labels:
app: elasticsearch7
spec:
containers:
- name: elasticsearch7
image: elasticsearch:7.6.2
resources:
limits:
cpu: 1000m
requests:
cpu: 100m
ports:
- containerPort: 9200
name: rest
protocol: TCP
- containerPort: 9300
name: inter-node
protocol: TCP
volumeMounts:
- name: data
mountPath: /usr/share/elasticsearch/data
env:
- name: cluster.name
value: k8s-logs
- name: node.name
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: discovery.seed_hosts
value: "es7-cluster-0.elasticsearch7,es7-cluster-1.elasticsearch7,es7-cluster-2.elasticsearch7"
- name: cluster.initial_master_nodes
value: "es7-cluster-0,es7-cluster-1,es7-cluster-2"
- name: ES_JAVA_OPTS
value: "-Xms1g -Xmx1g"
initContainers:
- name: fix-permissions
image: busybox
command: ["sh", "-c", "chown -R 1000:1000 /usr/share/elasticsearch/data"]
securityContext:
privileged: true
volumeMounts:
- name: data
mountPath: /usr/share/elasticsearch/data
- name: increase-vm-max-map
image: busybox
command: ["sysctl", "-w", "vm.max_map_count=262144"]
securityContext:
privileged: true
- name: increase-fd-ulimit
image: busybox
command: ["sh", "-c", "ulimit -n 65536"]
volumeClaimTemplates:
- metadata:
name: data
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: "local-storage"
resources:
requests:
storage: 20Gi
kubectl create -f sts.yaml
けんさ
[root@zqw01 es1]# kubectl get svc -n logging
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elasticsearch7 NodePort 10.96.55.170 <none> 9200:32000/TCP,9300:31147/TCP 41m
[root@zqw01 es1]# curl 10.96.55.170:9200
{
"name" : "es7-cluster-1",
"cluster_name" : "k8s-logs",
"cluster_uuid" : "R-OGPazVTBaemL0M6jRJ1g",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "docker",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
[root@zqw01 es1]# kubectl get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
local-storage-pv-0 20Gi RWO Retain Bound logging/data-es7-cluster-1 local-storage 47m
local-storage-pv-1 20Gi RWO Retain Bound logging/data-es7-cluster-0 local-storage 47m
local-storage-pv-2 20Gi RWO Retain Bound logging/data-es7-cluster-2 local-storage 47m
[root@zqw01 es1]#
[root@zqw01 es1]# kubectl get pvc -n logging
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
data-es7-cluster-0 Bound local-storage-pv-1 20Gi RWO local-storage 42m
data-es7-cluster-1 Bound local-storage-pv-0 20Gi RWO local-storage 41m
data-es7-cluster-2 Bound local-storage-pv-2 20Gi RWO local-storage 40m
PV-PVCの対応関係には一定のランダム選択性が見られますが、もちろんnodeは固定されています
リファレンス
https://hacpai.com/article/1586757433779