Friday, May 9, 2025

Install Elasticsearch Cluster on Azure Kubernetes Service

Elastic search is the first component of the ELK stack that gives powerful search and analytics capabilities to DevOps and development teams. We have discussed how to install Elastic Cloud for Kubernetes (ECK) in previous blog post. In this blog, let's learn how to install elastic stack on Kubernetes.

Pre-requites:

  • Azure Kubernetes Cluster
  • Full administrative access to the Kubernetes Cluster
  • Workstation with kubectl installed
  • Elastic Cloud on Kubernetes is installed

Open a shell or use the Azure Kubernetes Service 'Run Command' to run the script below and create an Elasticsearch node.

cat <<EOF | kubectl apply -f -

apiVersion: elasticsearch.k8s.elastic.co/v1

kind: Elasticsearch

metadata:

  name: quickstart

spec:

  version: 8.16.1

  nodeSets:

  - name: default

    count: 1

    config:

      node.store.allow_mmap: false

EOF

Run the following command to check the pod status.

kubectl get pods --selector='elasticsearch.k8s.elastic.co/cluster-name=quickstart'

The command will return a pod status similar to the output shown below

Once the pod status is 'Running', the Elasticsearch cluster is created and ready to use. Before accessing the cluster, we need to find the cluster IP and password. Run the command below to get the cluster IP.

kubectl get service quickstart-es-http

The command will return cluster IP information similar to below


Run the command below to get the password or retrieve the cluster password from the Azure portal by navigating to, Kubernetes Resources → Configuration → Secrets → quickstart-es-elastic-user.

PASSWORD=$(kubectl get secret quickstart-es-elastic-user -o go-template='{{.data.elastic | base64decode}}')

Run the command below to access Elasticsearch from inside the cluster.

curl -u "elastic:$PASSWORD" -k "https://quickstart-es-http:9200"

To access the Elasticsearch cluster from outside, first open PowerShell or any suitable shell, and run the command below to enable port forwarding

kubectl port-forward service/quickstart-es-http 9200



On Windows machine, open https://localhost:9200 in a browser and you will be prompted to enter a username and password. Enter elastic username and password (quickstart-es-elastic-user)



No comments:

Post a Comment