KUBERNETES: A Simple Guide to Master Kubernetes for Beginners and Advanced Users (2020 Edition) by Brian Docker

KUBERNETES: A Simple Guide to Master Kubernetes for Beginners and Advanced Users (2020 Edition) by Brian Docker

Author:Brian Docker [Docker, Brian]
Language: eng
Format: azw3, epub
Published: 2020-05-14T16:00:00+00:00


Chapter 7.

Logging

When you are using monitoring functions, then you can easily dig out components that show whether your system has failed or if there is a problem you might have overlooked. However, in many cases, you might not be able to discover the root cause of the problem.

This is why you have the process of logging.

Let us take a simple example. Imagine that you have run a program that is going to produce the sum of all the numbers from 1 to 100. You know that the result is 5,050. However, as you were monitoring the process, you realized that the program skipped the number 50.

You know that there was an error in that process. But when you get the result, you notice that the final number is 4,900. You know that the program has omitted the number 50, but you don’t know what other numbers were removed and for that matter, why those numbers have been excluded. You then go to the log and notice where the errors have happened and also why they occurred.

The process of logging allows you to refine your program so that it makes fewer and fewer errors in the future. Think of it this way: monitoring allows you to effectively look at the present situation of the program. However, logging allows you go back to the beginning if you would like to and check for any inconsistencies.

Generally, there are two important posts to a logging system. You have the logging agent and then the backend.

The logging agent is a layer that is responsible for gathering information and dispatching the information to the backend. When the information reaches the backend, then all the logs are saved. One of the most challenging parts of creating logs is for Kubernetes to determine how to gather logs from various containers and then transfer them to a centralized backend. Thankfully, there is a solution for that.

The most efficient method of creating logs is to assign logging agents for each and every node and configuring them in such a way that they forward all the information to one destination. To do so, we can create what is known as a sidecar container.

A sidecar container is a special utility entity. It does not perform any actions on its own, but actually supports the main container. This process is useful to us, as we can simply create a sidecar container to deal with the logs of each container within a pod.

That way, we do not have to worry about managing each and every log file since that is automatically done by the sidecar container. Here is a script that you can use for such a sidecar container:

---6-2_logging-sidecar.yml---

apiVersion: v1

kind: Pod

metadata:

name: myapp

spec:

containers:

- image: busybox

name: application

args:

- /bin/sh

- -c

- >

while true; do

echo "$(date) INFO hello" >> /var/log/myapp.log;

sleep 1;

done

volumeMounts:

- name: log

mountPath: /var/log

- name: sidecar

image: busybox

args:

- /bin/sh

- -c

- tail -fn+1 /var/log/myapp.log

volumeMounts:

- name: log

mountPath: /var/log

volumes:

- name: log

emptyDir: {}

Source: (Baier, 2017)

With that, you have successfully created your monitoring and logging capabilities within Kubernetes.

However, there is much more to logging, especially when we take into consideration Fluentd and Elasticsearch.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.