Skip to content

Instantly share code, notes, and snippets.

@korjavin
Created February 26, 2019 10:42
Show Gist options
  • Save korjavin/7e76be75c0cf2d85165d89d936768e1a to your computer and use it in GitHub Desktop.
Save korjavin/7e76be75c0cf2d85165d89d936768e1a to your computer and use it in GitHub Desktop.
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: default
name: elasticsearch-master
labels:
component: elasticsearch
role: master
spec:
replicas: 3
selector:
matchLabels:
app: elasticsearch
role: master
template:
metadata:
labels:
app: elasticsearch
role: master
spec:
affinity:
# Try to put each ES master node on a different node in the K8s cluster
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- elasticsearch
- key: role
operator: In
values:
- master
topologyKey: kubernetes.io/hostname
# spec.template.spec.initContainers
initContainers:
# Increase the default vm.max_map_count to 262144
# https://www.elastic.co/guide/en/elasticsearch/reference/current/docker.html#docker-cli-run-prod-mode
- name: increase-the-vm-max-map-count
image: busybox
command: ['sysctl', '-w', 'vm.max_map_count=262144']
securityContext:
privileged: true
# spec.template.spec.containers
containers:
- name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.2
ports:
- containerPort: 9200
name: http
- containerPort: 9300
name: transport
livenessProbe:
tcpSocket:
port: transport
initialDelaySeconds: 20
periodSeconds: 10
resources:
requests:
cpu: 0.25
limits:
cpu: 1
memory: 1Gi
# spec.template.spec.containers[elasticsearch].env
env:
- name: discovery.zen.ping.unicast.hosts
value: "elasticsearch-master.default.svc.cluster.local,elasticsearch.default.svc.cluster.local"
- name: ES_JAVA_OPTS
value: -Xms512m -Xmx512m
- name: discovery.zen.minimum_master_nodes
value: "2"
- name: node.master
value: "true"
- name: node.ingest
value: "false"
- name: node.data
value: "false"
- name: search.remote.connect
value: "false"
- name: cluster.name
value: my-es-cluster
- name: node.name
valueFrom:
fieldRef:
fieldPath: metadata.name
# spec.template.spec.containers[elasticsearch].volumeMounts
volumeMounts:
- name: storage
mountPath: /usr/share/elasticsearch/data
- name: config
# This path seems likely to break, but $JAVA_HOME doesn't work
mountPath: /opt/jdk-11.0.1/lib/security/java.security
subPath: java.security
# spec.template.spec
volumes:
- name: config
configMap:
name: es-config
- name: storage
emptyDir:
medium: ""
---
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
namespace: default
name: elasticsearch-master
spec:
maxUnavailable: 1
selector:
matchLabels:
app: elasticsearch
role: master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment