mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 10:13:58 +00:00
50 lines
1.5 KiB
Bash
Executable File
50 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Create a local k3d cluster with only agents that join a remote K3s server.
|
|
# This uses k3s args: --server and --token applied to all agent nodes.
|
|
|
|
set -euo pipefail
|
|
|
|
: "${K3D_CLUSTER_NAME:=knoe-remote-agents}"
|
|
: "${K3D_AGENTS:=2}"
|
|
: "${K3D_IMAGE:=}" # e.g. rancher/k3s:v1.30.6-k3s1
|
|
: "${K3D_REGISTRY_CONFIG:=}" # optional path to registries.yaml
|
|
|
|
# Remote server details
|
|
: "${K3S_REMOTE_SERVER_HOST:=raspberry.prole.org}"
|
|
: "${K3S_REMOTE_SERVER_PORT:=6443}"
|
|
: "${K3S_REMOTE_TOKEN:=}" # required
|
|
|
|
if [[ -z "${K3S_REMOTE_TOKEN}" ]]; then
|
|
echo "[error] K3S_REMOTE_TOKEN is required. Obtain it using k3s/get_remote_k3s_node_token.sh" >&2
|
|
exit 1
|
|
fi
|
|
|
|
SERVER_URL="https://${K3S_REMOTE_SERVER_HOST}:${K3S_REMOTE_SERVER_PORT}"
|
|
|
|
K3D_ARGS=(cluster create "${K3D_CLUSTER_NAME}" \
|
|
--servers 0 \
|
|
--agents "${K3D_AGENTS}" \
|
|
--k3s-arg "--server=${SERVER_URL}@agent:*" \
|
|
--k3s-arg "--token=${K3S_REMOTE_TOKEN}@agent:*"
|
|
)
|
|
|
|
if [[ -n "${K3D_IMAGE}" ]]; then
|
|
K3D_ARGS+=(--image "${K3D_IMAGE}")
|
|
fi
|
|
|
|
if [[ -n "${K3D_REGISTRY_CONFIG}" ]]; then
|
|
if [[ ! -f "${K3D_REGISTRY_CONFIG}" ]]; then
|
|
echo "[error] Registry config not found: ${K3D_REGISTRY_CONFIG}" >&2
|
|
exit 1
|
|
fi
|
|
K3D_ARGS+=(--registry-config "${K3D_REGISTRY_CONFIG}")
|
|
fi
|
|
|
|
echo "[info] Creating k3d agents-only cluster '${K3D_CLUSTER_NAME}' joining ${SERVER_URL}"
|
|
set -x
|
|
k3d "${K3D_ARGS[@]}"
|
|
set +x
|
|
|
|
echo "[ok] k3d cluster '${K3D_CLUSTER_NAME}' created with ${K3D_AGENTS} agent(s) joining ${SERVER_URL}"
|