如何在 Kubernetes 集群上部署 Elasticsearch?我需要在集群外部使用 Elasticsearch。為此,我應該使用哪種服務?任何人都可以發布部署和服務 yaml 檔案嗎?
uj5u.com熱心網友回復:
如果您想在生產環境中運行,可以使用 helm chart 來部署 elasticsearch。
Helm 圖表:https ://github.com/elastic/helm-charts
如果您只是為開發和測驗而部署,您可以在 YAML 檔案下方:
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app : elasticsearch
component: elasticsearch
release: elasticsearch
name: elasticsearch
spec:
podManagementPolicy: Parallel
replicas: 1
revisionHistoryLimit: 10
selector:
matchLabels:
app : elasticsearch
component: elasticsearch
release: elasticsearch
serviceName: elasticsearch
template:
metadata:
creationTimestamp: null
labels:
app : elasticsearch
component: elasticsearch
release: elasticsearch
spec:
containers:
- env:
- name: cluster.name
value: <SET THIS>
- name: discovery.type
value: single-node
- name: ES_JAVA_OPTS
value: -Xms512m -Xmx512m
- name: bootstrap.memory_lock
value: "false"
image: elasticsearch:6.5.0
imagePullPolicy: IfNotPresent
name: elasticsearch
ports:
- containerPort: 9200
name: http
protocol: TCP
- containerPort: 9300
name: transport
protocol: TCP
resources:
limits:
cpu: 250m
memory: 1Gi
requests:
cpu: 150m
memory: 512Mi
securityContext:
privileged: true
runAsUser: 1000
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: elasticsearch-data
dnsPolicy: ClusterFirst
initContainers:
- command:
- sh
- -c
- chown -R 1000:1000 /usr/share/elasticsearch/data
- sysctl -w vm.max_map_count=262144
- chmod 777 /usr/share/elasticsearch/data
- chomod 777 /usr/share/elasticsearch/data/node
- chmod g rwx /usr/share/elasticsearch/data
- chgrp 1000 /usr/share/elasticsearch/data
image: busybox:1.29.2
imagePullPolicy: IfNotPresent
name: set-dir-owner
resources: {}
securityContext:
privileged: true
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /usr/share/elasticsearch/data
name: elasticsearch-data
restartPolicy: Always
schedulerName: default-scheduler
securityContext: {}
terminationGracePeriodSeconds: 10
updateStrategy:
type: OnDelete
volumeClaimTemplates:
- metadata:
creationTimestamp: null
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
參考要點:https ://gist.github.com/harsh4870/ccd6ef71eaac2f09d7e136307e3ecda6
我應該使用哪種服務
您可以使用LoadBalancer型別公開 Elasticsearch 服務并將其公開到互聯網并使用它。
服務.yaml
---
apiVersion: v1
kind: Service
metadata:
name: eks-srv
spec:
selector:
app: elasticsearch
component: elasticsearch
ports:
- name: db
protocol: TCP
port: 9200
targetPort: 9200
- name: monitoring
protocol: TCP
port: 9300
targetPort: 9300
type: LoadBalancer
筆記 :
您需要使用NodePort或LoadBalancer作為ClusterIp的服務型別,除非您使用一些代理設定或入口,否則您將無法公開服務。
uj5u.com熱心網友回復:
您可以嘗試使用 YAML 檔案,如下所示:
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: elasticsearch
labels:
com/es: es
spec:
replicas: 1
selector:
matchLabels:
com/es: es
template:
metadata:
labels:
com/es: es
spec:
containers:
- resources: {}
terminationMessagePath: /dev/termination-log
name: elasticsearch
env:
- name: discovery.type
value: single-node
ports:
- name: rest
containerPort: 9200
protocol: TCP
- name: inter-node
containerPort: 9300
protocol: TCP
imagePullPolicy: IfNotPresent
volumeMounts:
- name: <volume-name>
mountPath: <mount-path>
terminationMessagePolicy: File
image: 'docker.elastic.co/elasticsearch/elasticsearch:7.10.2'
restartPolicy: Always
terminationGracePeriodSeconds: 10
dnsPolicy: ClusterFirst
securityContext: {}
imagePullSecrets:
- name: <image-pullsecret>
schedulerName: default-scheduler
volumeClaimTemplates:
- kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: es-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 15Gi
volumeMode: Filesystem
serviceName: es-service
podManagementPolicy: OrderedReady
您可以使用這個創建 statefulset 的 yaml,statefullset 將在內部創建 elaticsearch pod。如果您想要卷掛載,您可以添加此 yaml 中提到的卷掛載資料。如果您不從規范和 volumeClaimTemplates 中洗掉卷部分。
要在外部使用 elasticsearch 進行集群,請嘗試以下操作:
kind: Service
apiVersion: v1
metadata:
name: es-service
labels:
com/es: es
spec:
ports:
- name: rest
protocol: TCP
port: 9200
targetPort: 9200
- name: inter-node
protocol: TCP
port: 9300
targetPort: 9300
selector:
com/es: es
clusterIP: <ip of your cluster>
clusterIPs:
- <ip of your cluster>
type: ClusterIP
ipFamilies:
- IPv4
uj5u.com熱心網友回復:
正如其他答案所指出的那樣,您可以使用 helm 圖表,但是 Elastic 還發布了自己的運算子,這是一個比部署裸 statefulSet 更強大的選項
要安裝操作員:
kubectl create -f https://download.elastic.co/downloads/eck/2.0.0/crds.yaml
kubectl apply -f https://download.elastic.co/downloads/eck/2.0.0/operator.yaml
并部署一個集群
cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
spec:
version: 8.0.0
nodeSets:
- name: default
count: 1
config:
node.store.allow_mmap: false
EOF
如果您想準備好這個生產,您可能需要進行一些進一步的調整,您可以在檔案中找到這些調整
uj5u.com熱心網友回復:
好吧,以下 yamls 對我有用 elasticsearch-deploy.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch
labels:
app: elasticsearch
spec:
selector:
matchLabels:
app: elasticsearch
replicas: 1
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
image: elasticsearch:7.9.0
resources:
requests:
memory: 4Gi
limits:
memory: 5Gi
ports:
- containerPort: 9200
- containerPort: 9300
env:
- name: discovery.type
value: single-node
現在,我們想從集群外部訪問這個彈性搜索。默認情況下,部署將分配 clusterip 服務,該服務用于訪問同一集群內的 Pod。這里我們使用 NodePort 服務來訪問集群外部。彈性搜索服務.yaml:
apiVersion: v1
kind: Service
metadata:
name: esservice
spec:
selector:
app: elasticsearch
type: NodePort
ports:
- port: 9200
targetPort: 9200
nodePort: 31200
這使您的服務可以通過以下方式從您的瀏覽器訪問:
HTTP://<nodeip>:<nodeport>
例如:HTTP://192.168.18.90:31200/
輸出如下:
name "elasticsearch-5974b56749-fj8n7"
cluster_name "docker-cluster"
cluster_uuid "4o-NidnuSSiBI-RwEPWEVQ"
version
number "7.9.0"
build_flavor "default"
build_type "docker"
build_hash "a479a2a7fce0389512d6a9361301708b92dff667"
build_date "2020-08-11T21:36:48.204330Z"
build_snapshot false
lucene_version "8.6.0"
minimum_wire_compatibility_version "6.8.0"
minimum_index_compatibility_version "6.0.0-beta1"
tagline "You Know, for Search"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/432970.html
標籤:弹性搜索 Kubernetes 部署 服务 yaml
上一篇:K8sJob不斷被重新創建
