> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deployments for Kibana instances

> This article guides deploying a Kibana pod on a Kubernetes cluster, covering verification, manifest review, and connectivity with Elasticsearch.

Hello and welcome back!

In this article, we will guide you through deploying a Kibana pod on your Kubernetes cluster. You will learn how to verify your cluster’s status, review the necessary deployment and service manifests, and confirm that Kibana connects effectively with Elasticsearch.

***

## 1. Verifying the Cluster Status

Before proceeding, ensure your cluster is healthy by checking the status of your pods. Run the following command:

```bash theme={null}
kubectl get pods
```

You should see output similar to this:

```bash theme={null}
NAME                                READY   STATUS    RESTARTS   AGE
elasticsearch-0                     1/1     Running   0          2m50s
```

Next, verify that the required manifest files are available in your current working directory. List the files by executing:

```bash theme={null}
ls -lrt
```

A sample output might be:

```bash theme={null}
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   185 Aug  6 14:18 es-volume.yaml
```

***

## 2. Reviewing the Kibana Deployment Manifest

The `kibana-deployment.yaml` file defines how Kubernetes should deploy the Kibana pod. Open the file to review its contents:

```bash theme={null}
cat kibana-deployment.yaml
```

The manifest content is as follows:

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: kibana
  namespace: efk
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kibana
  template:
    metadata:
      labels:
        app: kibana
    spec:
      containers:
      - name: kibana
        image: docker.elastic.co/kibana/kibana:8.13.0
        ports:
        - containerPort: 5601
```

This manifest specifies:

* **Resource Kind:** A Deployment used to manage the lifecycle of the Kibana pod.
* **Namespace:** The `efk` namespace.
* **Replica Count:** A single instance (replica) of Kibana.
* **Container Configuration:** Utilizes the official Kibana Docker image from Elastic and exposes port 5601.

<Callout icon="lightbulb" color="#1CB2FE">
  Ensure that the versions of Elasticsearch and Kibana are compatible. Always review the corresponding release notes from Elastic before selecting your Docker image.
</Callout>

***

## 3. Reviewing the Kibana Service Manifest

The `kibana-service.yaml` file exposes Kibana using a NodePort. Open and inspect the service manifest:

```bash theme={null}
cat kibana-service.yaml
```

The manifest content should appear as:

```yaml theme={null}
apiVersion: v1
kind: Service
metadata:
  name: kibana
  namespace: efk
spec:
  type: NodePort
  selector:
    app: kibana
  ports:
    - protocol: TCP
      port: 5601
      nodePort: 30601
```

This service configuration:

* Uses the **NodePort** type to make Kibana accessible externally.
* Routes traffic from the cluster’s internal port 5601 to the node’s port 30601.
* Targets pods labeled with `app: kibana` in the `efk` namespace.

<Callout icon="lightbulb" color="#1CB2FE">
  By default, the Kibana Docker image searches for Elasticsearch within the same namespace. Ensure that Elasticsearch is deployed in the `efk` namespace to allow automatic connection.
</Callout>

***

## 4. Deploying Kibana

### Step 1: Apply the Deployment Manifest

Deploy the Kibana pod by applying the deployment manifest:

```bash theme={null}
kubectl apply -f kibana-deployment.yaml
```

A successful operation will confirm with a message similar to:

```text theme={null}
deployment.apps/kibana created
```

### Step 2: Apply the Service Manifest

Next, expose the Kibana pod by applying the service manifest:

```bash theme={null}
kubectl apply -f kibana-service.yaml
```

You should see an output like:

```Kubernetes theme={null}
service/kibana created
```

### Step 3: Verify the Pod Status

Clear your terminal and run the following command to check the status of the pods:

```bash theme={null}
kubectl get pods
```

The output may resemble:

```bash theme={null}
NAME                                READY   STATUS              RESTARTS   AGE
elasticsearch-0                     1/1     Running             0          4m47s
kibana-5bf7c766b4-pgdz              0/1     ContainerCreating   0          14s
```

Wait a minute or two for the Kibana pod to transition to the **Running** state. To monitor the progress in real-time, use:

```bash theme={null}
kubectl get pods -w
```

Once the pod shows as running, proceed to verify your services:

```bash theme={null}
kubectl get svc
```

A sample output might be:

```bash theme={null}
NAME            TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)                         AGE
elasticsearch   NodePort    10.96.188.157   <none>        9200:32000/TCP,9300:30300/TCP     5m30s
kibana          NodePort    10.103.134.155  <none>        5601:30601/TCP                  55s
```

<Callout icon="lightbulb" color="#1CB2FE">
  Depending on your specific requirements, you might consider using a load balancer instead of NodePort for production environments.
</Callout>

***

## 5. Connecting to the Kibana UI

Follow these steps to access the Kibana user interface:

1. **Identify the NodePort:** In our example, the NodePort is **30601**.
2. **Access through Browser:** Open your web browser and enter the following URL, replacing `\<NODE_IP>` with the IP address of your node:

   http\://\<NODE\_IP>:30601

Once the Kibana UI loads, click on **"Explore on my own"** (or a similar option) and proceed to the **"Dev Tools"** section. This interactive console allows you to run queries against the connected Elasticsearch cluster.

### Testing Elasticsearch Connectivity

Use the Dev Tools console in Kibana to execute the following commands:

1. **Run a Search Query:**

   ```json theme={null}
   GET _search
   {
     "query": {
       "match_all": {}
     }
   }
   ```

2. **Check Cluster Health:**

   Clear the previous output and run:

   ```json theme={null}
   GET /_cluster/health
   ```

A successful response will be similar to:

```json theme={null}
{
  "cluster_name": "docker-cluster",
  "status": "green",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 28,
  "active_shards": 28,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 0,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 100
}
```

A status of **green** means your Elasticsearch cluster is healthy and that Kibana is properly connected.

***

## Conclusion

In this guide, you learned how to deploy and expose Kibana on your Kubernetes cluster within the `efk` namespace. By carefully following the verification, deployment, and connectivity tests, you can replicate this setup in your environment—whether on-premises or in the cloud.

Happy deploying, and see you in the next article!

***

## Additional Resources

* [Kubernetes Documentation](https://kubernetes.io/docs/)
* [Kibana Documentation](https://www.elastic.co/guide/en/kibana/)
* [Elasticsearch Documentation](https://www.elastic.co/guide/en/elasticsearch/)

If you have any questions, feel free to consult the linked resources or reach out for further assistance.

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/efk-stack-enterprise-grade-logging-and-monitoring/module/79ef74c6-138f-4dd8-b5fb-e8a8050b59a5/lesson/b27a24c8-3103-4a19-b9c8-8267d53d3237" />

  <Card title="Practice Lab" icon="installation" cta="Learn more" href="https://learn.kodekloud.com/user/courses/efk-stack-enterprise-grade-logging-and-monitoring/module/79ef74c6-138f-4dd8-b5fb-e8a8050b59a5/lesson/f2aed817-c481-4f3e-8b53-a4221749ef8c" />
</CardGroup>
