This article provides a guide for deploying Elasticsearch on a Kubernetes cluster, including setup, configuration, and persistent storage.
Welcome to this comprehensive lesson on deploying Elasticsearch on a Kubernetes cluster. In this guide, you’ll learn how to set up the cluster, inspect configuration files, and deploy Elasticsearch with persistent storage.Let’s get started!
Before deploying the Elasticsearch cluster, execute a few preparatory commands. Start by tainting the control plane, creating a dedicated namespace called “efk”, and setting the current context to that namespace. Then, clone the repository and navigate to the Elasticsearch/Kibana folder.
After navigating to the proper directory, list the available files to understand the repository structure. There are five configuration files present. The three critical files for Elasticsearch are:
es-statefulset.yaml (defines the StatefulSet)
es-service.yaml (defines the Service)
es-pvolume.yaml (defines the Persistent Volume)
Copy
Ask AI
ls -lrt# total 4cd efk-stack/cd /root/efk-stack/elasticsearch-kibanals -lrt# total 20# -rw-r--r-- 1 root root 184 Aug 6 14:18 kibana-service.yaml# -rw-r--r-- 1 root root 354 Aug 6 14:18 kibana-deployment.yaml# -rw-r--r-- 1 root root 1195 Aug 6 14:18 es-statefulset.yaml# -rw-r--r-- 1 root root 299 Aug 6 14:18 es-service.yaml# -rw-r--r-- 1 root root 185 Aug 6 14:18 es-pvolume.yaml
The es-statefulset.yaml file contains the configuration for the Elasticsearch StatefulSet. This file includes metadata, pod specifications, and the Docker image version (8.13.0). It exposes ports 9200 and 9300 and sets essential environment variables, such as running in single-node mode and disabling x-pack security for demonstration purposes.
Later in the same file, the persistent storage size is updated along with similar configurations. Note that the x-pack security is disabled, and the volume mount ensures persistent data storage across pod restarts.
For enhanced security in production environments, explore additional configuration options to enable robust authentication and secure data communication.
The StatefulSet configures an “es-data” volume mount where Elasticsearch stores its data. This mount is defined via a Persistent Volume Claim, ensuring that data persists even if the pod is restarted or recreated.
The Persistent Volume (defined in es-pvolume.yaml) is configured to use a hostPath at “/data/elasticsearch” with a storage capacity of 5Gi and access mode “ReadWriteOnce”.
The es-service.yaml file defines the Elasticsearch Service, which exposes ports 9200 and 9300. It leverages NodePort and ensures consistent metadata with the StatefulSet for proper traffic routing.
After reviewing all configuration files, deploy the Elasticsearch stack by applying the Persistent Volume, StatefulSet, and Service configurations. First, confirm that all necessary files are present:
Copy
Ask AI
# List the files to ensure they are presentls -lrt# total 20# -rw-r--r-- 1 root root 184 Aug 6 14:18 kibana-service.yaml# -rw-r--r-- 1 root root 354 Aug 6 14:18 kibana-deployment.yaml# -rw-r--r-- 1 root root 1195 Aug 6 14:18 es-statefulset.yaml# -rw-r--r-- 1 root root 209 Aug 6 14:18 es-service.yaml# -rw-r--r-- 1 root root 105 Aug 6 14:18 es-pvolume.yaml
Apply the configuration files with the following commands:
Elasticsearch is now deployed in the “efk” namespace on Kubernetes. In the next lesson, we will deploy Kibana and demonstrate how to verify the Elasticsearch cluster status via the Kibana UI.Thank you for following along. See you in the next lesson!