Skip to main contentIBM Cloud Patterns

Configuring for Containers

Configuring for Containers

Logging and Monitoring have always been important but in a distributed microservices architecture on a Kubernetes cluster it is even more important. IBM Cloud with LogDNA can be used with a Kubernetes Cluster. This pattern will show you how to create a Kubenetes cluster and use IBM Cloud with LogDNA for tracking events logs in containers.

Creating a Kubernetes Cluster

First create a Kubernetes Cluster using this information, See, Getting Started Kubernetes

After you create a Kubernetes Cluster, use the IBM Cloud menu->Kubernetes->Cluster, and then select the cluster which you want information for. It will show the dashboard similar to the one below.

IBM Cloud Kubernetes Deployment

Note: Kubernetes event logs can be sent in the same region or in a different region.

You’ll need to provision an instance of the IBM Log Analysis with LogDNA service. This allows for a configured centralized log management system where log data is hosted on IBM Cloud. You can use either an existing Kubernetes cluster or configure Kubernetes on the IBM Cloud. Use an existing or provision a new instance of IBM Log Analysis with LogDNA through the IBM Cloud console, see Getting Started LogDNA

Make sure to choose your supported region, see Supported Regions.

Getting the ingestion key

For more information on setting up LogDNA, see Getting Started

Complete the following steps to get the ingestion key:

  1. Log in to your IBM Cloud account . After you log in, the IBM Cloud UI opens.
  2. Click the Menu icon Observability to access the Observability dashboard.
  3. Select Logging. The IBM Log Analysis with LogDNA dashboard opens. You can see the list of logging instances that are available on IBM Cloud.
  4. Identify the instance for which you want to get the ingestion key, and click View key.
  5. A window opens where you can click Show to view the ingestion key.
Get Ingestion Key

Configuring Kubernetes to Send logs

Now, let’s configure our Kubernetes cluster to send logs to the IBM LogDNA instance configured earlier. We can configure our Kubernetes cluster to send event log traffic to the us-south region, you’ll need to complete the following procedures below.

Open a terminal to login into your IBM Cloud account.

$ ibmcloud login -a cloud.ibm.com

Set the cluster where you want to configure logging as the context for this session.

$ ibmcloud ks cluster-config cluster_name_or_ID

Deploying the LogDNA agent on Kubernetes

Let’s now create a Kubernetes secret to store your logDNA ingestion key for your service instance.

  • Note: us-south region is shown below, choose the region according to your requirements.
$ kubectl create -f https://assets.us-south.logging.cloud.ibm.com/clients/logdna-agent-ds.yaml

The LogDNA ingestion key will be used to open a secure web socket to the logDNA ingestion server and to authenticate the logging agent with the IBM Log Analysis with LogDNA service.

Now, let’s verify our LogDNA agent was deployed successfully by running the following command.

$ kubectl get pods

If the deployment was successful you should see one or more LogDNA pods running.

LogDNA Pods

You’ll notice the number of LogDNA pods is equal to the number of worker nodes in your cluster. All pods should be in a Running state.

Now let’s take a look at the logs captured by IBM Log Analysis with LogDNA, by viewing the dashboard. Launch the LogDNA dashboard and view logs. You can do so by going through the IBM Cloud console, following the steps below:

  1. Log in to your IBM Cloud account External link icon.

  2. From the Menu icon, select Observability.

  3. Select Logging. The list of IBM Log Analysis with LogDNA service instances that are available on IBM Cloud is displayed.

  4. Select one instance and click View LogDNA. The LogDNA dashboard opens.

IBM Cloud Menu

Customizing LogDNA Views

Now let’s customize your default view. In the USER PREFERENCES section, you can modify the order of the data fields that are displayed per line.

Complete the following steps to modify the format of a log line: Select the Configuration icon. Configuration

Select USER PREFERENCES. A new window opens. User Preference

Choose something different from the default Viewer Theme, let’s select Monokai. Monokai

Select Log Format, modify the Line Format section to match your requirements. Line Format

Let’s look into a log line, at anytime you can view each event log line in context. Complete the following steps:

  1. Click the Views icon Configuration icon. Configuration
  2. Select Everything or a view.
  3. Identify a line in the log that you want to explore.
  4. Expand the log line.

Information about line identifiers, tags, and labels is displayed. Everything

Expanded view of the log line, from step 4 above. Log Line

  1. Click View in Context to see the log line in context of other log lines. View Context

  2. Click Copy to clipboard to copy the message field to the clipboard. When you are finished, close the line. Clipboard

With IBM Log Analysis with LogDNA, you can filter logs by log source, application and even log level. Sources of event log searches or filters can be a host, computer, virtual machine or Heroku app. Next, let’s try out filtering logs.

  1. Click on the Views icon Filter Configuration

  2. Select Everything or a view.

  3. Expand All Tags to see the list of tags that are identified in the logs. Then, choose the ones that you want.

  4. Expand All Sources to see the list of log sources that are identified in the logs. Then, choose the ones that you want.

  5. Expand All Apps to see the list of apps that are identified in the logs. Then, choose the ones that you want.

  6. Expand All Levels to see the list of log levels that are identified in the logs. Then, choose the ones that you want.

Notice, the All Apps expanded view below. All Apps

For our last activity, lets create a view. Follow the steps below.

  1. Click the Views icon Configuration icon. View Context

  2. Select Everything or a view.

  3. Filter log data then click Save as new view / alert. The Create new view page opens.

  4. Enter a name for the view in the Name field.

  5. Optionally, attach an alert. A new section is displayed for you to configure the alert.

  6. Click Save View

Shown below is a saved view, notice the error logs displayed. Views

You can manage your Views by Categories.

Saved View

For more information on IBM Cloud Log Analysis with LogDNA, visit Getting Started