Refresher on deploying
To understand how Tanka works, it is important to know what steps are required for the task of deploying Grafana and Prometheus to Kubernetes:
Deploymentmust be created, to run the
- Also a
Serviceis needed for Grafana to be able to connect port
Deploymentis required for the Grafana server.
- To connect to the web interface, we will be using a
Before taking a look how Tanka can help doing so, let's recall how to do it with
kubectl expects the resources it should create in
.yaml format. For Grafana
# Grafana server Deployment apiVersion: apps/v1 kind: Deployment metadata: name: grafana spec: selector: matchLabels: name: grafana template: metadata: labels: name: grafana spec: containers: - image: grafana/grafana name: grafana ports: - containerPort: 3000 name: ui
... and for Prometheus:
# Prometheus server Deployment apiVersion: apps/v1 kind: Deployment metadata: name: prometheus spec: selector: matchLabels: name: prometheus template: metadata: labels: name: prometheus spec: containers: - image: prom/prometheus name: prometheus ports: - containerPort: 9090 name: api
That's pretty verbose, right?
Even worse, there are labels and matchers (e.g.
prometheus) that need to be
exactly the same scattered across the file. It's a nightmare to debug and
furthermore harms readability a lot.
To actually apply those resources, copy them into
.yaml files and use:
$ kubectl apply -f prometheus.yaml -f grafana.yaml deployment.apps/grafana created deployment.apps/prometheus created service/grafana created service/prometheus created
So far so good, but can we tell it actually did what we wanted? Let's test that Grafana can connect to Prometheus!
# Temporarily forward Grafana to localhost kubectl port-forward deployments/grafana 8080:3000
Now go to http://localhost:8080 in your browser and login using
Then navigate to
Configuration > Data Sources > Add data source, choose
Prometheus as type and enter
http://prometheus:9090 as URL. Hit
Save & Test which should yield a big green bar telling you everything is good.
Cool! This worked out well for this small example, but the
.yaml files are
hard to read and maintain. Especially when you need to deploy this exact same
prod your choices are very limited.
Let's explore how Tanka can help us here in the next section!
Let's remove everything we created to start fresh with Jsonnet in the next section:
$ kubectl delete -f prometheus.yaml -f grafana.yaml