From 22fb898267328a00aa631ae1a8cdd2b0679cebc2 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Sun, 8 Apr 2018 16:26:08 -0500 Subject: [PATCH 1/3] Show how to install and use Stern Stern is super cool to stream the logs of multiple containers. --- slides/kube/logs-cli.md | 125 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 slides/kube/logs-cli.md diff --git a/slides/kube/logs-cli.md b/slides/kube/logs-cli.md new file mode 100644 index 00000000..4bcb8382 --- /dev/null +++ b/slides/kube/logs-cli.md @@ -0,0 +1,125 @@ +# Accessing logs from the CLI + +- The `kubectl logs` commands has limitations: + + - it cannot stream logs from multiple pods at a time + + - when showing logs from multiple pods, it mixes them all + +- We are going to see how to do better + +--- + +## Doing it manually + +- We *could* (if we were so inclined), write a program or script that would: + + - take a selector as an argument + + - enumerate all pods matching that selector (`with kubectl get -l ...`) + + - fork one `kubectl logs --follow ...` command per container + + - annotate the logs (the output of each `kubectl logs ...` process) with their origin + + - preserve ordering by using `kubectl logs --timestamps ...` and merge the output + +-- + +- We *could* do it, but thankfully, others did it for us already! + +--- + +## Stern + +[Stern](https://github.com/wercker/stern) is an open source project +by [Wercker](http://www.wercker.com/). + +From the README: + +*Stern allows you to tail multiple pods on Kubernetes and multiple containers within the pod. Each result is color coded for quicker debugging.* + +*The query is a regular expression so the pod name can easily be filtered and you don't need to specify the exact id (for instance omitting the deployment id). If a pod is deleted it gets removed from tail and if a new is added it automatically gets tailed.* + +Exactly what we need! + +--- + +## Installing Stern + +- For simplicity, let's just grab a binary release + +.exercise[ + +- Download a binary release from GitHub: + ```bash + sudo curl -L -o /usr/local/bin/stern \ + https://github.com/wercker/stern/releases/download/1.6.0/stern_linux_amd64 + sudo chmod +x /usr/local/bin/stern + ``` + +] + +(The installation will differ if you want to run Stern on anything else than a Linux amd64 machine.) + +--- + +## Using Stern + +- There are two ways to specify the pods for which we want to see the logs: + + - `-l` followed by a selector expression (like with many `kubectl` commands) + + - with a "pod query", i.e. a regex used to match pod names + +- These two ways can be combined if necessary + +.exercise[ + +- View the logs for all the rng containers: + ```bash + stern rng + ``` + +] + +--- + +## Stern convenient options + +- The `--tail N` flag shows the last `N` lines for each container + + (Instead of showing the logs since the creation of the container) + +- The `-t` / `--timestamps` flag shows timestamps + +- The `--all-namespaces` flag is self-explanatory + +.exercise[ + +- View what's up with the `weave` system containers: + ```bash + stern --tail 1 --timestamps --all-namespaces weave + ``` +] + +--- + +## Using Stern with a selector + +- When specifying a selector, we can omit the value for a label + +- This will match all objects having that label (regardless of the value) + +- Everything created with `kubectl run` has a label `run` + +- We can use that property to view the logs of all the pods created with `kubectl run` + +.exercise[ + +- View the logs for all the things started with `kubectl run`: + ```bash + stern -l run + ``` + +] From fcea6dbdb6832eb7c2bd2b172cc24fba7dadcf25 Mon Sep 17 00:00:00 2001 From: Jerome Petazzoni Date: Mon, 9 Apr 2018 11:29:19 -0500 Subject: [PATCH 2/3] Clarify Stern installation comments --- slides/kube/logs-cli.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/slides/kube/logs-cli.md b/slides/kube/logs-cli.md index 4bcb8382..06cc9f60 100644 --- a/slides/kube/logs-cli.md +++ b/slides/kube/logs-cli.md @@ -60,7 +60,9 @@ Exactly what we need! ] -(The installation will differ if you want to run Stern on anything else than a Linux amd64 machine.) +These installation instructions will work on our clusters, since they are Linux amd64 VMs. + +However, you will have to adapt them if you want to install Stern on your local machine. --- From a89430673f353e35eee1d6ac74a0f298261fa780 Mon Sep 17 00:00:00 2001 From: Bridget Kromhout Date: Mon, 9 Apr 2018 11:32:02 -0500 Subject: [PATCH 3/3] Update logs-cli.md clarifications --- slides/kube/logs-cli.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/slides/kube/logs-cli.md b/slides/kube/logs-cli.md index 06cc9f60..71674090 100644 --- a/slides/kube/logs-cli.md +++ b/slides/kube/logs-cli.md @@ -4,9 +4,9 @@ - it cannot stream logs from multiple pods at a time - - when showing logs from multiple pods, it mixes them all + - when showing logs from multiple pods, it mixes them all together -- We are going to see how to do better +- We are going to see how to do it better --- @@ -16,7 +16,7 @@ - take a selector as an argument - - enumerate all pods matching that selector (`with kubectl get -l ...`) + - enumerate all pods matching that selector (with `kubectl get -l ...`) - fork one `kubectl logs --follow ...` command per container @@ -39,7 +39,7 @@ From the README: *Stern allows you to tail multiple pods on Kubernetes and multiple containers within the pod. Each result is color coded for quicker debugging.* -*The query is a regular expression so the pod name can easily be filtered and you don't need to specify the exact id (for instance omitting the deployment id). If a pod is deleted it gets removed from tail and if a new is added it automatically gets tailed.* +*The query is a regular expression so the pod name can easily be filtered and you don't need to specify the exact id (for instance omitting the deployment id). If a pod is deleted it gets removed from tail and if a new [pod] is added it automatically gets tailed.* Exactly what we need!