Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: thanos-io/thanos
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: metalmatze/thanos
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 1 commit
  • 6 files changed
  • 1 contributor

Commits on Nov 27, 2020

  1. Create kube-thanos Katacoda tutorial

    Signed-off-by: Matthias Loibl <[email protected]>
    metalmatze committed Nov 27, 2020
    Copy the full SHA
    753ca78 View commit details
5 changes: 5 additions & 0 deletions tutorials/katacoda/thanos-pathway.json
Original file line number Diff line number Diff line change
@@ -23,6 +23,11 @@
"title": "Advanced: Achieving Multi-Tenancy with Thanos",
"description": "Extend your Prometheus setup for Multiple Teams use with Thanos."
},
{
"course_id": "9-kube-thanos",
"title": "Intro: kube-thanos - Kubernetes specific configuration for deploying Thanos",
"description": "Learn how to generate your Kubernetes YAML with kube-thanos."
},
{
"course_id": "x-playground",
"title": "Playground: All-in, Interactive Thanos un-guided Demo",
6 changes: 6 additions & 0 deletions tutorials/katacoda/thanos/9-kube-thanos/courseBase.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

GO111MODULE="on" go get github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@v0.4.0
GO111MODULE="on" go get github.com/brancz/gojsontoyaml
GO111MODULE="on" go get github.com/google/go-jsonnet/cmd/jsonnet@v0.17.0
GO111MODULE="on" go get github.com/google/go-jsonnet/cmd/jsonnetfmt@v0.17.0
33 changes: 33 additions & 0 deletions tutorials/katacoda/thanos/9-kube-thanos/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"title": "Intro: kube-thanos - Kubernetes specific configuration for deploying Thanos",
"description": "Learn how to generate your Kubernetes YAML with kube-thanos.",
"difficulty": "Beginner",
"time": "10-15 Minutes",
"details": {
"steps": [
{
"title": "Install kube-thanos as a dependency",
"text": "step-01.md"
},
{
"title": "Generating the Thanos Query YAML",
"text": "step-02.md"
}
],
"intro": {
"text": "intro.md",
"courseData": "courseBase.sh",
"credits": "https://thanos.io"
}
},
"files": [],
"environment": {
"uilayout": "editor-terminal",
"uisettings": "yaml",
"showdashboard": true,
"dashboards": []
},
"backend": {
"imageid": "golang:1.14"
}
}
30 changes: 30 additions & 0 deletions tutorials/katacoda/thanos/9-kube-thanos/intro.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Welcome to the kube-thanos Katacoda!

[Thanos](https://thanos.io) is a set of components that can be composed into a highly available metric system with unlimited storage capacity.
It can be added seamlessly on top of existing Prometheus deployments.

[kube-thanos](https://github.com/thanos-io/kube-thanos) collects [Kubernetes](https://kubernetes.io/) manifests combined with documentation and scripts to provide easy to deploy experience for Thanos on Kubernetes.

### Jsonnet

kube-thanos generates the YAML using [jsonnet](https://jsonnet.org/). Jsonnet is a data templating language based on JSON.
It adds some cool additional features to JSON like if-conditions, loops and functions. Most importantly we can generate default JSON, that in turn can later be customized to your needs without us having to tweak kube-thanos for every possible scenario!
This Katacoda comes with the `jsonnet`{{execute}} and `jsonnetfmt`{{execute}} binaries pre-installed (via go get).

### jsonnet-bundler

To fetch extra dependencies (like kube-thanos), we came up with a tool called [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler).
Once you initialized a project it's very simliar to [bundler](https://bundler.io/) or [npm](https://www.npmjs.com/).
It'll fetch dependencies via `git` and write them to a `jsonnetfile.json` and a `jsonnetfile.lock.json`.
The latter saves the specific revision/hash of the dependency you've added for max reproducibility.

Let's jump in! 🤓

### Feedback

Do you see any bug, typo in the tutorial or you have some feedback for us?
Let us know on https://github.com/thanos-io/kube-thanos or #thanos slack channel linked on https://thanos.io

### Contributed by:

* Matthias Loibl [@metalmatze](https://github.com/metalmatze)
25 changes: 25 additions & 0 deletions tutorials/katacoda/thanos/9-kube-thanos/step-01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Step 1 - Install kube-thanos as a dependency

Let's start by initializing our development environment by running `jb init`{{execute}}.
Under normal circumstances you would want to run this command in the repository/directory where the rest of your YAML is saved.

_If you see `bash: jb: command not found` retry the command in a few seconds, jb is still being installed._

Check the contents of the `jsonnetfile.json`:
```
cat jsonnetfile.json
```{{execute}}
### Add kube-thanos
Now we can add kube-thanos as our dependency:
```
jb install github.com/thanos-io/kube-thanos/jsonnet/kube-thanos
```{{execute}}
Jsonnet-bundler has pulled down the latest `master` branch and saved its contents to `vendor/github.com/thanos-io/kube-thanos`.
Additionally the version that has been written to disk has been saved in the `jsonnetfile.lock.json`.
```
cat jsonnetfile.lock.json
```{{execute}}
44 changes: 44 additions & 0 deletions tutorials/katacoda/thanos/9-kube-thanos/step-02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Step 2 - Simple example - generating Thanos Query YAML

Now that we have installed kube-thanos as a dependency, we can start using it.
We want to create a first jsonnet file where we import kube-thanos and then call its `query()` function.

<pre class="file" data-filename="simple.jsonnet" data-target="replace">
local thanos = import 'github.com/thanos-io/kube-thanos/jsonnet/kube-thanos/thanos.libsonnet';

local query = thanos.query({
namespace: 'monitoring',
version: 'v0.17.1',
image: 'quay.io/thanos/thanos',
replicas: 1,
replicaLabels: ['replica'],
});

{
apiVersion: 'v1',
kind: 'List',
items: [
query[name] for name in std.objectFields(query)
],
}
</pre>

Now, for the first time we are going to use the `jsonnet` binary to actually generate something.
Because we have a import statement we need to tell jsonnet where to find these imports from.
Jsonnet-bundler is saving these dependencies to `vendor/` and therefore we have to run `jsonnet` with the `-J vendor` flag.

```
jsonnet -J vendor simple.jsonnet > simple.yaml
```{{execute}}
As you can see, we get a Kubernetes _List_ object that contains several other Kubernetes objects like _Services_, _Deployments_ and more.
All of this is JSON though, so wouldn't it be great to generate YAML instead?
Turns out it's easy to convert JSON to YAML and there is a simple tool called `gojsontoyaml`.
```
jsonnet -J vendor simple.jsonnet | gojsontoyaml > simple.yaml
```{{execute}}
Perfect. There is our first example.
You can try adjusting the `replica` count in the simple.jsonnet and generate again. It should update :)