Knative Log analysis with LogDNA on IBM Cloud
Tags: kubernetes, ibmcloud, logging, knative
Published: 2019-04-02 07:02:17

---
title: Knative Log analysis with LogDNA on IBM Cloud
published: true
tags: kubernetes,ibm-cloud,logging,knative
canonical_url: https://medium.com/vmacwrites/knative-log-analysis-with-logdna-on-ibm-cloud-568c4f5edfa0
---

In this post, you will learn how to use the IBM Log Analysis with LogDNA service to configure cluster-level logging for an app named **Knative-node-app** published in IBM Cloud Kubernetes Service. Refer this post - [_Install Knative with Istio and deploy an app on IBM Cloud_](https://dev.to/vidyasagarmsc/install-knative-with-istio-on-ibm-cloud-2lde-temp-slug-9746339)_,_ to setup a nodejs app.

> IBM Log Analysis with LogDNA offers administrators, DevOps teams, and developers advanced features to filter, search, and tail log data, define alerts, and design custom views to monitor application and system logs.

From the moment you provision a cluster with IBM Cloud Kubernetes Service, you wish to know what is happening inside the cluster. You need to access logs to troubleshoot problems and pre-empt issues. At any time, you want to have access to different types of logs such as worker logs, pod logs, app logs, or network logs. In addition, you can monitor different sources of log data in your Kubernetes cluster. Therefore, your ability to manage and access log records from any of these sources is critical. Your success managing and monitoring logs depends on how you configure the logging capabilities for your Kubernetes platform.

### Provision an IBM Log Analysis with LogDNA instance and Configure the LogDNA agent

> Before provisioning the instance, Check the [**Prerequisites**](https://cloud.ibm.com/docs/services/Log-Analysis-with-LogDNA/tutorials/kube.html#prereqs)

Once you have the app running on the Knative Kubernetes Cluster, provision an instance of the [IBM Log Analysis with LogDNA](https://cloud.ibm.com/observe/logging/create) service

- Choose a region/location (us-south)
- Select a resource group
- Select an appropriate plan ( **7 day Log Search recommended** for this post)
- Click **create**. With this step, you configure a centralized log management system where log data is hosted on IBM Cloud.

### Configure your Kubernetes cluster to send logs to your LogDNA instance

- Once the service is provisioned under [https://cloud.ibm.com/observe/logging](https://cloud.ibm.com/observe/logging), click on **Edit log sources** and then click **Kubernetes.**

![](https://cdn-images-1.medium.com/max/1024/1*DbOwzmmiZTM6Pwgb2oQ7Cw.png)<figcaption>Observability on IBM Cloud</figcaption>

- You should see two commands to automatically install a logdna-agent pod on each node of your cluster.

```
kubectl create secret generic logdna-agent-key --from-literal=logdna-agent-key= **<INGESTION_KEY>**

kubectl create -f https://repo.logdna.com/ibm/prod/logdna-agent-ds-us-south.yaml
```

- This configures the LogDNA agent on every worker (node) in a cluster.

![](https://cdn-images-1.medium.com/max/862/1*SQb88xplfaJgL2v9ZpG8_w.png)<figcaption>LogDNA agent on K8s Cluster sending logs to IBM Log Analysis with LogDNA</figcaption>

- To confirm the successful creation of LogDNA agent on every worker node in the cluster, run the below command

```
kubectl get pods
```

![](https://cdn-images-1.medium.com/max/1024/1*OIgYdoXaqiiMlgSVcWxJiQ.png)<figcaption>kubectl commands on IBM kui tool</figcaption>

### Launch the LogDNA dashboard and view logs

Let’s check and search the logs and also create some graphs by clicking **View LogDNA.** On a new tab **,** Under **Everything** , you should start seeing all the logs in realtime.

![](https://cdn-images-1.medium.com/max/1024/1*g--X5ryHt_jwygHhtHc88A.gif)

For this, we need to generate some traffic/load and there are many open source libraries/tools available. In the post, we will be using [Vegeta](https://github.com/tsenart/vegeta), an HTTP load testing tool and library. You can also use [hey](https://github.com/rakyll/hey).

Before generating the load, let’s quickly check whether the IP_ADDRESS and HOST_URL are set properly while deploying the app.

```
echo $IP_ADDRESS

echo $HOST_URL
```

After installing [Vegeta](https://github.com/tsenart/vegeta/releases), run the below command

```
echo “GET [http://${IP_ADDRESS](http://%24%7BIP_ADDRESS)}" | vegeta attack -duration=300s -header “Host: ${HOST_URL}” | tee results.bin | vegeta report
 vegeta report -type=json results.bin > metrics.json
 cat results.bin | vegeta plot > plot.html
 cat results.bin | vegeta report -type=”hist[0,100ms,200ms,300ms]”
```

You can open the _plot.html_ file in the folder you have run the above command to see the Vegeta plot

![](https://cdn-images-1.medium.com/max/1024/1*hJuS-5X0DGHwTc1mXvVj5Q.png)

On the LogDNA dashboard, you can search/filter for various fields in the search box and also highlight the terms you are interested in. You can also save this as a **View** as a bookmark by clicking on Unsaved View .

![](https://cdn-images-1.medium.com/max/1024/1*nPRZ7VXBLnUVdkZWoyB1zw.png)<figcaption>LogDNA dashboard</figcaption>

> **For archiving logs to IBM Cloud Object Storage** , refer [this link](https://cloud.ibm.com/docs/services/Log-Analysis-with-LogDNA/archive.html#archiving)

You can filter the logs by tags, sources, Apps and Levels (info, error etc.,)

![](https://cdn-images-1.medium.com/max/1024/1*dB2p5dqcFcC_-Pekh6tdEQ.png)<figcaption>Filtering the logs</figcaption>

### Boards and Graphs

A board is a named collection of graphs and is similar to a [view](https://docs.logdna.com/docs/views). All boards are located in the Boards List and may contain any number of graphs. Changes made to a board are automatically saved.

To create a new board, on the left pane > click on the icon below the dashboard and click +NEW BOARD. Let’s call this _knative-board_.

- Click on +Add Graph.
- Select _destinationApp_ as the field to graph.
- Choose knative-node-app-00001 as the optional value and click add graph.

![](https://cdn-images-1.medium.com/max/1024/1*sGgdPcleSqBI5FJthwdTKA.png)<figcaption>New graph creation</figcaption>

A new graph will be created with a plot of destinationApp over a period of 24 hours (Feel free to change the timeframe). You can also add a new plot by clicking **+Add Plot** below the graph.

![](https://cdn-images-1.medium.com/max/1024/1*BVIPdNzEmoTUaTGaoI6hAQ.png)<figcaption>knative-board with multiple graphs</figcaption>

As Knative is known for its autoscaling capabilities, Let’s see how the autoscaler behaves with incoming traffic/requests by adding a new graph as shown in the image above.

> Knative Serving Autoscaler — another k8s Deployment running a single Pod which watches request load on the Pods running user code. It increases and decreases the size of the Deployment running the user code in order to compensate for higher or lower traffic load.

Additionally, as an extension to the graphs you created, you can see the breakdown (a histogram) of various fields like nodes, destinationNames etc., by clicking on the arrow below the graph > +Add. You can create multiple breakdowns.

![](https://cdn-images-1.medium.com/max/1024/1*n9lLYwUHjebr6xfwpSDThA.png)<figcaption>Worker Nodes information</figcaption>

We have just touched the tip of the iceberg and there are many fields/metrics to look out for. Explore the tool with different load and filters.

**_Questions or concerns? Post a question or Reach out on Twitter @_** [**_VidyasagarMSC_**](https://twitter.com/VidyasagarMSC)

### Further reading

- Working with [alerts](https://console.bluemix.net/docs/services/Log-Analysis-with-LogDNA/alerts.html#alerts)
- [Exporting logs](https://console.bluemix.net/docs/services/Log-Analysis-with-LogDNA/export.html#export) to a local file
- Using Kaniko — [Build a container image inside a K8s cluster and push it to IBM Cloud Container Registry](https://medium.com/@VidyasagarMSC/build-a-container-image-inside-a-k8s-cluster-and-push-it-to-ibm-cloud-container-registry-abac9b1e5246)
- [IBM, Google Give Birth to Knative Serverless Cloud Project](http://www.eweek.com/development/ibm-google-give-birth-to-knative-serverless-cloud-project)
- [Knative Docs](https://github.com/knative/docs)

* * *