elasticsearch
Opinionated Elasticsearch + Kibana chart for small to medium workloads
About this chart
Elasticsearch
Distributed search and analytics engine with integrated Kibana web UI for visualization and exploration.
TL;DR
# Add Helm repository
helm repo add sb-charts https://scriptonbasestar-container.github.io/sb-helm-charts
helm repo update
# Install chart with default values (single-node mode)
helm install elasticsearch sb-charts/elasticsearch
# Install with production cluster (3 nodes + security)
helm install elasticsearch sb-charts/elasticsearch \
-f https://raw.githubusercontent.com/scriptonbasestar-container/sb-helm-charts/master/charts/elasticsearch/values-small-prod.yaml \
--set elasticsearch.password=your-secure-password
Introduction
This chart bootstraps an Elasticsearch deployment with optional Kibana on a Kubernetes cluster using the Helm package manager.
Key Features:
- ✅ Single-node and cluster mode support
- ✅ Integrated Kibana for visualization and management
- ✅ Optional security with password authentication
- ✅ Production-ready with HA support (3+ nodes)
- ✅ Persistent storage with StatefulSet
- ✅ Snapshot/backup to S3 (MinIO compatible)
- ✅ No external database required
Prerequisites
- Kubernetes 1.24+
- Helm 3.8+
- PersistentVolume provisioner support in the underlying infrastructure
External Dependencies
None required! Elasticsearch is self-contained and does not require external databases.
Optional:
- MinIO/S3: For snapshot repository (backup/restore)
- Prometheus: For metrics collection
Installing the Chart
Quick Start
# Install with default values (single-node mode, security disabled)
helm install my-elasticsearch sb-charts/elasticsearch
Deployment Scenarios
This chart includes pre-configured values for different deployment scenarios:
Development Environment
helm install my-elasticsearch sb-charts/elasticsearch \
-f https://raw.githubusercontent.com/scriptonbasestar-container/sb-helm-charts/master/charts/elasticsearch/values-dev.yaml
Configuration:
- Single node (no clustering)
- Security disabled (no password)
- CORS enabled for browser-based tools
- Kibana ingress enabled
- Resources: 500m-2000m CPU, 1Gi-2Gi RAM
- Storage: 10Gi per node
Use Case: Local development, testing, quick prototyping
Small Production Cluster
helm install my-elasticsearch sb-charts/elasticsearch \
-f https://raw.githubusercontent.com/scriptonbasestar-container/sb-helm-charts/master/charts/elasticsearch/values-small-prod.yaml \
--set elasticsearch.password=your-secure-password
Configuration:
- 3-node cluster with quorum
- Security enabled (password required)
- Kibana HA (2 replicas)
- Production ingress with TLS
- Pod anti-affinity for HA
- PodDisruptionBudget (minAvailable: 2)
- Resources: 2000m-4000m CPU, 2Gi-4Gi RAM per node
- Storage: 100Gi per node (SSD recommended)
- Init container for sysctl tuning
Use Case: Small production deployments, logging infrastructure, search applications
Configuration
Deployment Modes
Elasticsearch supports two deployment modes:
Single-Node Mode:
- Single server deployment
discovery.type=single-node- Suitable for development/testing
- Lower resource requirements
- No cluster quorum required
Cluster Mode:
- 3+ nodes (minimum for quorum)
- Cluster discovery via headless service
- Master election and distributed data
- Production HA deployment
- Automatic shard allocation
elasticsearch:
clusterMode: true # Enable cluster mode
replicas: 3 # Minimum 3 for quorum
clusterName: "elasticsearch-prod"
Common Configuration Options
| Parameter | Description | Default |
|---|---|---|
elasticsearch.replicas | Number of Elasticsearch nodes | 1 |
elasticsearch.clusterMode | Enable cluster mode (requires 3+ nodes) | false |
elasticsearch.clusterName | Cluster name | elasticsearch |
elasticsearch.password | Elastic user password (empty = security disabled) | "" |
elasticsearch.javaOpts | JVM heap options | -Xms1g -Xmx1g |
elasticsearch.httpCorsEnabled | Enable CORS (for browser clients) | false |
kibana.enabled | Enable Kibana deployment | true |
kibana.replicas | Number of Kibana replicas | 1 |
kibana.ingress.enabled | Enable Kibana ingress | false |
image.repository | Elasticsearch image | docker.elastic.co/elasticsearch/elasticsearch |
image.tag | Image tag (overrides appVersion) | "" |
persistence.enabled | Enable persistence | true |
persistence.size | Storage size per node | 30Gi |
persistence.storageClass | Storage class name | "" |
resources.limits.memory | Memory limit | 2Gi |
resources.limits.cpu | CPU limit | 2000m |
See values.yaml for all available options.
JVM Heap Size
IMPORTANT: Set heap size to 50% of container memory limit, maximum 31GB.
elasticsearch:
javaOpts: "-Xms2g -Xmx2g" # For 4Gi memory limit
resources:
limits:
memory: 4Gi
Using Existing Secrets
elasticsearch:
existingSecret: "my-es-secret"
# Secret must contain key: elastic-password
Using Existing ConfigMap
elasticsearch:
existingConfigMap: "my-es-config"
# ConfigMap must contain key: elasticsearch.yml
Persistence
The chart creates Persistent Volumes using StatefulSet volumeClaimTemplates (one per pod).
PVC Configuration:
persistence:
enabled: true
storageClass: "fast-ssd" # Use SSD for better performance
accessMode: ReadWriteOnce
size: 100Gi # Size per node
annotations: {}
Total Storage Calculation:
Total = replicas × size
Example: 3 nodes × 100Gi = 300Gi raw
With replication factor 1: ~150Gi usable (excluding overhead)
Networking
Service Configuration
Elasticsearch exposes two services:
- HTTP Service (port 9200): REST API for queries and indexing
- Headless Service (port 9300): Cluster discovery and node-to-node transport
service:
type: ClusterIP
http:
port: 9200
headlessService:
annotations: {}
Kibana Ingress
kibana:
ingress:
enabled: true
className: nginx
annotations:
cert-manager.io/cluster-issuer: letsencrypt-prod
nginx.ingress.kubernetes.io/proxy-body-size: "0"
hosts:
- host: kibana.example.com
paths:
- path: /
pathType: Prefix
tls:
- secretName: kibana-tls
hosts:
- kibana.example.com
Security
Password Authentication
Enable security by setting password:
elasticsearch:
password: "your-secure-password"
This enables:
xpack.security.enabled=trueelasticuser with password- HTTP authentication required
CORS Settings (Development)
Enable for browser-based Elasticsearch clients:
elasticsearch:
httpCorsEnabled: true
httpCorsAllowOrigin: "*" # or specific origin
⚠️ Production: Disable CORS or restrict to specific origins.
Pod Security Context
podSecurityContext:
fsGroup: 1000
runAsUser: 1000
runAsGroup: 1000
fsGroupChangePolicy: "OnRootMismatch"
securityContext:
runAsNonRoot: true
runAsUser: 1000
capabilities:
drop:
- ALL
System Configuration
For production, set vm.max_map_count=262144 on Kubernetes nodes:
# On each node
sysctl -w vm.max_map_count=262144
# Persistent
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
Or use init container (values-small-prod.yaml includes this):
initContainers:
- name: init-sysctl
image: busybox:latest
command:
- sh
- -c
- |
sysctl -w vm.max_map_count=262144
sysctl -w fs.file-max=65536
securityContext:
privileged: true
High Availability
Cluster Quorum
Minimum 3 nodes for cluster mode with master election:
elasticsearch:
replicas: 3 # Minimum for quorum
clusterMode: true
Cluster will set cluster.initial_master_nodes=elasticsearch-0,elasticsearch-1,elasticsearch-2.
Pod Disruption Budget
Maintain quorum during updates:
podDisruptionBudget:
enabled: true
minAvailable: 2 # For 3-node cluster
Pod Anti-Affinity
Distribute pods across nodes/zones:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app.kubernetes.io/component
operator: In
values:
- elasticsearch
topologyKey: kubernetes.io/hostname
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app.kubernetes.io/component
operator: In
values:
- elasticsearch
topologyKey: topology.kubernetes.io/zone
Monitoring
Health Probes
Chart includes comprehensive health checks:
livenessProbe:
httpGet:
path: /_cluster/health?local=true
port: 9200
initialDelaySeconds: 90
periodSeconds: 30
readinessProbe:
httpGet:
path: /_cluster/health?local=true
port: 9200
initialDelaySeconds: 30
periodSeconds: 10
startupProbe:
httpGet:
path: /_cluster/health?local=true
port: 9200
failureThreshold: 60 # Up to 10 minutes for startup
Prometheus Integration
Enable monitoring (optional):
elasticsearch:
monitoring:
enabled: true
podAnnotations:
prometheus.io/scrape: "true"
prometheus.io/port: "9200"
prometheus.io/path: "/_prometheus/metrics"
Kibana Setup
Kibana is enabled by default and automatically connects to Elasticsearch.
Accessing Kibana
Port Forward:
kubectl port-forward svc/kibana 5601:5601
# Access at http://localhost:5601
Ingress:
kibana:
ingress:
enabled: true
hosts:
- host: kibana.example.com
Kibana Authentication
When Elasticsearch security is enabled, Kibana uses elastic user:
# Get password
kubectl get secret elasticsearch-secret -o jsonpath='{.data.elastic-password}' | base64 -d
# Login:
# Username: elastic
# Password: (from above)
Elasticsearch Client Setup
Using cURL
# Port forward
kubectl port-forward svc/elasticsearch 9200:9200 &
# No authentication (security disabled)
curl http://localhost:9200
# With authentication
PASSWORD=$(kubectl get secret elasticsearch-secret -o jsonpath='{.data.elastic-password}' | base64 -d)
curl -u elastic:$PASSWORD http://localhost:9200
# Cluster health
curl -u elastic:$PASSWORD http://localhost:9200/_cluster/health?pretty
# List indices
curl -u elastic:$PASSWORD http://localhost:9200/_cat/indices?v
Python Client
from elasticsearch import Elasticsearch
# No authentication
es = Elasticsearch(['http://elasticsearch:9200'])
# With authentication
es = Elasticsearch(
['http://elasticsearch:9200'],
basic_auth=('elastic', 'your-password')
)
# Create index
es.indices.create(index='myindex')
# Index document
es.index(index='myindex', id=1, document={'field': 'value'})
# Search
result = es.search(index='myindex', query={'match_all': {}})
Node.js Client
const { Client } = require('@elastic/elasticsearch');
// No authentication
const client = new Client({ node: 'http://elasticsearch:9200' });
// With authentication
const client = new Client({
node: 'http://elasticsearch:9200',
auth: {
username: 'elastic',
password: 'your-password'
}
});
// Create index
await client.indices.create({ index: 'myindex' });
// Index document
await client.index({
index: 'myindex',
id: 1,
document: { field: 'value' }
});
// Search
const result = await client.search({
index: 'myindex',
query: { match_all: {} }
});
Snapshot and Backup
S3/MinIO Snapshot Repository
Elasticsearch supports S3-compatible snapshot repositories (MinIO, AWS S3, etc.).
Prerequisites:
- MinIO/S3 bucket created
- Access credentials
Create Snapshot Repository:
# Using Makefile
make -f make/ops/elasticsearch.mk es-create-snapshot-repo \
REPO=minio \
BUCKET=elasticsearch-backups \
ENDPOINT=http://minio:9000 \
ACCESS_KEY=admin \
SECRET_KEY=password123
# Or manually
kubectl exec -it elasticsearch-0 -- curl -X PUT "http://localhost:9200/_snapshot/minio?pretty" \
-u elastic:password \
-H 'Content-Type: application/json' -d'{
"type": "s3",
"settings": {
"bucket": "elasticsearch-backups",
"endpoint": "http://minio:9000",
"access_key": "admin",
"secret_key": "password123",
"path_style_access": true
}
}'
Create Snapshot:
# Using Makefile
make -f make/ops/elasticsearch.mk es-create-snapshot REPO=minio SNAPSHOT=snapshot_1
# Or manually
curl -X PUT "http://localhost:9200/_snapshot/minio/snapshot_1?wait_for_completion=false&pretty" -u elastic:password
List Snapshots:
make -f make/ops/elasticsearch.mk es-snapshots REPO=minio
Restore Snapshot:
make -f make/ops/elasticsearch.mk es-restore-snapshot REPO=minio SNAPSHOT=snapshot_1
See S3 Integration Guide for MinIO integration.
Operational Commands
Using Makefile (make/ops/elasticsearch.mk):
Credentials and Access
# Get elastic user password
make -f make/ops/elasticsear
Deploy elasticsearch with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has elasticsearch on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartelasticsearch is pinned at v0.3.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply