Refresher on deploying
Deploying to Kubernetes using kubectl
Section titled “Deploying to Kubernetes using kubectl”To understand how Tanka works, it is important to know what steps are required for the task of deploying Grafana and Prometheus to Kubernetes:
- Prometheus
- A Deploymentmust be created, to run theprom/prometheusimage
- Also a Serviceis needed for Grafana to be able to connect port9090of Prometheus.
 
- A 
- Grafana
- Another Deploymentis required for the Grafana server.
- To connect to the web interface, we will be using a Serviceof typeNodePort.
 
- Another 
Before taking a look how Tanka can help doing so, let’s recall how to do it with
plain kubectl.
Writing the yaml
Section titled “Writing the yaml”kubectl expects the resources it should create in .yaml format.
For Grafana:
# Grafana server DeploymentapiVersion: apps/v1kind: Deploymentmetadata:  name: grafanaspec:  selector:    matchLabels:      name: grafana  template:    metadata:      labels:        name: grafana    spec:      containers:        - image: grafana/grafana          name: grafana          ports:            - containerPort: 3000              name: ui---# Grafana UI Service NodePortapiVersion: v1kind: Servicemetadata:  labels:    name: grafana  name: grafanaspec:  ports:    - name: grafana-ui      port: 3000      targetPort: 3000  selector:    name: grafana  type: NodePortand for Prometheus:
# Prometheus server DeploymentapiVersion: apps/v1kind: Deploymentmetadata:  name: prometheusspec:  selector:    matchLabels:      name: prometheus  template:    metadata:      labels:        name: prometheus    spec:      containers:        - image: prom/prometheus          name: prometheus          ports:            - containerPort: 9090              name: api---# Prometheus API ServiceapiVersion: v1kind: Servicemetadata:  labels:    name: prometheus  name: prometheusspec:  ports:    - name: prometheus-api      port: 9090      targetPort: 9090  selector:    name: prometheusThat’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.
Deploying to the cluster
Section titled “Deploying to the cluster”To actually apply those resources, copy them into .yaml files and use:
kubectl apply -f prometheus.yaml -f grafana.yamldeployment.apps/grafana createddeployment.apps/prometheus createdservice/grafana createdservice/prometheus createdChecking it worked
Section titled “Checking it worked”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 localhostkubectl port-forward deployments/grafana 8080:3000Now go to http://localhost:8080 in your browser and login using admin:admin.
Then navigate to Connections > Data sources > Add new 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
thing in dev and prod your choices are very limited.
Let’s explore how Tanka can help us here in the next section!
Cleaning up
Section titled “Cleaning up”Let’s remove everything we created to start fresh with Jsonnet in the next section:
kubectl delete -f prometheus.yaml -f grafana.yaml