Skip to main content
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!

Pre-deployment Setup

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.

Exploring the Repository Files

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)

Inspecting the Elasticsearch StatefulSet

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.

Volume Mount and Persistent Storage

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”.

Defining the Elasticsearch Service

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.

Deploying the Elasticsearch Stack

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:
Apply the configuration files with the following commands:
Next, monitor the status of the Elasticsearch pod:
To further troubleshoot or verify logs, run:
An example snippet from the Elasticsearch pod logs might be:
If no errors are reported, Elasticsearch is running correctly.

Final Verification

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!

Watch Video

Practice Lab