
The Elastic Stack (commonly known as the ELK Stack) is a collection of open-source tools for searching, analyzing, and visualizing log data in real time. It consists of Elasticsearch, Logstash, Kibana, and Beats (including Filebeat), which work together to collect, process, store, and visualize logs from applications and infrastructure. Organizations use the Elastic Stack to centralize logging, monitor system performance, detect security threats, and gain actionable insights from their data.
This article outlines the deployment of the ELK Stack on Kubernetes using the Elastic Cloud on Kubernetes (ECK) operator. It covers deploying Elasticsearch, Logstash, Kibana, and Filebeat, securing access with Traefik and Let's Encrypt SSL certificates, and visualizing cluster logs through the Kibana dashboard.
Before you begin, you need to:
kibana.example.com).Elasticsearch is a distributed, RESTful search and analytics engine that stores and indexes log data for fast retrieval. It serves as the central data store for the Elastic Stack, enabling full-text search, structured queries, and aggregations across large volumes of log data.
The Elastic Cloud on Kubernetes (ECK) operator simplifies deploying and managing Elasticsearch on Kubernetes by handling cluster configuration, scaling, and upgrades automatically.
Install the Elastic operator custom resource definitions (CRDs). Replace 3.4.0 with the latest stable version from the ECK releases page.
Install the Elastic operator.
The output confirms the operator resources are created including the namespace, service account, and statefulset.
List all pods in the elastic-system namespace and verify that the Elastic Operator is running.
The output shows the elastic-operator-0 pod with Running status.
Create a new elasticsearch.yaml file.
Add the following YAML contents to the file.
Save and close the file.
The above configuration creates an Elasticsearch cluster with the following settings:
version: Specifies the Elasticsearch version to deploy.nodeSets: Defines the cluster topology with one node in the default node set.config.node.store.allow_mmap: Disables memory-mapped files to avoid permission issues in containerized environments.volumeClaimTemplates: Configures persistent storage for Elasticsearch data. The storageClassName must match your cluster's available storage class. For Vultr Kubernetes Engine (VKE), use vultr-block-storage-hdd. Run kubectl get storageclass to list available storage classes for your provider.Apply the elasticsearch.yaml configuration to your cluster.
Wait at least 2 minutes, then list the Elasticsearch pods and verify that they are running.
The output shows the quickstart-es-default-0 pod with Running status.
Get the Elasticsearch service status and verify the assigned cluster IP.
The output displays the ClusterIP service listening on port 9200.
List all Persistent Volume Claims (PVCs) and verify that the Elasticsearch volume is bound.
The output shows the elasticsearch-data-quickstart-es-default-0 PVC with Bound status.
Monitor the Elasticsearch health and verify that the cluster is ready.
The output shows the cluster with Ready phase. With a single-node setup, the health may show yellow because replica shards cannot be placed. This is expected. If the health shows red, verify that the pods, service, and PVC resources are running and bound correctly.
Retrieve and store the generated password for the elastic user.
Copy the generated password from the output. You need this password to authenticate with Elasticsearch and Kibana.
Logstash is a server-side data processing pipeline that ingests, transforms, and forwards logs to Elasticsearch. It receives logs from various sources (including Filebeat), applies filters to parse and enrich the data, and sends the processed logs to Elasticsearch for storage and indexing.
Create a new logstash.yaml file.
Add the following YAML contents to the file.
Save and close the file.
The above configuration creates a Logstash instance with the following settings:
elasticsearchRefs: Links Logstash to the Elasticsearch cluster named quickstart. The ECK operator automatically injects connection credentials as environment variables.pipelines: Defines the data processing pipeline:input.beats: Configures Logstash to receive logs from Filebeat on port 5044.filter.mutate: Adds an environment field to each log entry based on the Kubernetes namespace, enabling filtering by namespace in Kibana.output.elasticsearch: Sends processed logs to Elasticsearch using credentials injected by ECK. Logs are indexed with a daily pattern (logstash-YYYY.MM.dd).services: Exposes a ClusterIP service on port 5044 for Filebeat to send logs.volumeClaimTemplates: Configures persistent storage for Logstash data and queue persistence. For Vultr Kubernetes Engine (VKE), use vultr-block-storage-hdd. Adjust the storageClassName based on your cluster's storage provider.Apply the logstash.yaml configuration to install Logstash in your cluster.
List the Logstash pods and verify that they are running.
The output shows the quickstart-ls-0 pod with Running status.
Monitor the Logstash health and verify that it is ready.
The output shows green health and 1/1 available replicas.
Filebeat is a lightweight log shipper that runs as a DaemonSet on every node in the Kubernetes cluster. It collects container logs from /var/log/containers/ and ships them to Logstash or Elasticsearch for processing. Filebeat automatically enriches logs with Kubernetes metadata such as pod name, namespace, and labels, making it easier to filter and analyze logs in Kibana.
Create a new filebeat.yaml file.
Add the following YAML contents to the file.
Save and close the file.
The above configuration deploys Filebeat as a DaemonSet with the following settings:
spec.type: Specifies Filebeat as the Beat type.config.filebeat.inputs: Configures log collection:type: filestream: Uses the filestream input to read container log files.paths: Collects all container logs from /var/log/containers/.parsers.container: Parses container log format automatically.prospector.scanner.symlinks: Follows symbolic links to locate actual log files.processors:add_kubernetes_metadata: Enriches each log entry with Kubernetes metadata (pod name, namespace, labels) based on the log file path.drop_event.when: Filters out logs from system namespaces (kube-system, kube-public, elastic-system, kube-node-lease) to reduce noise.output.logstash: Sends collected logs to Logstash on port 5044 for processing before indexing in Elasticsearch. Internal cluster communication over ClusterIP does not require additional SSL configuration.daemonSet.podTemplate: Configures the Filebeat pods:hostNetwork: true: Allows Filebeat to access node-level network for metadata enrichment.volumes: Mounts host paths to access container log files.securityContext.runAsUser: 0: Runs as root to read log files with restricted permissions.Create a new filebeat-rbac.yaml file to define the Role-Based Access Control (RBAC) configuration for Filebeat.
Add the following YAML contents to the file.
Save and close the file.
The above configuration creates RBAC resources that allow Filebeat to:
ServiceAccount: Provides an identity for Filebeat pods.ClusterRole: Grants read-only access to namespaces, pods, and nodes across the cluster for metadata enrichment.ClusterRoleBinding: Binds the ClusterRole to the Filebeat ServiceAccount.Apply the configurations to install Filebeat in your cluster.
List the Filebeat pods and verify that they are running on all nodes.
The output shows one Filebeat pod per node with Running status.
Monitor the Filebeat health and verify that it is ready.
The output shows green health with the expected number of available replicas matching your node count.
Kibana is the visualization and exploration interface for the Elastic Stack. It provides a web-based dashboard for searching, viewing, and analyzing logs stored in Elasticsearch. Kibana supports interactive charts, graphs, and maps, enabling real-time monitoring and troubleshooting of applications and infrastructure.
Create a new kibana.yaml file.
Add the following YAML contents to the file.
Save and close the file.
The above configuration deploys Kibana with the following settings:
elasticsearchRef: Connects Kibana to the Elasticsearch cluster named quickstart. ECK automatically configures authentication credentials.http.tls.selfSignedCertificate.disabled: Disables the self-signed certificate since Traefik handles TLS termination with Let's Encrypt certificates.Apply the kibana.yaml file to install Kibana in your cluster.
List all Kibana pods and verify that they are running.
The output shows the quickstart-kb-* pod with Running status.
Get the Kibana service status and verify the assigned cluster IP.
The output displays the ClusterIP service listening on port 5601.
Monitor the Kibana health and verify that it is ready.
The output shows green health and Ready status.
The Kibana dashboard requires secure TLS connections for production use. Traefik functions as an Ingress controller to route external traffic to Kibana, while cert-manager automatically provisions and renews Let's Encrypt SSL certificates.
Add the Traefik Helm chart repository.
Update the local Helm repository.
Install Traefik as an Ingress Controller in your cluster.
Get all resources deployed to the traefik namespace and verify that the deployment is ready.
The output shows the Traefik pod, service, deployment, and replicaset. Verify that the pod shows Running status.
Wait at least 3 minutes for the LoadBalancer to provision, then retrieve the external IP address.
The output displays the EXTERNAL-IP column with your public IP address. If it shows <pending>, wait a few more minutes for the cloud provider to assign an IP.
Log in to your DNS provider (such as Vultr DNS) and create a DNS A record pointing your domain (for example, kibana.example.com) to the LoadBalancer's external IP address.
Install cert-manager in your cluster. Replace v1.20.2 with the latest stable version from the cert-manager releases page.
List the cert-manager pods and verify that they are running.
The output shows all cert-manager pods with Running status.
Create a new issuer.yaml file.
Add the following YAML contents to the file. Replace admin@example.com with your active email address.
Save and close the file.
The above configuration creates a ClusterIssuer that:
Apply the ClusterIssuer configuration.
Create a new kibana-ingress.yaml file.
Add the following Ingress contents to the file. Replace kibana.example.com with your actual domain.
Save and close the file.
The above configuration:
kibana.example.com to the Kibana service on port 5601.letsencrypt ClusterIssuer to automatically provision and renew TLS certificates.kibana-tls.Apply the kibana-ingress.yaml configuration to your cluster.
List all Ingress resources and verify that Kibana is available.
The output shows the kibana Ingress with your domain in the HOSTS column.
Verify the certificate is issued successfully.
The output shows kibana-tls with True in the READY column. If it shows False, wait a few minutes for cert-manager to complete the ACME challenge.
Test HTTPS access to your domain.
The output shows HTTP/2 200 or a redirect to the Kibana login page, confirming TLS is working.
The Kibana web interface provides tools for exploring and visualizing log data from your Kubernetes cluster. Access the dashboard using your configured domain with the Elasticsearch credentials.
Retrieve the elastic user password.
Copy the password from the output.
Open a web browser and navigate to https://kibana.example.com. Replace kibana.example.com with your configured domain.
Log in to Kibana with the following credentials:
elasticClick Explore on my own to access the main dashboard.
Kibana's Discover feature allows you to search and filter logs collected by Filebeat from your Kubernetes cluster.
Expand the main menu in the top left corner.
Click Discover within the Analytics group.
Select the logstash-* data view from the dropdown menu. If no data view exists, create one:
logstash-* as the name and index pattern.@timestamp as the time field.Use the search bar to filter logs by namespace, pod name, or message content. For example:
kubernetes.namespace: default: Shows logs from the default namespace.kubernetes.pod.name: demo-app*: Shows logs from pods with names starting with demo-app.message: error: Shows logs containing the word "error".Adjust the time range using the date picker in the top right corner to view logs from specific time periods.
Click on any log entry to expand and view the full document, including Kubernetes metadata such as pod labels, container name, and node information.
Use the following checks to diagnose and resolve common issues encountered during deployment.
Elasticsearch pod stuck in Pending state
Run kubectl describe pod quickstart-es-default-0 to check the events. Common causes include:
kubectl get storageclass to verify available storage classes and update the storageClassName in elasticsearch.yaml.Elasticsearch health shows yellow or red
Run kubectl get elasticsearch to check the cluster status. A yellow status is normal for a single-node deployment because replica shards cannot be placed. For production workloads, increase nodeSets.count to at least 3 to achieve green health. If shards remain unassigned after scaling, run kubectl logs quickstart-es-default-0 to check for disk space or memory issues.
A red status indicates primary shards are unavailable. Check pod logs for out-of-memory errors or storage failures.
Filebeat pods not collecting logs
Verify the RBAC configuration is applied correctly:
If any resource is missing, reapply filebeat-rbac.yaml. Also verify the host path volumes are accessible by checking Filebeat logs:
Certificate not issued by cert-manager
Check the certificate status and events:
Common causes include:
dig kibana.example.com.Kibana shows "Kibana server is not ready yet"
Kibana requires Elasticsearch to be healthy before starting. Verify Elasticsearch status:
If Elasticsearch shows green health but Kibana still fails, check Kibana logs:
LoadBalancer IP shows pending
Cloud providers may take several minutes to provision a LoadBalancer. If the status remains <pending> after 5 minutes:
kubectl describe service traefik -n traefik.You have deployed the ELK Stack on Kubernetes using the ECK operator. Filebeat collects logs from every node in the cluster, Logstash processes and enriches them, Elasticsearch stores and indexes the data, and Kibana visualizes it through a dashboard secured with a Let's Encrypt TLS certificate. For more information on advanced configurations including multi-node clusters, custom pipelines, and alerting, refer to the official Elastic Cloud on Kubernetes documentation.
0 Comments
Be the first to comment and share your perspective with the community.