Skip to content

Commit

Permalink
update k3d example to work with k3d v4.0.0 (#510)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfratto authored Apr 2, 2021
1 parent 182b962 commit 80ee10c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 51 deletions.
13 changes: 5 additions & 8 deletions example/k3d/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ that
- Kubectl
- Docker
- [Tanka >= v0.9.2](https://github.com/grafana/tanka)
- [k3d >= v1.5.1 < v3.0.0](https://github.com/rancher/k3d)
- [k3d >= v4.0.0](https://github.com/rancher/k3d)

## Getting Started

Expand All @@ -21,17 +21,14 @@ Run the following to create your cluster:
# Create a new k3d cluster
./scripts/create.bash

# Merge the k3d cluster config with your local kubectl config
./scripts/merge_k3d.bash

# Import images into k3d if they are not available on docker hub
k3d import-images -n agent-k3d grafana/agent
k3d import-images -n agent-k3d grafana/agentctl
k3d image import -c agent-k3d grafana/agent:latest
k3d image import -c agent-k3d grafana/agentctl:latest

tk apply ./environment

# Navigate to localhost:30080 in your browser to view dashboards
# Navigate to grafana.k3d.localhost:30080 in your browser to view dashboards

# Delete the k3d cluster when you're done with it
k3d delete -n agent-k3d
k3d cluster delete agent-k3d
```
22 changes: 14 additions & 8 deletions example/k3d/environment/main.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ local k = import 'ksonnet-util/kausal.libsonnet';
local loki_config = import 'default/loki_config.libsonnet';
local grafana_agent = import 'grafana-agent/v1/main.libsonnet';

local ingress = k.networking.v1beta1.ingress;
local path = k.networking.v1beta1.httpIngressPath;
local rule = k.networking.v1beta1.ingressRule;
local service = k.core.v1.service;

local images = {
agent: 'grafana/agent:latest',
agentctl: 'grafana/agentctl:latest',
Expand All @@ -15,14 +19,16 @@ local images = {
{
default: default.new(namespace='default') {
grafana+: {
// Expose Grafana on 30080 on the k3d agent, which is exposed to the host
// machine.
service+:
local bindNodePort(port) = port { nodePort: port.port + 30000 };
service.mixin.spec.withPorts([
{ name: 'grafana', nodePort: 30080, port: 30080, targetPort: 80 },
]) +
service.mixin.spec.withType('NodePort'),
ingress+:
ingress.new('grafana-ingress') +
ingress.mixin.spec.withRules([
rule.withHost('grafana.k3d.localhost') +
rule.http.withPaths([
path.withPath('/')
+ path.backend.withServiceName('grafana')
+ path.backend.withServicePort(80),
]),
]),
},
},

Expand Down
2 changes: 1 addition & 1 deletion example/k3d/environment/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "default"
},
"spec": {
"apiServer": "https://localhost:50443",
"apiServer": "https://0.0.0.0:50443",
"namespace": "default"
}
}
10 changes: 6 additions & 4 deletions example/k3d/scripts/create.bash
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env bash

k3d create \
--name agent-k3d \
--publish 30080:30080 \
k3d cluster create agent-k3d \
--port 30080:80@loadbalancer \
--api-port 50443 \
-v /var/lib/k3d/agent-k3d/storage/:/var/lib/rancher/k3s/storage/ \
-v /etc/machine-id:/etc/machine-id
-v /etc/machine-id:/etc/machine-id \
--kubeconfig-update-default=true \
--kubeconfig-switch-context=true \
--wait
30 changes: 0 additions & 30 deletions example/k3d/scripts/merge_k3d.bash

This file was deleted.

0 comments on commit 80ee10c

Please sign in to comment.