1、创建yaml文件,这里我就不分开写了
apiVersion: v1
kind: ConfigMap
metadata:
name: sirc-elasticsearch-config
namespace: es
labels:
app: elasticsearch
data:
elasticsearch.yml: |+
cluster.name: crawl
node.name: ${MY_POD_NAME}
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/logs
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
discovery.zen.ping.unicast.hosts: ["elasticsearch-0.elasticsearch-cluster.es:9300","elasticsearch-1.elasticsearch-cluster.es:9300","elasticsearch-2.elasticsearch-cluster.es:9300"]
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
bootstrap.system_call_filter: false
xpack.security.enabled: false
indices.fielddata.cache.size: 60%
indices.queries.cache.size: 40%
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: elasticsearch
namespace: es
spec:
serviceName: "elasticsearch-cluster"
replicas: 3
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:6.0.0
ports:
- containerPort: 9200
name: elasticsearch
env:
- name: MY_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: ES_JAVA_OPTS
value: "-Xms1g -Xmx1g"
volumeMounts:
- name: elasticsearch-config
mountPath: /usr/share/elasticsearch/config/elasticsearch.yml
subPath: elasticsearch.yml
- name: es-data
mountPath: /usr/share/elasticsearch/data
volumes:
- name: elasticsearch-config
configMap:
name: sirc-elasticsearch-config
volumeClaimTemplates:
- metadata:
name: es-data
spec:
accessModes: ["ReadWriteOnce"]
storageClassName: nfs-boge
resources:
requests:
storage: 5Gi
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-cluster
namespace: es
labels:
app: elasticsearch
spec:
ports:
- port: 9200
name: elasticsearch
clusterIP: None
selector:
app: elasticsearch
---
apiVersion: v1
kind: Service
metadata:
name: elasticsearch
namespace: es
labels:
app: elasticsearch
spec:
ports:
- port: 9200
name: elasticsearch
type: NodePort
selector:
app: elasticsearch
2、应用yaml文件
[root@k8s-master1 ~]
configmap/sirc-elasticsearch-config created
statefulset.apps/elasticsearch created
service/elasticsearch-cluster created
service/elasticsearch created
3、验证是否成功
[root@k8s-master1 ~]
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
elasticsearch NodePort 10.0.0.251 <none> 9200:31637/TCP 11s
elasticsearch-cluster ClusterIP None <none> 9200/TCP 12s
node的ip+暴露端口
|