Created
February 11, 2020 20:54
-
-
Save lawrencejones/408d4a0cef21dfcb5512a190c7239c52 to your computer and use it in GitHub Desktop.
Custom jsonnet library for ES cluster
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local k = import 'vendor/k8s.libsonnet'; | |
k { | |
_config+:: { | |
name: 'name', | |
namespace: 'namespace', | |
node_storage: '5Gi', | |
labels: { app: 'elastic-cloud' }, | |
version: '7.5.2', | |
master_replicas: 3, | |
worker_replicas: 3, | |
config: { | |
'indices.breaker.total.limit': '80%', | |
'cluster.remote.connect': false, | |
'cluster.routing.allocation.awareness.attributes': 'zone', | |
'cluster.routing.allocation.disk.watermark.flood_stage': '98%', | |
'action.destructive_requires_name': true, | |
}, | |
master_config: $._config.config { | |
'node.master': true, | |
'node.data': false, | |
'node.ingest': false, | |
}, | |
worker_config: $._config.config { | |
'node.master': false, | |
'node.data': true, | |
'node.ingest': true, | |
}, | |
}, | |
local elasticsearch = self.elasticsearchType, | |
elasticsearchType:: { | |
local apiVersion = { apiVersion: 'elasticsearch.k8s.elastic.co/v1' }, | |
local kind = { kind: 'Elasticsearch' }, | |
new(name=''):: apiVersion + kind + self.mixin.metadata.withName(name), | |
mixin:: { | |
metadata:: $.core.v1.pod.mixin.metadata, | |
spec:: { | |
withVersion(version):: self { spec+: { version: version } }, | |
withNodeSetsMixin(nodeSets):: self { spec+: { nodeSets+: nodeSets } }, | |
}, | |
}, | |
}, | |
elasticsearch: | |
local statefulSet = $.apps.v1.statefulSet; | |
local container = statefulSet.mixin.spec.template.spec.containersType; | |
local volumeClaimTemplate = $.core.v1.persistentVolumeClaim; | |
local podTemplateSpec = $.apps.v1.deployment.mixin.spec.templateType; | |
local sysctlContainer = | |
container.new('sysctl') + | |
container.mixin.securityContext.withPrivileged(true) + | |
container.withCommand([ | |
['sh', '-c', 'sysctl -w vm.max_map_count=262144'], | |
]); | |
local dataVolumeClaim = | |
volumeClaimTemplate.new() + | |
volumeClaimTemplate.mixin.metadata.withName('elasticsearch-data') + | |
volumeClaimTemplate.mixin.spec.withAccessModes('ReadWriteOnce') + | |
volumeClaimTemplate.mixin.spec.withStorageClassName('ssd') + | |
volumeClaimTemplate.mixin.spec.resources.withRequests({ | |
storage: $._config.node_storage, | |
}); | |
elasticsearch.new($._config.name) + | |
elasticsearch.mixin.metadata.withNamespace($._config.namespace) + | |
elasticsearch.mixin.spec.withVersion($._config.version) + | |
elasticsearch.mixin.spec.withNodeSetsMixin([ | |
{ | |
name: 'master', | |
count: $._config.master_replicas, | |
config: $._config.master_config, | |
volumeClaimTemplates: [dataVolumeClaim], | |
podTemplate: | |
podTemplateSpec.new() + | |
podTemplateSpec.mixin.spec.withInitContainers( | |
sysctlContainer, | |
), | |
}, | |
{ | |
name: 'worker', | |
count: $._config.worker_replicas, | |
config: $._config.worker_config, | |
volumeClaimTemplates: [dataVolumeClaim], | |
podTemplate: | |
podTemplateSpec.new() + | |
podTemplateSpec.mixin.spec.withInitContainers( | |
sysctlContainer, | |
), | |
}, | |
]), | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment