apiVersion: apps/v1
kind: Deployment
metadata:
name: elasticsearch-node1
namespace: branch
spec:
replicas: 1
selector:
matchLabels:
app: elasticsearch
template:
metadata:
labels:
app: elasticsearch
spec:
initContainers:
- name: fix-permissions
image: busybox
command: ['sh', '-c', 'chown -R 1000:1000 /usr/share/elasticsearch/config', 'chown -R 1000:1000 /usr/share/elasticsearch/data']
volumeMounts:
- name: config-volume
mountPath: /usr/share/elasticsearch/config
- name: data-volume
mountPath: /usr/share/elasticsearch/data
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2
securityContext:
runAsUser: 1000
runAsGroup: 1000
env:
- name: node.name
value: "node1"
- name: cluster.name
value: "elasticsearch-cluster"
- name: discovery.seed_hosts
value: "node1, node2, node3"
- name: cluster.initial_master_nodes
value: "node1, node2, node3"
volumeMounts:
- name: config-volume
mountPath: /usr/share/elasticsearch/config
- name: data-volume
mountPath: /usr/share/elasticsearch/data
volumes:
- name: config-volume
hostPath:
path: /data/containerd/elasticsearch/node1/config
type: Directory
- name: data-volume
hostPath:
path: /data/containerd/elasticsearch/node1/data
type: Directory
nodeSelector:
name: node2
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-node
namespace: branch
spec:
clusterIP: None
selector:
app: elasticsearch
ports:
- port: 9201
name: http
- port: 9301
name: transport
apiVersion: v1
kind: Service
metadata:
name: elasticsearch-node1
namespace: branch
spec:
ports:
- port: 9201
name: rest
targetPort: 31015
- port: 9301
name: transport
clusterIP: None
selector:
app: elasticsearch
node.name: "node1"