Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update k3d example to work with k3d v4.0.0 #510

Merged
merged 1 commit into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.