k8s kind example cluster with cloud onboarding helm chart (#3836)

* k8s kind example environment

* move docker-compoese to own dir

* add taskfile and create cluster

* alloy and operator

* add grafana

* add mimir

* fix ignore

* fmt

* add grafana cloud support

* wip

* add local helm chart

* simplify

* wip

* draft

* WIP

* WIP

* rename chart

* improve dev exp

* add otel demo

* remove otel demo for now

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Apply suggestion from @Copilot

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Piotr
2025-09-12 15:03:42 +01:00
committed by GitHub
parent 74b5ee19a9
commit 799e6c057a
19 changed files with 135 additions and 1 deletions

1
.gitignore vendored
View File

@@ -4,6 +4,7 @@
/.pkg
/.cache
/.vscode
/.history
/.eventcache
vendor
data-alloy/

2
example/.gitignore vendored
View File

@@ -1,2 +1,2 @@
# Add here any additional datasources for testing
config/grafana/datasources/datasource-dev.yml
docker-compose/config/grafana/datasources/datasource-dev.yml

View File

@@ -0,0 +1,3 @@
GRAFANA_CLOUD_API_KEY=
REMOTE_CFG_USERNAME=
REMOTE_CFG_URL=

4
example/kind/.gitignore vendored Normal file
View File

@@ -0,0 +1,4 @@
# Generated files
build/
# Environment variables for local development
.env.credentials

17
example/kind/README.md Normal file
View File

@@ -0,0 +1,17 @@
# Alloy example using kind k8s cluster
## Dependencies
- `kind`
- `task` - taskfile.dev
- `kubectl`
- `helm`
## Setup credentials
Create a local `.env.credentials` from the provided template and fill in your values. This file is gitignored and is automatically loaded by Task via `dotenv` in `Taskfile.yml`.
```bash
cp example/kind/.env.credentials.template example/kind/.env.credentials
$EDITOR example/kind/.env.credentials
```

61
example/kind/Taskfile.yml Normal file
View File

@@ -0,0 +1,61 @@
# Install the task command from here: https://taskfile.dev
# It's a much more human-friendly version of Makefiles.
version: "3"
dotenv:
- .env.credentials
vars:
KUBECONFIG: build/kubeconfig.yaml
CLUSTERNAME: alloy-example
tasks:
cluster:create:
desc: Create a kind cluster
run: once
status:
- test -f {{.KUBECONFIG}} && kubectl --kubeconfig {{.KUBECONFIG}} cluster-info &>/dev/null
cmds:
- mkdir -p build
- kind create cluster --config config/kind/multinode.yaml --name {{.CLUSTERNAME}} --kubeconfig {{.KUBECONFIG}}
cluster:delete:
desc: Delete the kind cluster
run: once
cmds:
- kind delete cluster --name {{.CLUSTERNAME}}
- rm -rf {{.KUBECONFIG}}
update-helm-repos:
desc: Update helm repositories
run: once
cmds:
- helm repo add grafana https://grafana.github.io/helm-charts
- helm repo add open-telemetry https://open-telemetry.github.io/opentelemetry-helm-charts
- helm repo update
deploy:cloud-onboarding:local:
desc: Deploy Grafana Cloud Onboarding helm chart
deps: [cluster:create, update-helm-repos]
cmds:
- helm --kubeconfig {{.KUBECONFIG}} upgrade --install grafana-cloud
-n monitoring --create-namespace
grafana/grafana-cloud-onboarding
--set "cluster.name=example-kind-cluster"
--set "grafanaCloud.fleetManagement.auth.password={{.GRAFANA_CLOUD_API_KEY}}"
--set "grafanaCloud.fleetManagement.auth.username={{.REMOTE_CFG_USERNAME}}"
--set "grafanaCloud.fleetManagement.url={{.REMOTE_CFG_URL}}"
--wait
remove:cloud-onboarding:local:
desc: Remove Grafana Cloud Onboarding helm chart
deps: [update-helm-repos]
cmds:
- helm --kubeconfig {{.KUBECONFIG}} uninstall grafana-cloud -n monitoring
expose:
desc: Expose all services on localhost via port-forward
deps: [deploy:cloud-onboarding:local]
cmds:
- "{{.TASK_DIR}}/config/expose.sh {{.KUBECONFIG}}"

41
example/kind/config/expose.sh Executable file
View File

@@ -0,0 +1,41 @@
#!/bin/bash
# Script to expose Grafana Cloud Collector pod via port-forward
KUBECONFIG=${1:-build/kubeconfig.yaml}
# Get the first pod name from the daemonset
POD_NAME=$(kubectl --kubeconfig "$KUBECONFIG" get pods -n monitoring -l app.kubernetes.io/name=alloy-daemon -o jsonpath="{.items[0].metadata.name}")
if [ -z "$POD_NAME" ]; then
echo "Error: No pods found with label 'app.kubernetes.io/name=alloy-daemon' in namespace 'monitoring'"
exit 1
fi
# Start port-forward in background
kubectl --kubeconfig "$KUBECONFIG" port-forward -n monitoring pod/$POD_NAME 12345:12345 &
PORT_FORWARD_PID=$!
# Give port-forward a moment to start
sleep 2
# Print available URL
echo ""
echo "🌐 Service is now available at:"
echo " Alloy: http://localhost:12345"
echo ""
echo "Press Ctrl+C to stop port forwarding"
echo ""
# Function to cleanup background processes
cleanup() {
echo ""
echo "Stopping port forwarding..."
kill $PORT_FORWARD_PID 2>/dev/null || true
exit 0
}
# Set up signal handling
trap cleanup SIGINT SIGTERM
# Wait for background processes
wait

View File

@@ -0,0 +1,7 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker