Skip to content

WIP: k8s kind cloud onboarding #3836

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

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/.pkg
/.cache
/.vscode
/.history
/.eventcache
vendor
data-alloy/
Expand Down
2 changes: 1 addition & 1 deletion example/.gitignore
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions example/kind/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Generated files
build/
# Environment variables for local development
.envrc
7 changes: 7 additions & 0 deletions example/kind/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Alloy example using kind k8s cluster

## Dependencies
- `kind`
- `task` - taskfile.dev
- `kubectl`

56 changes: 56 additions & 0 deletions example/kind/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# https://taskfile.dev

version: "3"

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 update

deploy:cloud-onboarding:local:
desc: Deploy Grafana Cloud Collector helm chart using local checkout
deps: [cluster:create]
cmds:
- helm --kubeconfig {{.KUBECONFIG}} upgrade --install grafana-cloud
-n monitoring --create-namespace
{{.TASK_DIR}}/../../../grafana-cloud-onboarding-helm-chart/charts/grafana-cloud-onboarding/
--values {{.TASK_DIR}}/config/grafana-cloud-onboarding/values.yaml
--set "cluster.name=$(kubectl config current-context)"
--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 Collector helm chart
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 changes: 41 additions & 0 deletions example/kind/config/expose.sh
Original file line number Diff line number Diff line change
@@ -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 for grafana-cloud-collector-alloy-starter daemonset"
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
Empty file.
7 changes: 7 additions & 0 deletions example/kind/config/kind/multinode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
- role: worker