vim es.yaml
---apiVersion: apps/v1kind: StatefulSetmetadata:name: es-sts-01spec:selector:matchLabels:app: eses-cluster: es01serviceName: elasticsearch-svcreplicas: 1template:metadata:labels:app: eses-cluster: es01spec:terminationGracePeriodSeconds: 10volumes:- name: data-storagepersistentVolumeClaim:claimName: es-nfs-pvc-1- name: localtimehostPath:path: /usr/share/zoneinfo/Asia/Shanghaitype: Filecontainers:- name: elasticsearchimage: elasticsearch:7.6.2ports:- containerPort: 9200name: es-cli- containerPort: 9300name: es-innerenv:- name: cluster.namevalue: es-cluster- name: node.namevalue: es01- name: cluster.initial_master_nodesvalue: es01,es02,es03- name: discovery.seed_hostsvalue: es-svc-inner-02,es-svc-inner-02- name: http.cors.enabledvalue: "true"- name: http.cors.allow-originvalue: "*"volumeMounts:- mountPath: /usr/share/elasticsearch/dataname: data-storage- name: localtimemountPath: /etc/localtimereadOnly: truevolumeClaimTemplates:- metadata:name: "data-storage"spec:resources:requests:storage: 1GaccessModes:- ReadWriteOncestorageClassName: "nfs-storageclass"---apiVersion: apps/v1kind: StatefulSetmetadata:name: es-sts-02spec:selector:matchLabels:app: eses-cluster: es02serviceName: elasticsearch-svcreplicas: 1template:metadata:labels:app: eses-cluster: es02spec:terminationGracePeriodSeconds: 10volumes:- name: data-storagepersistentVolumeClaim:claimName: es-nfs-pvc-2- name: localtimehostPath:path: /usr/share/zoneinfo/Asia/Shanghaitype: Filecontainers:- name: es-02image: elasticsearch:7.6.2ports:- containerPort: 9200name: es-cli- containerPort: 9300name: es-innerenv:- name: cluster.namevalue: es-cluster- name: node.namevalue: es02- name: cluster.initial_master_nodesvalue: es01,es02,es03- name: discovery.seed_hostsvalue: es-svc-inner-01,es-svc-inner-03- name: http.cors.enabledvalue: "true"- name: http.cors.allow-originvalue: "*"volumeMounts:- mountPath: /usr/share/elasticsearch/dataname: data-storage- name: localtimemountPath: /etc/localtimereadOnly: truevolumeClaimTemplates:- metadata:name: "data-storage"spec:resources:requests:storage: 1GaccessModes:- ReadWriteOncestorageClassName: "nfs-storageclass"---apiVersion: apps/v1kind: StatefulSetmetadata:name: es-sts-03spec:selector:matchLabels:app: eses-cluster: es03serviceName: elasticsearch-svcreplicas: 1template:metadata:labels:app: eses-cluster: es03spec:terminationGracePeriodSeconds: 10volumes:- name: data-storagepersistentVolumeClaim:claimName: es-nfs-pvc-3- name: localtimehostPath:path: /usr/share/zoneinfo/Asia/Shanghaitype: Filecontainers:- name: es-03image: elasticsearch:7.6.2ports:- containerPort: 9200name: es-cli- containerPort: 9300name: es-inerenv:- name: cluster.namevalue: es-cluster- name: node.namevalue: es03- name: cluster.initial_master_nodes- name: discovery.seed_hostsvalue: es-svc-inner-01,es-svc-inner-02- name: http.cors.enabledvalue: "true"- name: http.cors.allow-originvalue: "*"volumeMounts:- mountPath: /usr/share/elasticsearch/dataname: data-storage- name: localtimemountPath: /etc/localtimereadOnly: truevolumeClaimTemplates:- metadata:name: "data-storage"spec:resources:requests:storage: 1GaccessModes:- ReadWriteOncestorageClassName: "nfs-storageclass"---apiVersion: v1kind: Servicemetadata:name: elasticsearch-svclabels:app: elasticsearch-svcspec:type: NodePortports:- port: 9200name: es-clitargetPort: 9200nodePort: 31920selector:app: es---apiVersion: v1kind: Servicemetadata:name: es-svc-inner-01labels:app: es-svc-inner-01spec:type: ClusterIPports:- port: 9300name: es-portselector:es-cluster: es01---apiVersion: v1kind: Servicemetadata:name: es-svc-inner-02labels:app: es-svc-inner-02spec:type: ClusterIPports:- port: 9300name: es-portselector:es-cluster: es02---apiVersion: v1kind: Servicemetadata:name: es-svc-inner-03labels:app: es-svc-inner-03spec:type: ClusterIPports:- port: 9300name: es-portselector:es-cluster: es03
kubectl apply -f es.yaml 即可