Compare commits
162
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
99cae11da3 | ||
|
|
eb7794962f | ||
|
|
f25d2fdfe9 | ||
|
|
2b5637516a | ||
|
|
ce6173b06a | ||
|
|
22dfe9a26b | ||
|
|
185e0c96d5 | ||
|
|
e55e46d020 | ||
|
|
cf139cd580 | ||
|
|
0623e151bb | ||
|
|
17a8061722 | ||
|
|
f6a708e897 | ||
|
|
b8516bae50 | ||
|
|
6d05f426d0 | ||
|
|
0466bd6929 | ||
|
|
8f9b6fda24 | ||
|
|
6ad6007df4 | ||
|
|
c5e545ef33 | ||
|
|
9d11189f3d | ||
|
|
5dde0da0d2 | ||
|
|
d93d1810f1 | ||
|
|
cdf033686a | ||
|
|
b1aff90ffd | ||
|
|
c6aa571a5c | ||
|
|
ffe976fb16 | ||
|
|
17648b53ae | ||
|
|
46b6593682 | ||
|
|
52e780f4af | ||
|
|
99f5f58a08 | ||
|
|
c2bd27c9a7 | ||
|
|
b21d5fc268 | ||
|
|
3d5b2ba097 | ||
|
|
3320f11e4b | ||
|
|
39dbfafe1c | ||
|
|
356f5b7ad4 | ||
|
|
6647d55050 | ||
|
|
13330ef3fb | ||
|
|
855d1cce85 | ||
|
|
9b388ff8e2 | ||
|
|
0d5f49591a | ||
|
|
12400b4c83 | ||
|
|
05bec1a5ff | ||
|
|
f6f74d9977 | ||
|
|
f2b8704914 | ||
|
|
be09d7592f | ||
|
|
abac1bf532 | ||
|
|
282e1c5236 | ||
|
|
339dcdd214 | ||
|
|
9b15ea5d33 | ||
|
|
344f748b84 | ||
|
|
84cf39e7d9 | ||
|
|
afc9fd36d7 | ||
|
|
3e6c8188da | ||
|
|
4c3a2b4226 | ||
|
|
c40fc0caac | ||
|
|
49fd2ba307 | ||
|
|
85ce271fd6 | ||
|
|
7548402542 | ||
|
|
9e0ce35712 | ||
|
|
c1e409780d | ||
|
|
5a2d32ea84 | ||
|
|
e3fab0e151 | ||
|
|
a1867b18c8 | ||
|
|
71b0f3ce7d | ||
|
|
d0600b9153 | ||
|
|
7acf83e68d | ||
|
|
088cb5add1 | ||
|
|
b04ab52fd2 | ||
|
|
ff2b565677 | ||
|
|
4b22f4ad11 | ||
|
|
020b277a04 | ||
|
|
ba53cbc465 | ||
|
|
b4d27c6546 | ||
|
|
481ff9e7ac | ||
|
|
5865c38ea7 | ||
|
|
4f90febc89 | ||
|
|
739e0ff111 | ||
|
|
897813a916 | ||
|
|
5cd50c31ff | ||
|
|
098c1c93c2 | ||
|
|
7c2a37abdb | ||
|
|
9a884acc22 | ||
|
|
812d1ba1c5 | ||
|
|
c08f9df9af | ||
|
|
dac1a98029 | ||
|
|
90c3d37e74 | ||
|
|
19bf92d6bc | ||
|
|
afac1f338f | ||
|
|
2f57f1822f | ||
|
|
07c4678a6d | ||
|
|
fb1f8db36b | ||
|
|
0ae688ac66 | ||
|
|
b7d5a5c5cd | ||
|
|
10a4578ce4 | ||
|
|
3f98874008 | ||
|
|
e830eb3b40 | ||
|
|
ca940be8fa | ||
|
|
ddf3ff9717 | ||
|
|
05208ca802 | ||
|
|
ce5b61dba4 | ||
|
|
dd6fc1dfeb | ||
|
|
d7d9444a2b | ||
|
|
f8f14db80a | ||
|
|
ea35bb55e4 | ||
|
|
7a54674ba2 | ||
|
|
93a5eac028 | ||
|
|
21c3d0402e | ||
|
|
189fe17cf6 | ||
|
|
0d233c1544 | ||
|
|
71732df894 | ||
|
|
135458c9ac | ||
|
|
b803ec937c | ||
|
|
bcccd79148 | ||
|
|
7274953cd2 | ||
|
|
3b1c2f4901 | ||
|
|
8b913e921f | ||
|
|
e502c918b1 | ||
|
|
6753be7f09 | ||
|
|
13549a8d37 | ||
|
|
6b3ed077ee | ||
|
|
bceebacf7e | ||
|
|
551b035db9 | ||
|
|
76e8697253 | ||
|
|
2c7d13eded | ||
|
|
24bb67ce2c | ||
|
|
68bd4092d3 | ||
|
|
ce7e9d5633 | ||
|
|
d274bd695c | ||
|
|
4ccb1884f9 | ||
|
|
c5f8a86451 | ||
|
|
b13a808c93 | ||
|
|
64b83c04de | ||
|
|
284f338e68 | ||
|
|
8ea8c8ede8 | ||
|
|
79fe68b577 | ||
|
|
dd6fa942cb | ||
|
|
021711f721 | ||
|
|
9c77acd034 | ||
|
|
45fc56af3e | ||
|
|
b61759c3c0 | ||
|
|
0c9692812c | ||
|
|
37395e3a4d | ||
|
|
c8f606fd20 | ||
|
|
cbcb829137 | ||
|
|
64ef076350 | ||
|
|
f89822e4f7 | ||
|
|
94be23def7 | ||
|
|
19af76fd2b | ||
|
|
354cf65657 | ||
|
|
61758cbb67 | ||
|
|
c97bebd327 | ||
|
|
9ffc1bc94e | ||
|
|
cc40873bb4 | ||
|
|
c4a7ea185a | ||
|
|
3f874e6f97 | ||
|
|
5de2a16b9b | ||
|
|
54b97fadeb | ||
|
|
f22cad1a37 | ||
|
|
113de6fb46 | ||
|
|
8420c33f69 | ||
|
|
786974fca3 | ||
|
|
7cdc35d696 |
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
# Old Gitea token in deleted .env.local. Confirmed revoked (API returned 401) on 2026-11-22.
|
||||||
|
8c69ec772ab5f0df73fa2614e5b8b22adb9bbd15:.env.local:gitea-access-token:2
|
||||||
Executable
+37
@@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Stop hook: makes Claude fix TypeScript errors before it can finish a reply.
|
||||||
|
#
|
||||||
|
# Why: CLAUDE.md tells Claude to run `npm run typecheck` after editing a stack,
|
||||||
|
# but an instruction can be forgotten. A hook can't: Claude Code runs it itself.
|
||||||
|
#
|
||||||
|
# When: "Stop" is the Claude Code event that fires every time Claude finishes a
|
||||||
|
# reply. It has nothing to do with Gitea issues or tickets.
|
||||||
|
#
|
||||||
|
# What: for every stack (01-..05-) with uncommitted .ts changes, run
|
||||||
|
# `npm run typecheck`. If one fails, exit 2 sends the errors back to Claude and
|
||||||
|
# it has to keep working. If nothing changed, it does nothing.
|
||||||
|
#
|
||||||
|
# Not included: `pulumi preview`. It's slow and needs credentials, so it stays a
|
||||||
|
# manual step (see "Verifying changes" in CLAUDE.md).
|
||||||
|
#
|
||||||
|
# Idea taken from the deverenz repo (.claude/hooks/check-on-stop.sh).
|
||||||
|
input=$(cat)
|
||||||
|
# Set when Claude is already continuing because of this hook; stopping here
|
||||||
|
# prevents an endless loop if it can't fix the error.
|
||||||
|
[[ "$(jq -r '.stop_hook_active // false' <<<"$input")" == "true" ]] && exit 0
|
||||||
|
cd "$CLAUDE_PROJECT_DIR" || exit 0
|
||||||
|
|
||||||
|
# -uall lists files inside new folders, not just the folder.
|
||||||
|
stacks=$(git status --porcelain -uall | grep -oE '0[1-5]-[a-z0-9-]+/.*\.ts$' | cut -d/ -f1 | sort -u)
|
||||||
|
|
||||||
|
failed=0
|
||||||
|
for stack in $stacks; do
|
||||||
|
[[ -f "$stack/package.json" && -d "$stack/node_modules" ]] || continue
|
||||||
|
if ! out=$(npm run --silent --prefix "$stack" typecheck 2>&1); then
|
||||||
|
echo "typecheck failed in $stack, fix before finishing:" >&2
|
||||||
|
tail -n 30 <<<"$out" >&2
|
||||||
|
failed=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[[ $failed -eq 1 ]] && exit 2
|
||||||
|
exit 0
|
||||||
Executable
+41
@@ -0,0 +1,41 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# PreToolUse hook for Bash: forces a permission prompt before any command that
|
||||||
|
# changes live infrastructure. The ask rules in .claude/settings.json match the
|
||||||
|
# command text as Claude usually writes it; this catches the same commands when
|
||||||
|
# they are wrapped (sh -c '...', env VAR=x ..., absolute paths).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
input=$(cat)
|
||||||
|
cmd=$(jq -r '.tool_input.command // empty' <<<"$input")
|
||||||
|
cwd=$(jq -r '.cwd // empty' <<<"$input")
|
||||||
|
|
||||||
|
[ -z "$cmd" ] && exit 0
|
||||||
|
|
||||||
|
# A subcommand must follow whitespace, so flags like `preview --refresh` don't match.
|
||||||
|
# It may be followed by a closing quote or paren when the command is wrapped.
|
||||||
|
end="([[:space:]\"')]|\$)"
|
||||||
|
pulumi_re="pulumi[[:space:]]+([^|;&]*[[:space:]])?(up|destroy|refresh|import|state|cancel)$end"
|
||||||
|
kubectl_re="kubectl[[:space:]]+([^|;&]*[[:space:]])?(apply|delete|patch|edit|replace|create|drain|cordon|uncordon|taint|scale|rollout|exec|annotate|label|set|cp)$end"
|
||||||
|
ssh_re='(^|[^[:alnum:]_./-])(ssh|scp)[[:space:]]'
|
||||||
|
|
||||||
|
what=""
|
||||||
|
if [[ $cmd =~ $pulumi_re ]]; then
|
||||||
|
what="pulumi ${BASH_REMATCH[2]}"
|
||||||
|
elif [[ $cmd =~ $kubectl_re ]]; then
|
||||||
|
what="kubectl ${BASH_REMATCH[2]}"
|
||||||
|
elif [[ $cmd =~ $ssh_re ]]; then
|
||||||
|
what="${BASH_REMATCH[2]} to a node"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -z "$what" ] && exit 0
|
||||||
|
|
||||||
|
stack=$(grep -oE '0[1-5]-[a-z0-9-]+' <<<"$cmd $cwd" | head -n 1 || true)
|
||||||
|
reason="Live infrastructure: '$what'${stack:+ in $stack}. Approve only if you want Claude to run this instead of running it yourself."
|
||||||
|
|
||||||
|
jq -n --arg reason "$reason" '{
|
||||||
|
hookSpecificOutput: {
|
||||||
|
hookEventName: "PreToolUse",
|
||||||
|
permissionDecision: "ask",
|
||||||
|
permissionDecisionReason: $reason
|
||||||
|
}
|
||||||
|
}'
|
||||||
Executable
+84
@@ -0,0 +1,84 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Gitea API helper so Claude Code can work with pull requests.
|
||||||
|
#
|
||||||
|
# Why: the remote is a self-hosted Gitea, so the GitHub CLI `gh` doesn't work.
|
||||||
|
# This script calls the Gitea API instead, as the claude-bot account, so PRs
|
||||||
|
# show up as the bot's work and it only has the rights you gave it.
|
||||||
|
#
|
||||||
|
# Scope: used for PRs only (list, open, check CI status, merge after your OK).
|
||||||
|
# Technically it can call any endpoint; CLAUDE.md limits its use to PRs.
|
||||||
|
# In .claude/settings.json, GET and POST (e.g. opening a PR) run without a
|
||||||
|
# prompt. Merging a PR (POST .../merge), PATCH, PUT and DELETE always ask first.
|
||||||
|
#
|
||||||
|
# Usage: gitea.sh METHOD PATH [BODY]
|
||||||
|
# METHOD GET | POST | PATCH | PUT | DELETE
|
||||||
|
# PATH path below /api/v1, e.g. /repos/kasun/homelab-infrastructure-as-code/pulls?state=open
|
||||||
|
# BODY JSON string, or @file to send a file
|
||||||
|
#
|
||||||
|
# Read-only CI wait: gitea.sh WAIT /repos/OWNER/REPO/commits/SHA/status
|
||||||
|
# Polls until checks finish. Exit 0: passed or no CI ran. 1: a check failed.
|
||||||
|
# 2: bad usage. 3: timed out after 15 minutes.
|
||||||
|
#
|
||||||
|
# Config (outside the repo, never committed):
|
||||||
|
# ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/url e.g. http://192.168.1.208:3000
|
||||||
|
# ${XDG_CONFIG_HOME:-~/.config}/homelab-agent/token chmod 600
|
||||||
|
# Token: Site Administration → Identity & Access → User Accounts → claude-bot → generate
|
||||||
|
# (write:repository, write:issue). claude-bot is a collaborator with Write on the repo.
|
||||||
|
#
|
||||||
|
# Adapted from the deverenz repo (.claude/scripts/gitea.sh).
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
method=${1:?usage: gitea.sh METHOD PATH [BODY]}
|
||||||
|
path=${2:?usage: gitea.sh METHOD PATH [BODY]}
|
||||||
|
body=${3:-}
|
||||||
|
|
||||||
|
if [[ "$method" == "WAIT" ]]; then
|
||||||
|
[[ "$path" =~ ^/repos/[^/]+/[^/]+/commits/[0-9a-f]{40}/status$ ]] \
|
||||||
|
|| { echo "WAIT only accepts /repos/OWNER/REPO/commits/SHA/status" >&2; exit 2; }
|
||||||
|
for ((i = 1; i <= 45; i++)); do
|
||||||
|
status=$("$0" GET "$path") || status='{}'
|
||||||
|
total=$(jq '.statuses // [] | length' <<<"$status")
|
||||||
|
running=$(jq '[.statuses // [] | .[] | select(.status == "pending" or .status == "running")] | length' <<<"$status")
|
||||||
|
# Give checks time to register. Path-filtered workflows may never start any.
|
||||||
|
if (( total == 0 && i >= 7 )); then
|
||||||
|
echo "no CI ran"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
if (( total > 0 && running == 0 && i >= 4 )); then
|
||||||
|
jq -r '.statuses[] | "\(.context): \(.status) \(.target_url)"' <<<"$status"
|
||||||
|
jq -e '[.statuses[].status] | any(. == "failure" or . == "error") | not' <<<"$status" >/dev/null || exit 1
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
sleep 20
|
||||||
|
done
|
||||||
|
echo "timed out waiting for CI" >&2
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
case "$method" in
|
||||||
|
GET | POST | PATCH | PUT | DELETE) ;;
|
||||||
|
*) echo "unsupported method: $method" >&2; exit 2 ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
config=${XDG_CONFIG_HOME:-$HOME/.config}/homelab-agent
|
||||||
|
for f in url token; do
|
||||||
|
[[ -s "$config/$f" ]] || { echo "missing $config/$f" >&2; exit 2; }
|
||||||
|
done
|
||||||
|
url=$(<"$config/url")
|
||||||
|
token=$(<"$config/token")
|
||||||
|
|
||||||
|
args=(-sS --fail-with-body -X "$method" -H "Accept: application/json")
|
||||||
|
# The token header is read from stdin so it never shows up in the process list.
|
||||||
|
args+=(-H @-)
|
||||||
|
if [[ -n "$body" ]]; then
|
||||||
|
[[ "$body" == "@-" ]] && { echo "BODY from stdin is not supported, use @file" >&2; exit 2; }
|
||||||
|
args+=(-H "Content-Type: application/json" --data-binary "$body")
|
||||||
|
fi
|
||||||
|
|
||||||
|
out=$(curl "${args[@]}" "${url%/}/api/v1${path}" <<<"Authorization: token $token") \
|
||||||
|
|| { echo "$out" >&2; exit 1; }
|
||||||
|
if command -v jq >/dev/null && [[ -n "$out" ]]; then
|
||||||
|
jq . <<<"$out" 2>/dev/null || echo "$out"
|
||||||
|
else
|
||||||
|
echo "$out"
|
||||||
|
fi
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"defaultMode": "plan",
|
||||||
|
"disableAutoMode": "disable",
|
||||||
|
"allow": [
|
||||||
|
"Bash(pulumi preview *)",
|
||||||
|
"Bash(pulumi stack ls *)",
|
||||||
|
"Bash(pulumi whoami *)",
|
||||||
|
"Bash(pulumi version *)",
|
||||||
|
"Bash(pulumi stack output *)",
|
||||||
|
"Bash(pulumi stack history *)",
|
||||||
|
"Bash(pulumi config)",
|
||||||
|
"Bash(pulumi config get *)",
|
||||||
|
"Bash(npm ci)",
|
||||||
|
"Bash(npm install)",
|
||||||
|
"Bash(npm run typecheck *)",
|
||||||
|
"Bash(npx tsc *)",
|
||||||
|
"Bash(kubectl get *)",
|
||||||
|
"Bash(kubectl describe *)",
|
||||||
|
"Bash(kubectl logs *)",
|
||||||
|
"Bash(kubectl top *)",
|
||||||
|
"Bash(kubectl config get-contexts *)",
|
||||||
|
"Bash(git log *)",
|
||||||
|
"Bash(git status *)",
|
||||||
|
"Bash(git diff *)",
|
||||||
|
"Bash(git show *)",
|
||||||
|
"Bash(git grep *)",
|
||||||
|
"Bash(git blame *)",
|
||||||
|
"Bash(git ls-files *)",
|
||||||
|
"Bash(git ls-tree *)",
|
||||||
|
"Bash(git rev-parse *)",
|
||||||
|
"Bash(git describe *)",
|
||||||
|
"Bash(git shortlog *)",
|
||||||
|
"Bash(git merge-base *)",
|
||||||
|
"Bash(git reflog show *)",
|
||||||
|
"Bash(git stash list *)",
|
||||||
|
"Bash(git branch --list *)",
|
||||||
|
"Bash(git branch -a *)",
|
||||||
|
"Bash(git branch -v *)",
|
||||||
|
"Bash(git tag --list *)",
|
||||||
|
"Bash(git remote -v)",
|
||||||
|
"Bash(git fetch *)",
|
||||||
|
"Bash(pulumi about *)",
|
||||||
|
"Bash(pulumi plugin ls *)",
|
||||||
|
"Bash(kubectl api-resources *)",
|
||||||
|
"Bash(kubectl api-versions *)",
|
||||||
|
"Bash(kubectl explain *)",
|
||||||
|
"Bash(kubectl version *)",
|
||||||
|
"Bash(kubectl events *)",
|
||||||
|
"Bash(kubectl cluster-info)",
|
||||||
|
"Bash(kubectl auth can-i *)",
|
||||||
|
"Bash(kubectl rollout status *)",
|
||||||
|
"Bash(kubectl rollout history *)",
|
||||||
|
"Bash(kubectl config current-context *)",
|
||||||
|
"Bash(npm ls *)",
|
||||||
|
"Bash(npm outdated *)",
|
||||||
|
"Bash(ls *)",
|
||||||
|
"Bash(pwd)",
|
||||||
|
"Bash(wc *)",
|
||||||
|
"Bash(which *)",
|
||||||
|
"Bash(jq *)",
|
||||||
|
"Bash(git add *)",
|
||||||
|
"Bash(git switch *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh GET *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh WAIT *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh POST *)",
|
||||||
|
"Bash(git commit *)",
|
||||||
|
"Bash(git push *)",
|
||||||
|
"WebFetch(domain:www.pulumi.com)",
|
||||||
|
"WebFetch(domain:github.com)",
|
||||||
|
"WebFetch(domain:raw.githubusercontent.com)",
|
||||||
|
"WebFetch(domain:kube-vip.io)",
|
||||||
|
"WebFetch(domain:longhorn.io)",
|
||||||
|
"WebFetch(domain:registry.terraform.io)"
|
||||||
|
],
|
||||||
|
"ask": [
|
||||||
|
"Bash(pulumi up *)",
|
||||||
|
"Bash(pulumi destroy *)",
|
||||||
|
"Bash(pulumi refresh *)",
|
||||||
|
"Bash(pulumi import *)",
|
||||||
|
"Bash(pulumi state *)",
|
||||||
|
"Bash(pulumi config set *)",
|
||||||
|
"Bash(pulumi config rm *)",
|
||||||
|
"Bash(kubectl get secret*)",
|
||||||
|
"Bash(kubectl config set*)",
|
||||||
|
"Bash(kubectl config use-context *)",
|
||||||
|
"Bash(kubectl config delete*)",
|
||||||
|
"Bash(kubectl config rename-context *)",
|
||||||
|
"Bash(kubectl apply *)",
|
||||||
|
"Bash(kubectl delete *)",
|
||||||
|
"Bash(kubectl patch *)",
|
||||||
|
"Bash(kubectl drain *)",
|
||||||
|
"Bash(kubectl exec *)",
|
||||||
|
"Bash(ssh *)",
|
||||||
|
"Bash(scp *)",
|
||||||
|
"Bash(curl *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh POST */merge*)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh PATCH *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh PUT *)",
|
||||||
|
"Bash(.claude/scripts/gitea.sh DELETE *)"
|
||||||
|
],
|
||||||
|
"deny": [
|
||||||
|
"Bash(env)",
|
||||||
|
"Bash(printenv *)",
|
||||||
|
"Bash(pulumi stack export *)",
|
||||||
|
"Bash(pulumi *--show-secrets*)",
|
||||||
|
"Read(**/.env)",
|
||||||
|
"Edit(**/Pulumi.dev.yaml)",
|
||||||
|
"Edit(~/.kube/**)",
|
||||||
|
"Edit(~/.config/homelab-agent/**)",
|
||||||
|
"Read(~/.config/homelab-agent/token)",
|
||||||
|
"Bash(*homelab-agent/token*)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"attribution": {
|
||||||
|
"commit": "",
|
||||||
|
"pr": ""
|
||||||
|
},
|
||||||
|
"hooks": {
|
||||||
|
"PreToolUse": [
|
||||||
|
{
|
||||||
|
"matcher": "Bash",
|
||||||
|
"hooks": [
|
||||||
|
{
|
||||||
|
"type": "command",
|
||||||
|
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/guard-live-infra.sh"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"Stop": [
|
||||||
|
{
|
||||||
|
"hooks": [
|
||||||
|
{
|
||||||
|
"type": "command",
|
||||||
|
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/check-on-stop.sh",
|
||||||
|
"timeout": 300
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
name: explain-diff
|
||||||
|
description: Walk through the current uncommitted git diff hunk by hunk, explain what each change does to the Pulumi resources, then quiz the author before they commit.
|
||||||
|
argument-hint: [optional path or git ref range]
|
||||||
|
disable-model-invocation: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Explain the changes in `git diff HEAD` (or in `$ARGUMENTS` if a path or ref range was given) to the person who is about to commit them. They want to understand the change well enough to defend it, not to be reassured. Make no edits.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
|
||||||
|
1. Get the diff. If it is empty, say so and stop.
|
||||||
|
2. For each hunk, in file order:
|
||||||
|
- **What changed**, in one or two sentences, with a `file:line` link.
|
||||||
|
- **Why this way**: the reason for the approach, and one alternative that was available and why it was not used. If the reason is not visible in the code or the conversation, say that instead of inventing one.
|
||||||
|
- **Effect on resources**: which Pulumi resources this would create, update in place, or replace. Call out any replace of a VM, a PVC, or a resource adopted with `import`. If you cannot tell without `pulumi preview`, say so.
|
||||||
|
- **What could break**, and how it would show up.
|
||||||
|
3. Link the official documentation for any provider argument or Kubernetes field the diff introduces.
|
||||||
|
4. State what you did not verify.
|
||||||
|
|
||||||
|
## Then quiz
|
||||||
|
|
||||||
|
Ask three questions, one at a time, and wait for each answer:
|
||||||
|
|
||||||
|
1. A prediction: what will `pulumi preview` show for this change (creates, updates, replaces)?
|
||||||
|
2. A "why": pick the least obvious line in the diff and ask what it is for.
|
||||||
|
3. A failure: ask what happens to the running cluster if this change is applied and one specific thing goes wrong.
|
||||||
|
|
||||||
|
After each answer, say what was right, correct what was not, and point to the line or the doc that settles it. Do not grade or praise. If an answer shows the change is misunderstood, recommend not committing yet and say what to read first.
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
---
|
||||||
|
name: merge
|
||||||
|
description: Commit the staged and unstaged changes that fit the branch with meaningful messages, push a branch, open a Gitea PR, wait for CI, and merge it, without stopping for confirmation.
|
||||||
|
argument-hint: [optional note on intent, or paths to limit the merge to]
|
||||||
|
disable-model-invocation: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Take the working tree changes through commit, push, PR and merge in one run. If `$ARGUMENTS` names paths, include only those. If it describes intent, use it for the commit messages and PR.
|
||||||
|
|
||||||
|
Typing `/merge` is the user's explicit instruction to commit, push, open a PR and merge these changes. It satisfies the "commit" and "ask before opening or merging" rules in `CLAUDE.md` for this run. Do not ask for confirmation, and do not pause to show drafts. Stop only for a condition under "Stop conditions".
|
||||||
|
|
||||||
|
## Rules
|
||||||
|
|
||||||
|
- Follow `CONVENTIONS.md` for branch names, commit messages and PR titles.
|
||||||
|
- Add no AI attribution to commits or PRs.
|
||||||
|
- Never use `--no-verify`, force push, or commit directly to `main`.
|
||||||
|
- Use `.claude/scripts/gitea.sh` for PR calls, because `gh` does not work here. `$REPO` below means `/repos/kasun/homelab-infrastructure-as-code`, and must be written out in full in each command.
|
||||||
|
- Never stage `Pulumi.dev.yaml`, `.env` files, keys, credentials, `.claude/settings.local.json`, or anything in `sdks/`. Leave them out, carry on, and mention them in the report.
|
||||||
|
- Write commit messages and JSON bodies to files in the scratchpad directory with the Write tool.
|
||||||
|
- Run each command on its own, in the exact forms below, from the repo root. `cd` prefixes, pipes, loops and redirects cause permission prompts.
|
||||||
|
|
||||||
|
## Stop conditions
|
||||||
|
|
||||||
|
Stop and report only if:
|
||||||
|
|
||||||
|
- HEAD is detached, or a merge or rebase is in progress.
|
||||||
|
- There are no changes and no unpushed commits.
|
||||||
|
- Typecheck or `pulumi preview` fails.
|
||||||
|
- The preview shows a replace or delete of a VM, a PVC, or an imported resource.
|
||||||
|
- A file that looks like a secret is the only change.
|
||||||
|
- A commit hook, push or API call fails after one corrected retry of a message-format error.
|
||||||
|
- CI fails, or the PR is not mergeable.
|
||||||
|
|
||||||
|
Leave the branch and PR in place when stopping after they exist, and say what is needed to continue.
|
||||||
|
|
||||||
|
## 1. Inspect
|
||||||
|
|
||||||
|
1. Run `git status`, `git diff --staged`, `git diff`, and `git log --oneline -5`. Read any untracked files that would be included.
|
||||||
|
2. Run `git fetch origin main`.
|
||||||
|
3. On a non-`main` branch, run `.claude/scripts/gitea.sh GET $REPO/pulls?state=open`. If this branch has an open PR, reuse it only for changes that serve its purpose. If all remaining changes are unrelated to it, take that PR through steps 6 and 7 first, which returns you to `main`, then continue with the remaining changes as new work.
|
||||||
|
|
||||||
|
## 2. Group into commits
|
||||||
|
|
||||||
|
Split by reason for the change, and decide without asking. Each commit should make sense and be revertable alone.
|
||||||
|
|
||||||
|
- First decide the PR's purpose from `$ARGUMENTS`, the conversation, the branch name, or else the largest change.
|
||||||
|
- On the first `/merge`, leave out any change that does not serve that purpose, such as an unrelated `.claude/settings.json` edit. Keep it uncommitted and untouched, do not ask, and list it in the report.
|
||||||
|
- On a repeat `/merge`, meaning an earlier run this session left changes out or its PR is still open, handle all remaining changes in this run. Give each separate purpose its own branch and PR, and take them one at a time through steps 3 to 7, so each is merged and you are back on `main` before the next starts. If `$ARGUMENTS` names paths, handle only those.
|
||||||
|
- Use one commit when the remaining changes serve one purpose, and several when they are distinct steps toward it.
|
||||||
|
- Group whole files. If one file mixes purposes, put it in the commit for its main change.
|
||||||
|
- Scope is the stack (`01-proxmox-infra/` is `proxmox-infra`), or `ci` for `.gitea/workflows/`. Omit the scope for repo-wide or `.claude/` changes.
|
||||||
|
- Add a body only when the diff shows a reason that is not obvious. Never invent a reason.
|
||||||
|
|
||||||
|
## 3. Verify
|
||||||
|
|
||||||
|
For each stack with changed code, run:
|
||||||
|
|
||||||
|
- `npm run typecheck --prefix <stack-dir>`
|
||||||
|
- `pulumi preview --cwd <stack-dir> --stack dev`
|
||||||
|
|
||||||
|
## 4. Commit and push
|
||||||
|
|
||||||
|
1. If on `main`, run `git switch -c <type>/<short-kebab-description>`. This carries the changes across.
|
||||||
|
2. For each commit, run `git add -- <paths>`, then `git commit -F <message file> -- <paths>`. Naming the paths commits only those files, whatever else is staged.
|
||||||
|
3. Run `git status` to confirm only intentionally excluded files remain.
|
||||||
|
4. Run `git push -u origin <branch>`.
|
||||||
|
|
||||||
|
## 5. Open the PR
|
||||||
|
|
||||||
|
Unless one exists, run `.claude/scripts/gitea.sh POST $REPO/pulls @<json file>` with `title`, `body`, `head` and `base: "main"`. The body says what changed, why, and the preview result for each stack.
|
||||||
|
|
||||||
|
## 6. Wait for CI
|
||||||
|
|
||||||
|
Get the SHA with `git rev-parse HEAD`, then run `.claude/scripts/gitea.sh WAIT $REPO/commits/<sha>/status` as a background command. Do not write a polling loop, because that causes a permission prompt.
|
||||||
|
|
||||||
|
- Exit 0: checks passed, or it printed `no CI ran` because workflows are path-filtered. Continue.
|
||||||
|
- Exit 1: stop, and report the failing check and its `target_url`.
|
||||||
|
- Exit 3: CI timed out. Stop and report it.
|
||||||
|
|
||||||
|
Then run `.claude/scripts/gitea.sh GET $REPO/pulls/<number>` and confirm `mergeable` is true.
|
||||||
|
|
||||||
|
## 7. Merge
|
||||||
|
|
||||||
|
1. Run `.claude/scripts/gitea.sh POST $REPO/pulls/<number>/merge @<json file>` with `{"Do":"merge","head_commit_id":"<sha>"}`, so only the commit CI checked can merge.
|
||||||
|
2. Run `git fetch origin main:main`, then `git switch main`.
|
||||||
|
|
||||||
|
## 8. Report
|
||||||
|
|
||||||
|
Keep it short:
|
||||||
|
|
||||||
|
- PR link and commits.
|
||||||
|
- What the merge deploys, from the `on.push.paths` in `.gitea/workflows/`. `01`, `03`, `04` and `05` deploy on merge. A change under `.gitea/workflows/` can deploy `03`, `04` and `05`, and a change to `01`'s own workflow deploys `01`.
|
||||||
|
- For `02` changes, say that they are not live until someone runs the manual workflow.
|
||||||
|
- Anything left uncommitted. Also run `git -C .pulumi-config status --short --branch`, and if it shows uncommitted or unpushed changes, remind the user to commit and push them there because CI uses that repo's `main`. Don't commit or push that repo as part of `/merge`.
|
||||||
|
|
||||||
|
Do not delete the branch, dispatch a workflow, or change a live system.
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
name: stack-review
|
||||||
|
description: Read-only review of one Pulumi stack in this repo against Pulumi best practices. Reports ranked findings with doc links and makes no edits.
|
||||||
|
argument-hint: <stack directory, e.g. 03-k8s-infra>
|
||||||
|
disable-model-invocation: true
|
||||||
|
---
|
||||||
|
|
||||||
|
Review the stack in `$ARGUMENTS`. If no stack was given, ask which one. Review one stack per run.
|
||||||
|
|
||||||
|
This is a review for someone who wants to understand their own code better, and who will decide what to change. Do not edit any file, and do not run anything against the cluster or the Pulumi backend.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
|
||||||
|
1. Read the stack's `CLAUDE.md`, `index.ts`, `package.json`, `tsconfig.json` and `Pulumi.yaml`, plus its workflow in `.gitea/workflows/`.
|
||||||
|
2. Load the `pulumi:pulumi-best-practices` skill and check the code against it.
|
||||||
|
3. Run `npm run typecheck` in the stack directory and include the result.
|
||||||
|
4. Check each candidate finding against the code before reporting it. Drop anything you cannot point to a line for.
|
||||||
|
|
||||||
|
## What to look for
|
||||||
|
|
||||||
|
- Correctness: `Output<T>` misuse, missing `dependsOn` or `parent`, resources that would be replaced by a rename, secrets that lose their secret marking.
|
||||||
|
- Changes that are dangerous to apply here: anything that forces a replace of a VM, a PVC, or a resource adopted with `import`.
|
||||||
|
- Repetition that hides differences (near-identical blocks that differ in one argument).
|
||||||
|
- Drift between the stack's `CLAUDE.md` and what the code does.
|
||||||
|
- Dependency versions that lag the other stacks.
|
||||||
|
|
||||||
|
Skip style preferences and anything the compiler already enforces.
|
||||||
|
|
||||||
|
## Report format
|
||||||
|
|
||||||
|
Rank findings by consequence, most serious first, and stop at eight. For each:
|
||||||
|
|
||||||
|
- **What**: one sentence, with a `file:line` link.
|
||||||
|
- **Why it matters here**: the concrete consequence in this homelab, not the general rule.
|
||||||
|
- **Source**: a link to the official Pulumi, Kubernetes or provider documentation that supports it. If you have no source, say it is your own judgement.
|
||||||
|
- **Confidence**: high, medium or low, and what would raise it.
|
||||||
|
- **Size of fix**: one line, a small refactor, or a change that touches live resources.
|
||||||
|
|
||||||
|
End with the two findings you would start with and why. Do not offer to implement them.
|
||||||
@@ -0,0 +1,119 @@
|
|||||||
|
name: Deploy Proxmox Infra
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "01-proxmox-infra/**"
|
||||||
|
- ".gitea/workflows/01-deploy-proxmox-infra.yaml"
|
||||||
|
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "01-proxmox-infra/**"
|
||||||
|
- ".gitea/workflows/**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
preview:
|
||||||
|
name: Pulumi Preview
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "24"
|
||||||
|
|
||||||
|
- name: Checkout Stack Config
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
working-directory: 01-proxmox-infra
|
||||||
|
|
||||||
|
- name: Install Pulumi CLI
|
||||||
|
run: curl -fsSL https://get.pulumi.com | sh && echo "$HOME/.pulumi/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Generate Local pfSense SDK
|
||||||
|
run: pulumi package add terraform-provider marshallford/pfsense 0.22.0
|
||||||
|
working-directory: 01-proxmox-infra
|
||||||
|
|
||||||
|
- name: Preview
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: preview
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 01-proxmox-infra
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
name: Pulumi Deploy
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "24"
|
||||||
|
|
||||||
|
- name: Checkout Stack Config
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm ci
|
||||||
|
working-directory: 01-proxmox-infra
|
||||||
|
|
||||||
|
- name: Install Pulumi CLI
|
||||||
|
run: curl -fsSL https://get.pulumi.com | sh && echo "$HOME/.pulumi/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Generate Local pfSense SDK
|
||||||
|
run: pulumi package add terraform-provider marshallford/pfsense 0.22.0
|
||||||
|
working-directory: 01-proxmox-infra
|
||||||
|
|
||||||
|
# Manual runs only: a refresh that finds a VM missing drops it from state,
|
||||||
|
# and `up` would then create a blank replacement without review.
|
||||||
|
- name: Refresh State
|
||||||
|
if: github.event_name == 'workflow_dispatch'
|
||||||
|
run: |
|
||||||
|
pulumi login "$PULUMI_BACKEND_URL"
|
||||||
|
pulumi refresh --yes --stack dev \
|
||||||
|
--target 'urn:pulumi:dev::proxmox-infra::proxmoxve**' \
|
||||||
|
--target 'urn:pulumi:dev::proxmox-infra::tls**'
|
||||||
|
working-directory: 01-proxmox-infra
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
|
PULUMI_BACKEND_URL: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: up
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 01-proxmox-infra
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
name: Deploy k8s Bootstrap
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "02-k8s-bootstrap/**"
|
||||||
|
- ".gitea/workflows/02-deploy-k8s-bootstrap.yaml"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
preview:
|
||||||
|
name: Pulumi Preview
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "24"
|
||||||
|
|
||||||
|
- name: Checkout Stack Config
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm install
|
||||||
|
working-directory: 02-k8s-bootstrap
|
||||||
|
|
||||||
|
- name: Preview
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: preview
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 02-k8s-bootstrap
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
name: Bootstrap k3s Cluster
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'workflow_dispatch'
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "24"
|
||||||
|
|
||||||
|
- name: Checkout Stack Config
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm install
|
||||||
|
working-directory: 02-k8s-bootstrap
|
||||||
|
|
||||||
|
- name: Refresh State
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: refresh
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 02-k8s-bootstrap
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: up
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 02-k8s-bootstrap
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
+34
-30
@@ -1,4 +1,4 @@
|
|||||||
name: Deploy Proxmox Infra
|
name: Deploy k8s Infra
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -6,14 +6,14 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- 'proxmox-infra/**'
|
- "03-k8s-infra/**"
|
||||||
- '.gitea/workflows/**'
|
- ".gitea/workflows/03-deploy-k8s-infra.yaml"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- 'proxmox-infra/**'
|
- "03-k8s-infra/**"
|
||||||
- '.gitea/workflows/**'
|
- ".gitea/workflows/**"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
preview:
|
preview:
|
||||||
@@ -27,28 +27,30 @@ jobs:
|
|||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: "24"
|
||||||
|
|
||||||
- name: Restore Stack Config
|
- name: Checkout Stack Config
|
||||||
run: echo "${{ secrets.PROXMOX_INFRA_PULUMI_DEV_YAML }}" | base64 -d > proxmox-infra/Pulumi.dev.yaml
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Helm
|
||||||
|
uses: azure/setup-helm@v4
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
working-directory: proxmox-infra
|
working-directory: 03-k8s-infra
|
||||||
|
|
||||||
- name: Install Pulumi CLI
|
|
||||||
run: curl -fsSL https://get.pulumi.com | sh && echo "$HOME/.pulumi/bin" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Generate Local pfSense SDK
|
|
||||||
run: pulumi package add terraform-provider marshallford/pfsense
|
|
||||||
working-directory: proxmox-infra
|
|
||||||
|
|
||||||
- name: Preview
|
- name: Preview
|
||||||
uses: pulumi/actions@v5
|
uses: pulumi/actions@v5
|
||||||
with:
|
with:
|
||||||
command: preview
|
command: preview
|
||||||
stack-name: dev
|
stack-name: dev
|
||||||
work-dir: proxmox-infra
|
work-dir: 03-k8s-infra
|
||||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
env:
|
env:
|
||||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
@@ -64,28 +66,30 @@ jobs:
|
|||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
uses: actions/setup-node@v4
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '24'
|
node-version: "24"
|
||||||
|
|
||||||
- name: Restore Stack Config
|
- name: Checkout Stack Config
|
||||||
run: echo "${{ secrets.PROXMOX_INFRA_PULUMI_DEV_YAML }}" | base64 -d > proxmox-infra/Pulumi.dev.yaml
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Helm
|
||||||
|
uses: azure/setup-helm@v4
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm ci
|
run: npm ci
|
||||||
working-directory: proxmox-infra
|
working-directory: 03-k8s-infra
|
||||||
|
|
||||||
- name: Install Pulumi CLI
|
|
||||||
run: curl -fsSL https://get.pulumi.com | sh && echo "$HOME/.pulumi/bin" >> $GITHUB_PATH
|
|
||||||
|
|
||||||
- name: Generate Local pfSense SDK
|
|
||||||
run: pulumi package add terraform-provider marshallford/pfsense
|
|
||||||
working-directory: proxmox-infra
|
|
||||||
|
|
||||||
- name: Refresh State
|
- name: Refresh State
|
||||||
uses: pulumi/actions@v5
|
uses: pulumi/actions@v5
|
||||||
with:
|
with:
|
||||||
command: refresh
|
command: refresh
|
||||||
stack-name: dev
|
stack-name: dev
|
||||||
work-dir: proxmox-infra
|
work-dir: 03-k8s-infra
|
||||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
env:
|
env:
|
||||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
@@ -95,7 +99,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: up
|
command: up
|
||||||
stack-name: dev
|
stack-name: dev
|
||||||
work-dir: proxmox-infra
|
work-dir: 03-k8s-infra
|
||||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
env:
|
env:
|
||||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
+27
-15
@@ -1,4 +1,4 @@
|
|||||||
name: Deploy k8s Bootstrap
|
name: Deploy k8s Apps
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
@@ -6,14 +6,14 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- "k8s-bootstrap/**"
|
- "04-k8s-apps/**"
|
||||||
- ".gitea/workflows/deploy-k8s-bootstrap.yaml"
|
- ".gitea/workflows/04-deploy-k8s-apps.yaml"
|
||||||
pull_request:
|
pull_request:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
paths:
|
paths:
|
||||||
- "k8s-bootstrap/**"
|
- "04-k8s-apps/**"
|
||||||
- ".gitea/workflows/deploy-k8s-bootstrap.yaml"
|
- ".gitea/workflows/**"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
preview:
|
preview:
|
||||||
@@ -29,25 +29,31 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: "24"
|
node-version: "24"
|
||||||
|
|
||||||
- name: Restore Stack Config
|
- name: Checkout Stack Config
|
||||||
run: echo "${{ secrets.K8S_BOOTSTRAP_PULUMI_DEV_YAML }}" | base64 -d > k8s-bootstrap/Pulumi.dev.yaml
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm install
|
run: npm install
|
||||||
working-directory: k8s-bootstrap
|
working-directory: 04-k8s-apps
|
||||||
|
|
||||||
- name: Preview
|
- name: Preview
|
||||||
uses: pulumi/actions@v5
|
uses: pulumi/actions@v5
|
||||||
with:
|
with:
|
||||||
command: preview
|
command: preview
|
||||||
stack-name: dev
|
stack-name: dev
|
||||||
work-dir: k8s-bootstrap
|
work-dir: 04-k8s-apps
|
||||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
env:
|
env:
|
||||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
name: Bootstrap k3s Cluster
|
name: Pulumi Deploy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||||
steps:
|
steps:
|
||||||
@@ -59,19 +65,25 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
node-version: "24"
|
node-version: "24"
|
||||||
|
|
||||||
- name: Restore Stack Config
|
- name: Checkout Stack Config
|
||||||
run: echo "${{ secrets.K8S_BOOTSTRAP_PULUMI_DEV_YAML }}" | base64 -d > k8s-bootstrap/Pulumi.dev.yaml
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: npm install
|
run: npm install
|
||||||
working-directory: k8s-bootstrap
|
working-directory: 04-k8s-apps
|
||||||
|
|
||||||
- name: Refresh State
|
- name: Refresh State
|
||||||
uses: pulumi/actions@v5
|
uses: pulumi/actions@v5
|
||||||
with:
|
with:
|
||||||
command: refresh
|
command: refresh
|
||||||
stack-name: dev
|
stack-name: dev
|
||||||
work-dir: k8s-bootstrap
|
work-dir: 04-k8s-apps
|
||||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
env:
|
env:
|
||||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
@@ -81,7 +93,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
command: up
|
command: up
|
||||||
stack-name: dev
|
stack-name: dev
|
||||||
work-dir: k8s-bootstrap
|
work-dir: 04-k8s-apps
|
||||||
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
env:
|
env:
|
||||||
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
@@ -0,0 +1,99 @@
|
|||||||
|
name: Deploy Monitoring
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "05-monitoring/**"
|
||||||
|
- ".gitea/workflows/05-deploy-monitoring.yaml"
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
paths:
|
||||||
|
- "05-monitoring/**"
|
||||||
|
- ".gitea/workflows/**"
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
preview:
|
||||||
|
name: Pulumi Preview
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "24"
|
||||||
|
|
||||||
|
- name: Checkout Stack Config
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm install
|
||||||
|
working-directory: 05-monitoring
|
||||||
|
|
||||||
|
- name: Preview
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: preview
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 05-monitoring
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
name: Pulumi Deploy
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
|
||||||
|
steps:
|
||||||
|
- name: Checkout Code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: "24"
|
||||||
|
|
||||||
|
- name: Checkout Stack Config
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
repository: kasun/homelab-pulumi-config
|
||||||
|
ref: main
|
||||||
|
token: ${{ secrets.PULUMI_CONFIG_REPO_TOKEN }}
|
||||||
|
path: .pulumi-config
|
||||||
|
persist-credentials: false
|
||||||
|
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: npm install
|
||||||
|
working-directory: 05-monitoring
|
||||||
|
|
||||||
|
- name: Refresh State
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: refresh
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 05-monitoring
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
|
|
||||||
|
- name: Deploy
|
||||||
|
uses: pulumi/actions@v5
|
||||||
|
with:
|
||||||
|
command: up
|
||||||
|
stack-name: dev
|
||||||
|
work-dir: 05-monitoring
|
||||||
|
cloud-url: ${{ secrets.PULUMI_BACKEND_URL }}
|
||||||
|
env:
|
||||||
|
PULUMI_CONFIG_PASSPHRASE: ${{ secrets.PULUMI_CONFIG_PASSPHRASE }}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
name: Secret Scan
|
||||||
|
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
env:
|
||||||
|
BETTERLEAKS_VERSION: "1.10.1"
|
||||||
|
BETTERLEAKS_SHA256: c174b42d7aa60caf58c0c3e555c0e4bed01fe6b0d99a412bce777b5af4ce913e
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
scan:
|
||||||
|
name: Betterleaks
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Checkout Full History
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
|
||||||
|
- name: Install Betterleaks
|
||||||
|
run: |
|
||||||
|
curl -fsSL -o /tmp/betterleaks.tar.gz \
|
||||||
|
"https://github.com/betterleaks/betterleaks/releases/download/v${BETTERLEAKS_VERSION}/betterleaks_${BETTERLEAKS_VERSION}_linux_x64.tar.gz"
|
||||||
|
echo "${BETTERLEAKS_SHA256} /tmp/betterleaks.tar.gz" | sha256sum -c -
|
||||||
|
tar -xzf /tmp/betterleaks.tar.gz -C /tmp betterleaks
|
||||||
|
|
||||||
|
- name: Scan Git History
|
||||||
|
run: /tmp/betterleaks git . --redact --verbose --no-banner --no-color --log-opts="--all -m -p -U0"
|
||||||
Executable
+38
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Git commit-msg hook: rejects commit messages that don't follow CONVENTIONS.md.
|
||||||
|
#
|
||||||
|
# Why: CONVENTIONS.md and CLAUDE.md only describe the format; nothing checked it,
|
||||||
|
# so older commits ("added node constants", "refactor code") drifted. Git runs
|
||||||
|
# this hook on every commit, from Claude or from you, and aborts the commit if
|
||||||
|
# the message is wrong. Your message is kept in .git/COMMIT_EDITMSG to fix up.
|
||||||
|
#
|
||||||
|
# Checks:
|
||||||
|
# - first line is `<type>(<scope>): <summary>` with a type and optional scope
|
||||||
|
# from CONVENTIONS.md, and no period at the end
|
||||||
|
# - no AI attribution lines (Co-Authored-By: Claude, "Generated with Claude")
|
||||||
|
#
|
||||||
|
# Activate once per clone: git config core.hooksPath .githooks
|
||||||
|
# Skip in an emergency: git commit --no-verify
|
||||||
|
#
|
||||||
|
# Idea taken from the deverenz repo (.githooks/commit-msg).
|
||||||
|
msg_file="$1"
|
||||||
|
first_line=$(grep -v '^#' "$msg_file" | head -n1)
|
||||||
|
|
||||||
|
# Let git's own merge/revert/fixup messages through.
|
||||||
|
[[ "$first_line" =~ ^(Merge|Revert|fixup!|squash!) ]] && exit 0
|
||||||
|
|
||||||
|
types='feature|bug|enhancement|chore|docs'
|
||||||
|
scopes='proxmox-infra|k8s-bootstrap|k8s-infra|k8s-apps|monitoring|ci'
|
||||||
|
pattern="^($types)(\(($scopes)\))?: .*[^.]$"
|
||||||
|
if ! [[ "$first_line" =~ $pattern ]]; then
|
||||||
|
echo "commit-msg: '$first_line'" >&2
|
||||||
|
echo " expected '<type>(<scope>): <summary>' with no trailing period (see CONVENTIONS.md)" >&2
|
||||||
|
echo " types: ${types//|/ }" >&2
|
||||||
|
echo " scopes: ${scopes//|/ } (optional)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -qiE '^(Co-Authored-By:.*(claude|anthropic)|.*Generated with \[?Claude)' "$msg_file"; then
|
||||||
|
echo "commit-msg: no AI attribution lines (see CLAUDE.md)" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Executable
+11
@@ -0,0 +1,11 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Git pre-commit hook: blocks a commit if its staged changes contain a secret.
|
||||||
|
#
|
||||||
|
# Activate once per clone: git config core.hooksPath .githooks
|
||||||
|
# Skip in an emergency: git commit --no-verify
|
||||||
|
if ! command -v betterleaks >/dev/null 2>&1; then
|
||||||
|
echo "pre-commit: betterleaks is not installed, so staged changes can't be scanned" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec betterleaks git --pre-commit --staged --redact --no-banner --no-color .
|
||||||
+4
-1
@@ -5,4 +5,7 @@ node_modules/
|
|||||||
bin/
|
bin/
|
||||||
Pulumi.dev.yaml
|
Pulumi.dev.yaml
|
||||||
sdks/
|
sdks/
|
||||||
.env
|
.env
|
||||||
|
.env.*
|
||||||
|
!.env.example
|
||||||
|
.pulumi-config
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# proxmox-infra
|
||||||
|
|
||||||
|
- The pfSense SDK in `sdks/pfsense/` is gitignored and generated by `pulumi package add terraform-provider marshallford/pfsense 0.22.0` (CI runs it; locally, run it before `npm install` if the folder is missing). Don't edit it by hand.
|
||||||
|
- VMs are sometimes changed by hand in the Proxmox GUI. Before planning an `up`, suggest `pulumi refresh` so state matches reality.
|
||||||
@@ -11,6 +11,8 @@ config:
|
|||||||
packages:
|
packages:
|
||||||
pfsense:
|
pfsense:
|
||||||
source: terraform-provider
|
source: terraform-provider
|
||||||
version: 1.1.3
|
version: 1.5.1
|
||||||
parameters:
|
parameters:
|
||||||
- marshallford/pfsense
|
- marshallford/pfsense
|
||||||
|
- 0.22.0
|
||||||
|
stackConfigDir: ../.pulumi-config/01-proxmox-infra
|
||||||
@@ -0,0 +1,425 @@
|
|||||||
|
import * as pulumi from "@pulumi/pulumi";
|
||||||
|
import * as proxmox from "@muhlba91/pulumi-proxmoxve";
|
||||||
|
import * as tls from "@pulumi/tls";
|
||||||
|
import * as pfsense from "@pulumi/pfsense";
|
||||||
|
|
||||||
|
const config = new pulumi.Config();
|
||||||
|
|
||||||
|
const pve1Endpoint = config.requireSecret("pve1Endpoint");
|
||||||
|
const pve2Endpoint = config.requireSecret("pve2Endpoint");
|
||||||
|
const pve3Endpoint = config.requireSecret("pve3Endpoint");
|
||||||
|
|
||||||
|
const pve1ApiToken = config.requireSecret("pve1ApiToken");
|
||||||
|
const pve2ApiToken = config.requireSecret("pve2ApiToken");
|
||||||
|
const pve3ApiToken = config.requireSecret("pve3ApiToken");
|
||||||
|
|
||||||
|
const pfSenseUrl = config.requireSecret("pfSenseUrl");
|
||||||
|
const pfSenseUser = config.requireSecret("pfSenseUser");
|
||||||
|
const pfSensePassword = config.requireSecret("pfSensePassword");
|
||||||
|
|
||||||
|
const master1Ip = config.requireSecret("master1Ip");
|
||||||
|
const master2Ip = config.requireSecret("master2Ip");
|
||||||
|
const master3Ip = config.requireSecret("master3Ip");
|
||||||
|
|
||||||
|
const worker1Ip = config.requireSecret("worker1Ip");
|
||||||
|
const worker2Ip = config.requireSecret("worker2Ip");
|
||||||
|
const worker3Ip = config.requireSecret("worker3Ip");
|
||||||
|
|
||||||
|
const ansibleIp = config.requireSecret("ansibleIp");
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// VM templates — one per node, cloned from the downloaded cloud image.
|
||||||
|
// Templates are not started and have no cloud-init config; that is applied
|
||||||
|
// per-clone so each node gets its own hostname (derived from VM name).
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const templateSettings = {
|
||||||
|
template: true,
|
||||||
|
protection: true,
|
||||||
|
started: false,
|
||||||
|
operatingSystem: { type: "l26" },
|
||||||
|
stopOnDestroy: true,
|
||||||
|
scsiHardware: "virtio-scsi-pci",
|
||||||
|
cdrom: { fileId: "none" },
|
||||||
|
cpu: {
|
||||||
|
cores: 2,
|
||||||
|
sockets: 1,
|
||||||
|
type: "host",
|
||||||
|
numa: true,
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
dedicated: 2048,
|
||||||
|
floating: 0,
|
||||||
|
},
|
||||||
|
networkDevices: [{ bridge: "vmbr0", model: "virtio" }],
|
||||||
|
serialDevices: [{}],
|
||||||
|
vga: { type: "serial0" },
|
||||||
|
agent: { enabled: true, timeout: "30s" },
|
||||||
|
};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Providers — one per standalone Proxmox machine
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
interface PveNodeConfig {
|
||||||
|
nodeName: string;
|
||||||
|
hostLabel: string;
|
||||||
|
isoStore: string;
|
||||||
|
dataStore: string;
|
||||||
|
endpoint: pulumi.Output<string>;
|
||||||
|
apiToken: pulumi.Output<string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pveNodeSeeds: PveNodeConfig[] = [
|
||||||
|
{
|
||||||
|
nodeName: "pve",
|
||||||
|
hostLabel: "pve-b550",
|
||||||
|
isoStore: "pve-local-ext1",
|
||||||
|
dataStore: "local-lvm",
|
||||||
|
endpoint: pve1Endpoint,
|
||||||
|
apiToken: pve1ApiToken,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: "pve-bckp",
|
||||||
|
hostLabel: "pve-optiplex",
|
||||||
|
isoStore: "local",
|
||||||
|
dataStore: "local",
|
||||||
|
endpoint: pve2Endpoint,
|
||||||
|
apiToken: pve2ApiToken,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
nodeName: "pve",
|
||||||
|
hostLabel: "pve-esprimo",
|
||||||
|
isoStore: "local",
|
||||||
|
dataStore: "local-lvm",
|
||||||
|
endpoint: pve3Endpoint,
|
||||||
|
apiToken: pve3ApiToken,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const pveNodes = pveNodeSeeds
|
||||||
|
.map((n) => ({
|
||||||
|
...n,
|
||||||
|
provider: new proxmox.Provider(n.hostLabel, {
|
||||||
|
endpoint: n.endpoint,
|
||||||
|
apiToken: n.apiToken,
|
||||||
|
insecure: true,
|
||||||
|
}),
|
||||||
|
}))
|
||||||
|
.map((n) => ({
|
||||||
|
...n,
|
||||||
|
ubuntuImagePve: new proxmox.download.File(
|
||||||
|
`ubuntu-noble-${n.hostLabel}`,
|
||||||
|
{
|
||||||
|
nodeName: n.nodeName,
|
||||||
|
datastoreId: n.isoStore,
|
||||||
|
contentType: "import",
|
||||||
|
fileName: "noble-server-cloudimg-amd64.qcow2",
|
||||||
|
url: "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img",
|
||||||
|
overwrite: false,
|
||||||
|
overwriteUnmanaged: true,
|
||||||
|
},
|
||||||
|
{ provider: n.provider },
|
||||||
|
),
|
||||||
|
}))
|
||||||
|
.map((n) => ({
|
||||||
|
...n,
|
||||||
|
pveTemplate: new proxmox.VmLegacy(
|
||||||
|
`k3s-template-${n.hostLabel}`,
|
||||||
|
{
|
||||||
|
...templateSettings,
|
||||||
|
nodeName: n.nodeName,
|
||||||
|
name: "k3s-ubuntu-noble-template",
|
||||||
|
disks: [
|
||||||
|
{
|
||||||
|
interface: "scsi0",
|
||||||
|
datastoreId: n.dataStore,
|
||||||
|
importFrom: pulumi.interpolate`${n.ubuntuImagePve.datastoreId}:import/${n.ubuntuImagePve.fileName}`,
|
||||||
|
size: 10,
|
||||||
|
ssd: true,
|
||||||
|
discard: "on",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{ provider: n.provider, protect: true, ignoreChanges: ["disks"] },
|
||||||
|
),
|
||||||
|
}));
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Providers — PfSense
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const pfSenseProvider = new pfsense.Provider("pfsense", {
|
||||||
|
url: pfSenseUrl,
|
||||||
|
username: pfSenseUser,
|
||||||
|
password: pfSensePassword,
|
||||||
|
tlsSkipVerify: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// CI runner SSH keypair — generated once, stored in Pulumi state backend.
|
||||||
|
// Public key goes into every VM; private key is exported for k8s-bootstrap.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const ciRunnerKey = new tls.PrivateKey("ci-runner-key", {
|
||||||
|
algorithm: "ED25519",
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// k3s nodes — full clones of their respective templates
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const k3sVmPassword = config.requireSecret("k3sVmPassword");
|
||||||
|
const pve1SshPublicKey = config.requireSecret("pve1SshPublicKey");
|
||||||
|
const pve2SshPublicKey = config.requireSecret("pve2SshPublicKey");
|
||||||
|
const pve3SshPublicKey = config.requireSecret("pve3SshPublicKey");
|
||||||
|
|
||||||
|
interface NodeConfig {
|
||||||
|
name: string;
|
||||||
|
role: "master" | "worker";
|
||||||
|
host: (typeof pveNodes)[number]; // one row from the pveNodes chain
|
||||||
|
ip: pulumi.Output<string>;
|
||||||
|
longhornDiskSize?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hostFor = (label: string) => pveNodes.find((n) => n.hostLabel === label)!;
|
||||||
|
|
||||||
|
const nodeConfigs: NodeConfig[] = [
|
||||||
|
{
|
||||||
|
name: "k3s-master-1",
|
||||||
|
role: "master",
|
||||||
|
host: hostFor("pve-b550"),
|
||||||
|
ip: master1Ip,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "k3s-master-2",
|
||||||
|
role: "master",
|
||||||
|
host: hostFor("pve-esprimo"),
|
||||||
|
ip: master2Ip,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "k3s-worker-1",
|
||||||
|
role: "worker",
|
||||||
|
host: hostFor("pve-b550"),
|
||||||
|
ip: worker1Ip,
|
||||||
|
longhornDiskSize: 50,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "k3s-master-3",
|
||||||
|
role: "master",
|
||||||
|
host: hostFor("pve-optiplex"),
|
||||||
|
ip: master3Ip,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "k3s-worker-2",
|
||||||
|
role: "worker",
|
||||||
|
host: hostFor("pve-optiplex"),
|
||||||
|
ip: worker2Ip,
|
||||||
|
longhornDiskSize: 50,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "k3s-worker-3",
|
||||||
|
role: "worker",
|
||||||
|
host: hostFor("pve-esprimo"),
|
||||||
|
ip: worker3Ip,
|
||||||
|
longhornDiskSize: 50,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const k3sVms = nodeConfigs.map(
|
||||||
|
(node) =>
|
||||||
|
new proxmox.VmLegacy(
|
||||||
|
node.name,
|
||||||
|
{
|
||||||
|
nodeName: node.host.nodeName,
|
||||||
|
name: node.name,
|
||||||
|
description: "k3s " + node.role + " node — managed by Pulumi",
|
||||||
|
tags: ["k3s", node.role],
|
||||||
|
clone: {
|
||||||
|
vmId: node.host.pveTemplate.vmId,
|
||||||
|
full: true,
|
||||||
|
datastoreId: node.host.dataStore,
|
||||||
|
},
|
||||||
|
cpu: {
|
||||||
|
cores: 2,
|
||||||
|
sockets: 1,
|
||||||
|
type: "host",
|
||||||
|
numa: true,
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
dedicated: node.role === "master" ? 4096 : 8192,
|
||||||
|
floating: 0,
|
||||||
|
},
|
||||||
|
disks: [
|
||||||
|
{
|
||||||
|
interface: "scsi0",
|
||||||
|
datastoreId: node.host.dataStore,
|
||||||
|
size: 35,
|
||||||
|
ssd: true,
|
||||||
|
discard: "on",
|
||||||
|
},
|
||||||
|
...(node.longhornDiskSize == null
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
interface: "scsi1",
|
||||||
|
datastoreId: node.host.dataStore,
|
||||||
|
size: node.longhornDiskSize,
|
||||||
|
ssd: true,
|
||||||
|
discard: "on",
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
],
|
||||||
|
initialization: {
|
||||||
|
datastoreId: node.host.dataStore,
|
||||||
|
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
||||||
|
userAccount: {
|
||||||
|
username: "ubuntu",
|
||||||
|
password: k3sVmPassword,
|
||||||
|
keys: [
|
||||||
|
pve1SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve2SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve3SshPublicKey.apply((k) => k.trim()),
|
||||||
|
ciRunnerKey.publicKeyOpenssh.apply((k) => k.trim()),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
networkDevices: [{ bridge: "vmbr0", model: "virtio" }],
|
||||||
|
scsiHardware: "virtio-scsi-pci",
|
||||||
|
serialDevices: [{}],
|
||||||
|
vga: { type: "serial0" },
|
||||||
|
agent: { enabled: true, timeout: "30s" },
|
||||||
|
cdrom: { fileId: "none" },
|
||||||
|
started: false,
|
||||||
|
rebootAfterUpdate: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provider: node.host.provider,
|
||||||
|
retainOnDelete: true,
|
||||||
|
protect: true,
|
||||||
|
ignoreChanges: [
|
||||||
|
"clone",
|
||||||
|
"started",
|
||||||
|
// Pulumi bridge bug: unset disk speed always shows a diff.
|
||||||
|
// https://github.com/muhlba91/pulumi-proxmoxve/issues/664
|
||||||
|
"disks[0].speed",
|
||||||
|
...(node.longhornDiskSize == null ? [] : ["disks[1].speed"]),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
k3sVms.forEach((vmResource, i) => {
|
||||||
|
const assignedMac = vmResource.networkDevices.apply(
|
||||||
|
(nic) => nic[0].macAddress,
|
||||||
|
);
|
||||||
|
|
||||||
|
new pfsense.Dhcpv4Staticmapping(
|
||||||
|
`${nodeConfigs[i].name}-dhcp`,
|
||||||
|
{
|
||||||
|
interface: "lan",
|
||||||
|
macAddress: assignedMac,
|
||||||
|
ipAddress: nodeConfigs[i].ip,
|
||||||
|
hostname: nodeConfigs[i].name,
|
||||||
|
},
|
||||||
|
{ dependsOn: vmResource, provider: pfSenseProvider, protect: true },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Ansible control node — unprivileged LXC with a pfSense DHCP reservation.
|
||||||
|
// The MAC is fixed so the reservation can exist before the container's first
|
||||||
|
// boot; otherwise its first DHCP lease could come from the dynamic pool.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const ansibleHost = hostFor("pve-b550");
|
||||||
|
const ansibleMac = "02:A5:1B:00:01:54";
|
||||||
|
|
||||||
|
const ansibleTemplate = new proxmox.download.File(
|
||||||
|
"ubuntu-resolute-lxc-pve-b550",
|
||||||
|
{
|
||||||
|
nodeName: ansibleHost.nodeName,
|
||||||
|
datastoreId: ansibleHost.isoStore,
|
||||||
|
contentType: "vztmpl",
|
||||||
|
fileName: "ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||||
|
url: "https://download.proxmox.com/images/system/ubuntu-26.04-standard_26.04-1_amd64.tar.zst",
|
||||||
|
overwrite: false,
|
||||||
|
overwriteUnmanaged: true,
|
||||||
|
},
|
||||||
|
{ provider: ansibleHost.provider },
|
||||||
|
);
|
||||||
|
|
||||||
|
const ansibleDhcp = new pfsense.Dhcpv4Staticmapping(
|
||||||
|
"ansible-dhcp",
|
||||||
|
{
|
||||||
|
interface: "lan",
|
||||||
|
macAddress: ansibleMac,
|
||||||
|
ipAddress: ansibleIp,
|
||||||
|
hostname: "ansible",
|
||||||
|
},
|
||||||
|
{ provider: pfSenseProvider, protect: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
new proxmox.ContainerLegacy( // NOSONAR typescript:S1848
|
||||||
|
"ansible",
|
||||||
|
{
|
||||||
|
nodeName: ansibleHost.nodeName,
|
||||||
|
description: "Ansible control node — managed by Pulumi",
|
||||||
|
tags: ["ansible"],
|
||||||
|
unprivileged: true,
|
||||||
|
features: { nesting: true },
|
||||||
|
operatingSystem: {
|
||||||
|
templateFileId: ansibleTemplate.id,
|
||||||
|
type: "ubuntu",
|
||||||
|
},
|
||||||
|
cpu: { cores: 1 },
|
||||||
|
memory: { dedicated: 1024, swap: 0 },
|
||||||
|
disk: { datastoreId: ansibleHost.dataStore, size: 8 },
|
||||||
|
networkInterfaces: [
|
||||||
|
{ name: "eth0", bridge: "vmbr0", macAddress: ansibleMac },
|
||||||
|
],
|
||||||
|
initialization: {
|
||||||
|
hostname: "ansible",
|
||||||
|
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
||||||
|
userAccount: {
|
||||||
|
keys: [
|
||||||
|
pve1SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve2SshPublicKey.apply((k) => k.trim()),
|
||||||
|
pve3SshPublicKey.apply((k) => k.trim()),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
started: true,
|
||||||
|
startOnBoot: true,
|
||||||
|
protection: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provider: ansibleHost.provider,
|
||||||
|
dependsOn: ansibleDhcp,
|
||||||
|
retainOnDelete: true,
|
||||||
|
protect: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
export const vmIds = {
|
||||||
|
master1: k3sVms[0].vmId,
|
||||||
|
master2: k3sVms[1].vmId,
|
||||||
|
worker1: k3sVms[2].vmId,
|
||||||
|
master3: k3sVms[3].vmId,
|
||||||
|
worker2: k3sVms[4].vmId,
|
||||||
|
worker3: k3sVms[5].vmId,
|
||||||
|
};
|
||||||
|
|
||||||
|
// CI runner SSH private key — consumed by k8s-bootstrap via StackReference.
|
||||||
|
export const ciRunnerPrivateKey = pulumi.secret(ciRunnerKey.privateKeyOpenssh);
|
||||||
|
|
||||||
|
export {
|
||||||
|
pve1Endpoint,
|
||||||
|
pve1ApiToken,
|
||||||
|
pve2Endpoint,
|
||||||
|
pve2ApiToken,
|
||||||
|
pve3Endpoint,
|
||||||
|
pve3ApiToken,
|
||||||
|
};
|
||||||
|
|
||||||
|
export { master1Ip, master2Ip, worker1Ip, master3Ip, worker2Ip, worker3Ip };
|
||||||
Generated
+1396
File diff suppressed because it is too large.
Load diff
@@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"name": "proxmox-infra",
|
"name": "proxmox-infra",
|
||||||
"main": "index.ts",
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^18",
|
"@types/node": "^24",
|
||||||
"typescript": "^5.0.0"
|
"typescript": "^6.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@muhlba91/pulumi-proxmoxve": "^8.2.1",
|
"@muhlba91/pulumi-proxmoxve": "^8.2.1",
|
||||||
"@pulumi/pfsense": "file:sdks/pfsense",
|
"@pulumi/pfsense": "file:sdks/pfsense",
|
||||||
"@pulumi/pulumi": "^3.113.0",
|
"@pulumi/pulumi": "^3.244.0",
|
||||||
"@pulumi/tls": "^5.5.0"
|
"@pulumi/tls": "^5.5.0"
|
||||||
},
|
},
|
||||||
"imports": {
|
"imports": {
|
||||||
File renamed without changes.
@@ -0,0 +1,13 @@
|
|||||||
|
# k8s-bootstrap
|
||||||
|
|
||||||
|
## Decisions the code doesn't explain
|
||||||
|
|
||||||
|
- **Everything goes through `controlPlaneVipAddress` except master-1's own install.** master-1 is installed with `--cluster-init` and a `--tls-san` for both `master1Ip` and the VIP. The stack then waits for `https://<controlPlaneVipAddress>:6443/healthz` before anyone joins, because master-2, master-3 and the workers all join via the VIP, and the exported `kubeconfig` points at it.
|
||||||
|
- **The VIP is pfSense + HAProxy, set up by hand, not kube-vip.** `03-k8s-infra`'s kube-vip DaemonSet only handles Service/LoadBalancer VIPs. Don't propose kube-vip `cp_enable` for API access: it was considered and rejected, see [the decision record](../docs/decisions/0001-control-plane-vip-via-pfsense-haproxy.md). The manual pfSense steps are in [the runbook](../docs/runbooks/pfsense-control-plane-vip.md).
|
||||||
|
- **Workers get a dedicated Longhorn disk.** The `scsi1` disk is formatted ext4 (if not already) and mounted at `/mnt/longhorn-extra` via `/etc/fstab`. `03-k8s-infra` later registers it as an extra Longhorn disk, which keeps Longhorn off the root filesystem and avoids `DiskPressure`.
|
||||||
|
|
||||||
|
## Running against live VMs
|
||||||
|
|
||||||
|
Re-running this stack restarts the bootstrap sequence against already-provisioned VMs. That's why it only deploys via manual dispatch. For changes to the running cluster, write the code for a fresh bootstrap and give separate manual steps. To rebuild the whole cluster, follow [the rebuild runbook](../docs/runbooks/full-cluster-rebuild.md).
|
||||||
|
|
||||||
|
The SSH key comes from `proxmox-infra`'s first `pulumi up`. VMs created before that need the public key added to `~/.ssh/authorized_keys` by hand.
|
||||||
@@ -8,3 +8,4 @@ config:
|
|||||||
pulumi:tags:
|
pulumi:tags:
|
||||||
value:
|
value:
|
||||||
pulumi:template: typescript
|
pulumi:template: typescript
|
||||||
|
stackConfigDir: ../.pulumi-config/02-k8s-bootstrap
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIF3TCCA8WgAwIBAgIUDXajbsIFjkrtUM/HEOAMI06xHjEwDQYJKoZIhvcNAQEL
|
||||||
|
BQAwdjEkMCIGA1UEAwwbUHJveG1veCBWaXJ0dWFsIEVudmlyb25tZW50MS0wKwYD
|
||||||
|
VQQLDCRiYTk0ZDJhZC0wOTc2LTRmZjAtODQ1Mi1kMjM1OGMxZGM3OGIxHzAdBgNV
|
||||||
|
BAoMFlBWRSBDbHVzdGVyIE1hbmFnZXIgQ0EwHhcNMjYxMTAzMDAwODM5WhcNMzYx
|
||||||
|
MDMxMDAwODM5WjB2MSQwIgYDVQQDDBtQcm94bW94IFZpcnR1YWwgRW52aXJvbm1l
|
||||||
|
bnQxLTArBgNVBAsMJGJhOTRkMmFkLTA5NzYtNGZmMC04NDUyLWQyMzU4YzFkYzc4
|
||||||
|
YjEfMB0GA1UECgwWUFZFIENsdXN0ZXIgTWFuYWdlciBDQTCCAiIwDQYJKoZIhvcN
|
||||||
|
AQEBBQADggIPADCCAgoCggIBAM1OPRmaMGdkrgVQikVCOFAF7eXL0H7lUfognG4A
|
||||||
|
Xi/D85bLKGJYF106PQFlmkvw+CvNIHCeeqvgDJc2AoV22PnKjPlP34b3j4AAoEm3
|
||||||
|
sMvKHke+N3kSfhG7hxZ8JfnV+EIZO1ZAI0X2z0ixmmn3gzIVjdtO9VycL7Nj2JJV
|
||||||
|
O+Ws+yc3j3swhVA87bIikc+sD0YT8F8dK41DQfgM01wWhieGLCk4g8DSbOt1Ypgv
|
||||||
|
hAwlKziUtUdw/teC8vmE0GwUMas/uwFVXzBEd/4ancI1SkPH/Mtu568HCVzcCBjE
|
||||||
|
wFAhdMZ90g7UXC58m5cFqs2PafDsAYv2rmSCic8yO2aZCO5nbQOtU9rN2b1e9KGs
|
||||||
|
xfDksugSJ2ZsIZ4YsG9Eao6WXkZIohANEhUkGK3yI4REiJO96/pmqf1QtNRvUZWW
|
||||||
|
YIxa56i2KrjB2RdGe9eirNlshTPA3DpJbLHmcsw1agPEI5mN4uQJ3DrSGrFwXHkB
|
||||||
|
QYW9NmgwLHUlOYdvUUq7AIY3RqCBWWkBW0vlg78W2fiaq1Gp6Mx/9HeVdriB2FGa
|
||||||
|
UlAE6CAzDI+JqQPQkmzo6QmFB3hFa9m1aPctLZo0bOKCeoyREBaPmmZfn6VaI1Xk
|
||||||
|
+mUIw6NLstdG0lS/qThNYbG5LWdRIyHdLcjsg19pFfmj9YUMphoMD7k2IG4Cu9nP
|
||||||
|
mwqlAgMBAAGjYzBhMB0GA1UdDgQWBBTKcVA3Li/Qe4f/vEsHFHc/VNVFHzAfBgNV
|
||||||
|
HSMEGDAWgBTKcVA3Li/Qe4f/vEsHFHc/VNVFHzAPBgNVHRMBAf8EBTADAQH/MA4G
|
||||||
|
A1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAgEAMLrQvbGlgpqxSaxQKb4N
|
||||||
|
wmmRQqgWvJ7/s9UhHE5BNfkUzJ+3ktAwfbswuNc4yfREjPqRBWzd/mz/WhlsDOzR
|
||||||
|
KT+ECQpNbnlR3JBJMYOiLDwKydnYWgiTiINxtc7p74NoGe/fu8dGKiGYtsk+bmps
|
||||||
|
yP1FOp3YQ2UM1NjQoalk2sZYOCRUL1HbgfaSHEwFXskJMKprUEEjJjXLxyJey14U
|
||||||
|
u6gSvUb2T8bbycW8Ilibo5Dn/DxLFBNT154M7GHQyVSdWLoEAVVzkrlJJ9b0RYnb
|
||||||
|
PQXOySSuIvrQx8QqG6X/4AfPrm2L1O8CAAwpNi3xa6jvVX6DWT1+HOhN8MfjtYJE
|
||||||
|
9KxbG6MNxnE8A39m46O2iYfwW+zTej842N1Fq6eA7i2nMuzHB3jqNVdvxaLCNK2a
|
||||||
|
FCAilpl2iuqO5eOWZG2Gd9qcPQSslRrhJid6GV/pTeh/ZpZyf/OG4XXata+IB2aq
|
||||||
|
0ggaQgGn5dFiCklLeFsnX0k0pydz/ZVA1v5C/sVk3q07JrPJo0IKs0SuS0lsHH9n
|
||||||
|
hPIdbUH3AsG850vDTIsKYgmZdssnG13bsGwZtC8x3MS1c868PRgG/ZycdT6BGk6Q
|
||||||
|
qX9ogoFrdUy3XYSRVDb2L+Z8NEI8grFOTDRXAlp5B4BHAbvXoIeeYjGtjtOunYCo
|
||||||
|
f3Em5SShmS4B2U/jTPyDeZ0=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIF3TCCA8WgAwIBAgIUUfheavZDUF4EvmQ6q8upF7dd74UwDQYJKoZIhvcNAQEL
|
||||||
|
BQAwdjEkMCIGA1UEAwwbUHJveG1veCBWaXJ0dWFsIEVudmlyb25tZW50MS0wKwYD
|
||||||
|
VQQLDCQxZWQ0Nzc1Yi1hMjc1LTQ3ZDktYTA1Mi1kM2M1MThhYjE2MzIxHzAdBgNV
|
||||||
|
BAoMFlBWRSBDbHVzdGVyIE1hbmFnZXIgQ0EwHhcNMjYxMTAyMDMzMDIxWhcNMzYx
|
||||||
|
MDMwMDMzMDIxWjB2MSQwIgYDVQQDDBtQcm94bW94IFZpcnR1YWwgRW52aXJvbm1l
|
||||||
|
bnQxLTArBgNVBAsMJDFlZDQ3NzViLWEyNzUtNDdkOS1hMDUyLWQzYzUxOGFiMTYz
|
||||||
|
MjEfMB0GA1UECgwWUFZFIENsdXN0ZXIgTWFuYWdlciBDQTCCAiIwDQYJKoZIhvcN
|
||||||
|
AQEBBQADggIPADCCAgoCggIBAK3vi3/3+0trXhEkDXoSrOFWTuXc7x7vPmORzQ6R
|
||||||
|
V/sg1X6KTbguzSPg71B/8Qu1vRYTkS6Pf5YclpE0P+z45hCV+G8B40cAL3D1Xpbo
|
||||||
|
JTznI2gaO00XDTei1MdDTC/mwUzoNBa7osXEmMwgz7Oid7WHJbIQegwq2LEMRbqQ
|
||||||
|
UtAXsAone1eq+N2vQys57MlnXnSbMFFlY1VNfUJIinjyLZgE9klFkvVFSqy9CkUs
|
||||||
|
4Yq9M6YSgvNA77tPSH/yc0605N1462x/VRHUkY4nufrWqI8oUlcGrK8mNieCtPK7
|
||||||
|
FOr3PZXq5K0I3LsSlbp7M43Bbumnuscg0ustyf/eCM7tdMQm9E5yfQsMH+Ao390x
|
||||||
|
nBrlpVqA6RSWGAeDhspuB6Sj+InVfzoLKvhqwzlGV5S+WT+uDN4VhRdGlet/kVC8
|
||||||
|
Xn5GIRgeGR/x5zs93Xxz9OEyVhSxPB6+NP/NJ4z7OD21Oiar7GUFzPbaMpWnSChW
|
||||||
|
5Vsp2i8HUikjUyiGb8nYZfVEHwj/w3JEs+m4eTwUroT4YgLRMwahye5gJTcq19oA
|
||||||
|
xFUzStAXEGglv5AVf0ngU3KTkwFP2ROLry/FIk6ZQSedJtnBpq0+CcMZe+vKSVD7
|
||||||
|
acFZ6k/bFh4jMeD9i1/Zx+mRf8XvZEeaImxYc0P9vnxfl2XP7QiroEP7PkuFZ6As
|
||||||
|
69rpAgMBAAGjYzBhMB0GA1UdDgQWBBSex+vVqEdCLAk0eKJiSfYltlTaKTAfBgNV
|
||||||
|
HSMEGDAWgBSex+vVqEdCLAk0eKJiSfYltlTaKTAPBgNVHRMBAf8EBTADAQH/MA4G
|
||||||
|
A1UdDwEB/wQEAwIBBjANBgkqhkiG9w0BAQsFAAOCAgEAkeVBiV4Zs+yoXKTcdy0A
|
||||||
|
Y7cEAGUY+zWQeg/eZnbNMWqG5x4UKWpA+9LZDOhAu7lBwkWoTlYLw6foDuy47uzQ
|
||||||
|
LBxqxI5gXkUi/CvIlOZ8AjuNdVU02wdDoib8O5mJDpvEMIOQawbRno84mlYdzhRs
|
||||||
|
BHeBugNdiORBk1JbqZjsvAmtlbjDaDNV0oxm9C5Np4F9sbA9lChkz+bv/KJxYexB
|
||||||
|
P91nonJfmyajDkWqrCaFIyjliNjfmff1CM2EpNDlngwXo6XjSgWjFuEVtHE2xl3t
|
||||||
|
J21a0WSxuIkQUNWJMcyr9j9LLAnZG06XCNEy6g2R8vMFmm3xGM76NkABkCsFT5PZ
|
||||||
|
lEmrAVmVDWKx2heAlVmVQ1wFrlGVYnlVxTWWcIHrHRCJJfc12tCwczbumBDxO45u
|
||||||
|
iJ5d4GI5HBSYz3kdMzzpBhLIH5l5h/AzmGebkhbSAK7I/V0kPOQvOVVrtCYr/Ec4
|
||||||
|
gU1AV6bjiu3USOeiAqkxW791Xp0IFkP+8e4FYohyG6QyS5jHtf0Vtl8/xJSKU9mj
|
||||||
|
idc4dwZSWu0V9LaNcMbk8kyRTvX/LwKuLOYp++a0/vxUMvgsv0yqeElvWAJB33xe
|
||||||
|
Ih/rsFCIC247ccQZ1g4JGHRJqRTAIQT4VsDqSRh+0KwarPvgJPEsluDB9bholfZ9
|
||||||
|
LoZqoymHgYm95H7LaDTdytA=
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
-----BEGIN CERTIFICATE-----
|
||||||
|
MIIFzTCCA7WgAwIBAgIUHFXkUXk2cmTrkKJxLSTvxhg5lfowDQYJKoZIhvcNAQEL
|
||||||
|
BQAwdjEkMCIGA1UEAwwbUHJveG1veCBWaXJ0dWFsIEVudmlyb25tZW50MS0wKwYD
|
||||||
|
VQQLDCQ4NzNhNGYzMS05YWQ2LTQ3MDYtYTg5MS0xZmU2NDIzNzgyYzQxHzAdBgNV
|
||||||
|
BAoMFlBWRSBDbHVzdGVyIE1hbmFnZXIgQ0EwHhcNMjUwODI5MjIzNjU5WhcNMzUw
|
||||||
|
ODI3MjIzNjU5WjB2MSQwIgYDVQQDDBtQcm94bW94IFZpcnR1YWwgRW52aXJvbm1l
|
||||||
|
bnQxLTArBgNVBAsMJDg3M2E0ZjMxLTlhZDYtNDcwNi1hODkxLTFmZTY0MjM3ODJj
|
||||||
|
NDEfMB0GA1UECgwWUFZFIENsdXN0ZXIgTWFuYWdlciBDQTCCAiIwDQYJKoZIhvcN
|
||||||
|
AQEBBQADggIPADCCAgoCggIBAL3iGXWp8BkVcXIpfVybY0slRl36bQp3OkswgTc9
|
||||||
|
awdsN62wWkN6NIa4yZsItzjHnCyte6Nac9qCmu25Pwhw4QEc7XRWuh4sVPvw4ica
|
||||||
|
0JgDw7yJbn8IM3C7qm9+g5iXoGcOdY41xsKJz7+cWgySh4EBPWYEuKOxtWuvTRzV
|
||||||
|
Q3b/o+LT8X/Q5qR7EehgLVy5KtWZCDjV/6862hh9zEiA87zosULHtVYAa1lWtL48
|
||||||
|
9q0flbQsIIFmaeio/iEJR66YHXTF7AlKaIrXLVCMRdRV6oef/b4SqECwnZVQnE28
|
||||||
|
I1uwnOV88MIfr9sINhdW7ogxSvlGFptkDkRVXnqfIOwLJjjPRuIifFg98KYR1gLp
|
||||||
|
vGMeRY96mJvJ98NUSeVZOQMVs8vnEXHlpPewsklQty23KQJTr42R5zIKXSguZZUU
|
||||||
|
NjNgDTPdUu45jNDu8nzU8guK3AcTkLbtmbL5uUCGZo860ScUFQUtuibou6plYVjx
|
||||||
|
Yca+mH3QoZI/lfnB/f2aNL9JP+DlTUfwTMgSAKiilOOqWvsHLjXvZjZupoAW0Xh4
|
||||||
|
CREKf0n5T9ldy6goRzbmWE475uc0UPtmLdlVrqt0F89YH8wZAlPu91a6pvomWUYX
|
||||||
|
pokkimWvPf3C+YgRDJIkolAQ1l+egnS/KR2tgLVEKktfXm4nRk2VotWOcsBDme40
|
||||||
|
Hwz3AgMBAAGjUzBRMB0GA1UdDgQWBBTK4krmBcFK3+fphDn5+DuknRdz4TAfBgNV
|
||||||
|
HSMEGDAWgBTK4krmBcFK3+fphDn5+DuknRdz4TAPBgNVHRMBAf8EBTADAQH/MA0G
|
||||||
|
CSqGSIb3DQEBCwUAA4ICAQCFW1DCfMOMTy/MvbYT8KKhwLujjjQvdKsgnRaktRzq
|
||||||
|
j66dohxWHiN0jDDgIeT1DkB/guh5pqcDnwVaiVZAagEJ/NvigTPRodTcijhomCzz
|
||||||
|
p9GCaMnl21YX2D5Ckg69iJ+AVekwNTHWqAVwbXZj1dpxs3SBceps9NQvzfNUI823
|
||||||
|
jDNpgYo9E4kymBIe8ibXNXiGbrZb171aqWzdJEdXIGmvbruXiIOwkkynJHViMo1Y
|
||||||
|
8RiUQx+NwGJw5NTTuHuCI0zYTxrqObPvtfwvyYEpaOf1fs246fRHDo8okffxLuMR
|
||||||
|
AbEVJuU4GCh3JhO5M1BUWEKllx4wZW8/ygtHc8TkKwxMQS86/bEptSoMn0TJ0XeC
|
||||||
|
YnnhML0XD0aRtcoqRhmfBjMntNeiHaAkXusLyc8LNyynhqWv3ldTw05JSfVSlhjC
|
||||||
|
paJNzLYYFa2VC/EG++1Kv6nvZjNZHzV34fkBw9dS6cJbhp5WK7WQgoZgIUF6kJN3
|
||||||
|
nEm0DzRUR6R4KjNgYJxmhXxHvKOeYyp52muiNkehFZ0d1/RdftgUvjh8pR7KEfSH
|
||||||
|
JaO5K0BWMy7infAcAOHb6krEMwfkr3NXUfF4pbuqNGQx5MHYfXkPiIdPy6q6ZqmO
|
||||||
|
ittFd5xKjL7J0QaDkAcxmJFJ2FdtQhoV14eKESBUdQV0NCSKXQgebkV5a8ik0mJU
|
||||||
|
GA==
|
||||||
|
-----END CERTIFICATE-----
|
||||||
@@ -0,0 +1,467 @@
|
|||||||
|
import * as pulumi from "@pulumi/pulumi";
|
||||||
|
import * as command from "@pulumi/command";
|
||||||
|
|
||||||
|
const config = new pulumi.Config();
|
||||||
|
|
||||||
|
// Bootstrap commands run once, on a fresh install. Without this, a changed VM
|
||||||
|
// ID, node IP, SSH key or command would re-run the k3s installer on the live
|
||||||
|
// cluster. After recreating a VM, re-run its commands explicitly with
|
||||||
|
// --target-replace.
|
||||||
|
pulumi.runtime.registerResourceTransform((args) =>
|
||||||
|
args.type.startsWith("command:")
|
||||||
|
? {
|
||||||
|
props: args.props,
|
||||||
|
opts: pulumi.mergeOptions(args.opts, {
|
||||||
|
ignoreChanges: [
|
||||||
|
"create",
|
||||||
|
"triggers",
|
||||||
|
"connection",
|
||||||
|
"environment",
|
||||||
|
"stdin",
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
);
|
||||||
|
|
||||||
|
const infraRef = new pulumi.StackReference(
|
||||||
|
`${pulumi.getOrganization()}/proxmox-infra/dev`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const pve1Endpoint = infraRef.requireOutput(
|
||||||
|
"pve1Endpoint",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
const pve1ApiToken = infraRef.requireOutput(
|
||||||
|
"pve1ApiToken",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
const pve2Endpoint = infraRef.requireOutput(
|
||||||
|
"pve2Endpoint",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
const pve2ApiToken = infraRef.requireOutput(
|
||||||
|
"pve2ApiToken",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
const pve3Endpoint = infraRef.requireOutput(
|
||||||
|
"pve3Endpoint",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
const pve3ApiToken = infraRef.requireOutput(
|
||||||
|
"pve3ApiToken",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
|
||||||
|
// Node IPs — static DHCP leases set in the router
|
||||||
|
const master1Ip = infraRef.requireOutput("master1Ip");
|
||||||
|
const master2Ip = infraRef.requireOutput("master2Ip");
|
||||||
|
const master3Ip = infraRef.requireOutput("master3Ip");
|
||||||
|
const worker1Ip = infraRef.requireOutput("worker1Ip");
|
||||||
|
const worker2Ip = infraRef.requireOutput("worker2Ip");
|
||||||
|
const worker3Ip = infraRef.requireOutput("worker3Ip");
|
||||||
|
|
||||||
|
// Pre-shared k3s cluster token
|
||||||
|
const k3sToken = config.requireSecret("k3sToken");
|
||||||
|
|
||||||
|
// Version for fresh installs. Changing it does not upgrade the live cluster.
|
||||||
|
const k3sVersion = "v1.36.2+k3s1";
|
||||||
|
const k3sInstallerUrl = `https://raw.githubusercontent.com/k3s-io/k3s/${encodeURIComponent(k3sVersion)}/install.sh`;
|
||||||
|
|
||||||
|
const secretsEncryptionArgs =
|
||||||
|
"--secrets-encryption --secrets-encryption-provider=secretbox";
|
||||||
|
|
||||||
|
// Runs the pinned installer. The token arrives on stdin and travels in the
|
||||||
|
// environment, so it never appears in process arguments.
|
||||||
|
function k3sInstallScript(
|
||||||
|
installEnv: pulumi.Input<string>,
|
||||||
|
installArgs: pulumi.Input<string>,
|
||||||
|
): pulumi.Output<string> {
|
||||||
|
return pulumi.interpolate`set -euo pipefail; IFS= read -r K3S_TOKEN || true; export K3S_TOKEN; curl -sfL ${k3sInstallerUrl} | sudo --preserve-env=K3S_TOKEN INSTALL_K3S_VERSION='${k3sVersion}' ${installEnv} sh -s - ${installArgs}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Control-plane VIP — floating IP for API server access, ARP-announced by
|
||||||
|
// kube-vip on whichever master is alive. Added as a TLS SAN on master-1's
|
||||||
|
// cert below, then used (instead of master1Ip) for every other node's join
|
||||||
|
// URL and for the exported kubeconfig, so the cluster stays reachable
|
||||||
|
// through the loss of any single master.
|
||||||
|
const controlPlaneVipAddress = config.requireSecret("controlPlaneVipAddress");
|
||||||
|
|
||||||
|
// VM IDs and CI runner SSH key — read from proxmox-infra stack outputs
|
||||||
|
const vmIdsOutput = infraRef.requireOutput("vmIds") as pulumi.Output<
|
||||||
|
Record<string, number>
|
||||||
|
>;
|
||||||
|
const ciRunnerPrivateKey = infraRef.requireOutput(
|
||||||
|
"ciRunnerPrivateKey",
|
||||||
|
) as pulumi.Output<string>;
|
||||||
|
|
||||||
|
const master1VmId = vmIdsOutput.apply((ids) => String(ids.master1));
|
||||||
|
const master2VmId = vmIdsOutput.apply((ids) => String(ids.master2));
|
||||||
|
const master3VmId = vmIdsOutput.apply((ids) => String(ids.master3));
|
||||||
|
const worker1VmId = vmIdsOutput.apply((ids) => String(ids.worker1));
|
||||||
|
const worker2VmId = vmIdsOutput.apply((ids) => String(ids.worker2));
|
||||||
|
const worker3VmId = vmIdsOutput.apply((ids) => String(ids.worker3));
|
||||||
|
|
||||||
|
// SSH connection helper
|
||||||
|
function conn(
|
||||||
|
ip: pulumi.Input<string>,
|
||||||
|
): command.types.input.remote.ConnectionArgs {
|
||||||
|
return { host: ip, user: "ubuntu", privateKey: ciRunnerPrivateKey };
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 1: Start all VMs (VMs are owned by proxmox-infra)
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Succeeds if the VM is already running, or reaches running after a start.
|
||||||
|
// TLS is verified against the host's Proxmox CA in certs/. The API token comes
|
||||||
|
// from PVE_API_TOKEN and reaches curl on stdin, keeping it out of process
|
||||||
|
// arguments.
|
||||||
|
function startVmScript(
|
||||||
|
endpoint: pulumi.Input<string>,
|
||||||
|
caName: string,
|
||||||
|
nodeName: string,
|
||||||
|
vmId: pulumi.Input<string>,
|
||||||
|
): pulumi.Output<string> {
|
||||||
|
return pulumi.interpolate`base="${endpoint}/api2/json/nodes/${nodeName}/qemu/${vmId}/status"; ca="certs/${caName}-ca.pem"; auth() { printf 'header = "Authorization: PVEAPIToken=%s"
|
||||||
|
' "$PVE_API_TOKEN"; }; is_running() { auth | curl -sf -K - --cacert "$ca" "$base/current" | grep -Eq '"status" *: *"running"'; }; is_running && exit 0; auth | curl -sf -K - --cacert "$ca" -X POST "$base/start" >/dev/null || exit 1; for i in $(seq 1 30); do is_running && exit 0; sleep 2; done; exit 1`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startMaster1 = new command.local.Command("start-master-1", {
|
||||||
|
create: startVmScript(pve1Endpoint, "pve1", "pve", master1VmId),
|
||||||
|
environment: { PVE_API_TOKEN: pve1ApiToken },
|
||||||
|
triggers: [master1VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
});
|
||||||
|
const startMaster2 = new command.local.Command("start-master-2", {
|
||||||
|
create: startVmScript(pve3Endpoint, "pve3", "pve", master2VmId),
|
||||||
|
environment: { PVE_API_TOKEN: pve3ApiToken },
|
||||||
|
triggers: [master2VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
});
|
||||||
|
const startWorker1 = new command.local.Command("start-worker-1", {
|
||||||
|
create: startVmScript(pve1Endpoint, "pve1", "pve", worker1VmId),
|
||||||
|
environment: { PVE_API_TOKEN: pve1ApiToken },
|
||||||
|
triggers: [worker1VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
});
|
||||||
|
const startMaster3 = new command.local.Command("start-master-3", {
|
||||||
|
create: startVmScript(pve2Endpoint, "pve2", "pve-bckp", master3VmId),
|
||||||
|
environment: { PVE_API_TOKEN: pve2ApiToken },
|
||||||
|
triggers: [master3VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
});
|
||||||
|
const startWorker2 = new command.local.Command("start-worker-2", {
|
||||||
|
create: startVmScript(pve2Endpoint, "pve2", "pve-bckp", worker2VmId),
|
||||||
|
environment: { PVE_API_TOKEN: pve2ApiToken },
|
||||||
|
triggers: [worker2VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
});
|
||||||
|
const startWorker3 = new command.local.Command("start-worker-3", {
|
||||||
|
create: startVmScript(pve3Endpoint, "pve3", "pve", worker3VmId),
|
||||||
|
environment: { PVE_API_TOKEN: pve3ApiToken },
|
||||||
|
triggers: [worker3VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const allStarts = [
|
||||||
|
startMaster1,
|
||||||
|
startMaster2,
|
||||||
|
startMaster3,
|
||||||
|
startWorker1,
|
||||||
|
startWorker2,
|
||||||
|
startWorker3,
|
||||||
|
];
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 2: Wait for SSH on master-1, install k3s
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const waitMaster1Ssh = new command.local.Command(
|
||||||
|
"wait-ssh-master-1",
|
||||||
|
{
|
||||||
|
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master1Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
||||||
|
triggers: [master1VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
},
|
||||||
|
{ dependsOn: allStarts },
|
||||||
|
);
|
||||||
|
|
||||||
|
const installMaster1 = new command.remote.Command(
|
||||||
|
"install-k3s-master-1",
|
||||||
|
{
|
||||||
|
connection: conn(master1Ip),
|
||||||
|
create: k3sInstallScript(
|
||||||
|
"",
|
||||||
|
pulumi.interpolate`server --cluster-init --tls-san ${master1Ip} --tls-san ${controlPlaneVipAddress} --disable servicelb ${secretsEncryptionArgs} --node-name k3s-master-1`,
|
||||||
|
),
|
||||||
|
stdin: k3sToken,
|
||||||
|
triggers: [master1VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitMaster1Ssh] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const waitK3sMaster1Ready = new command.remote.Command(
|
||||||
|
"wait-k3s-master-1-ready",
|
||||||
|
{
|
||||||
|
connection: conn(master1Ip),
|
||||||
|
create: `for i in $(seq 1 60); do sudo kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml get node k3s-master-1 --no-headers 2>/dev/null | grep -q " Ready" && exit 0; sleep 10; done; exit 1`,
|
||||||
|
triggers: [master1VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [installMaster1] },
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 3: Confirm the control-plane VIP is actually reachable before anyone
|
||||||
|
// else joins, so master-2/master-3 and every worker join through the VIP
|
||||||
|
// instead of master1Ip directly. The VIP itself is NOT managed here (or by
|
||||||
|
// any Pulumi stack) — it's a pfSense IP Alias Virtual IP with HAProxy
|
||||||
|
// TCP-load-balancing 6443 across all three masters, set up manually (see
|
||||||
|
// "pfSense one-time setup" in this stack's CLAUDE.md). This intentionally
|
||||||
|
// avoids a second kube-vip/ARP-based VIP for something as critical as API
|
||||||
|
// access — 03-k8s-infra's existing kube-vip DaemonSet already handles
|
||||||
|
// Service/LoadBalancer VIPs (e.g. Traefik) separately, entirely inside the
|
||||||
|
// cluster.
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const waitControlPlaneVipReady = new command.remote.Command(
|
||||||
|
"wait-control-plane-vip-ready",
|
||||||
|
{
|
||||||
|
connection: conn(master1Ip),
|
||||||
|
// 401/403 still prove the API server answered through the VIP: the request
|
||||||
|
// is anonymous, and some clusters reject anonymous health checks.
|
||||||
|
create: pulumi.interpolate`for i in $(seq 1 60); do code=$(curl -sk --max-time 3 -o /dev/null -w '%{http_code}' https://${controlPlaneVipAddress}:6443/healthz); case "$code" in 200|401|403) exit 0;; esac; sleep 5; done; exit 1`,
|
||||||
|
triggers: [master1VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitK3sMaster1Ready] },
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 4: Wait for SSH on remaining masters, join cluster via the VIP
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const waitMaster2Ssh = new command.local.Command(
|
||||||
|
"wait-ssh-master-2",
|
||||||
|
{
|
||||||
|
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master2Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
||||||
|
triggers: [master2VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitK3sMaster1Ready] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const waitMaster3Ssh = new command.local.Command(
|
||||||
|
"wait-ssh-master-3",
|
||||||
|
{
|
||||||
|
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master3Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
||||||
|
triggers: [master3VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitK3sMaster1Ready] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const joinMaster2 = new command.remote.Command(
|
||||||
|
"join-k3s-master-2",
|
||||||
|
{
|
||||||
|
connection: conn(master2Ip),
|
||||||
|
create: k3sInstallScript(
|
||||||
|
"",
|
||||||
|
pulumi.interpolate`server --server https://${controlPlaneVipAddress}:6443 --disable servicelb ${secretsEncryptionArgs} --node-name k3s-master-2`,
|
||||||
|
),
|
||||||
|
stdin: k3sToken,
|
||||||
|
triggers: [master2VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitMaster2Ssh, waitControlPlaneVipReady] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const joinMaster3 = new command.remote.Command(
|
||||||
|
"join-k3s-master-3",
|
||||||
|
{
|
||||||
|
connection: conn(master3Ip),
|
||||||
|
create: k3sInstallScript(
|
||||||
|
"",
|
||||||
|
pulumi.interpolate`server --server https://${controlPlaneVipAddress}:6443 --disable servicelb ${secretsEncryptionArgs} --node-name k3s-master-3`,
|
||||||
|
),
|
||||||
|
stdin: k3sToken,
|
||||||
|
triggers: [master3VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitMaster3Ssh, waitControlPlaneVipReady, joinMaster2] },
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 5: Join worker nodes via the VIP
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const waitWorker1Ssh = new command.local.Command(
|
||||||
|
"wait-ssh-worker-1",
|
||||||
|
{
|
||||||
|
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker1Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
||||||
|
triggers: [worker1VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
},
|
||||||
|
{ dependsOn: [joinMaster3] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const waitWorker2Ssh = new command.local.Command(
|
||||||
|
"wait-ssh-worker-2",
|
||||||
|
{
|
||||||
|
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker2Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
||||||
|
triggers: [worker2VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
},
|
||||||
|
{ dependsOn: [joinMaster3] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const waitWorker3Ssh = new command.local.Command(
|
||||||
|
"wait-ssh-worker-3",
|
||||||
|
{
|
||||||
|
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker3Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
||||||
|
triggers: [worker3VmId],
|
||||||
|
interpreter: ["/bin/bash", "-c"],
|
||||||
|
},
|
||||||
|
{ dependsOn: [joinMaster3] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const joinWorker1 = new command.remote.Command(
|
||||||
|
"join-k3s-worker-1",
|
||||||
|
{
|
||||||
|
connection: conn(worker1Ip),
|
||||||
|
create: k3sInstallScript(
|
||||||
|
pulumi.interpolate`K3S_URL=https://${controlPlaneVipAddress}:6443`,
|
||||||
|
"--node-name k3s-worker-1",
|
||||||
|
),
|
||||||
|
stdin: k3sToken,
|
||||||
|
triggers: [worker1VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitWorker1Ssh] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const joinWorker2 = new command.remote.Command(
|
||||||
|
"join-k3s-worker-2",
|
||||||
|
{
|
||||||
|
connection: conn(worker2Ip),
|
||||||
|
create: k3sInstallScript(
|
||||||
|
pulumi.interpolate`K3S_URL=https://${controlPlaneVipAddress}:6443`,
|
||||||
|
"--node-name k3s-worker-2",
|
||||||
|
),
|
||||||
|
stdin: k3sToken,
|
||||||
|
triggers: [worker2VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitWorker2Ssh] },
|
||||||
|
);
|
||||||
|
|
||||||
|
const joinWorker3 = new command.remote.Command(
|
||||||
|
"join-k3s-worker-3",
|
||||||
|
{
|
||||||
|
connection: conn(worker3Ip),
|
||||||
|
create: k3sInstallScript(
|
||||||
|
pulumi.interpolate`K3S_URL=https://${controlPlaneVipAddress}:6443`,
|
||||||
|
"--node-name k3s-worker-3",
|
||||||
|
),
|
||||||
|
stdin: k3sToken,
|
||||||
|
triggers: [worker3VmId],
|
||||||
|
},
|
||||||
|
{ dependsOn: [waitWorker3Ssh] },
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 6: Format and mount Longhorn disks
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const workers = [worker1Ip, worker2Ip, worker3Ip];
|
||||||
|
const workerSshReader = [waitWorker1Ssh, waitWorker2Ssh, waitWorker3Ssh];
|
||||||
|
|
||||||
|
workers.forEach((worker, i) => {
|
||||||
|
return new command.remote.Command(
|
||||||
|
`mount-longhorn-disk-${i}`,
|
||||||
|
{
|
||||||
|
connection: conn(worker),
|
||||||
|
create: `set -euo pipefail;
|
||||||
|
DISK_ID=$(ls /dev/disk/by-id/ | grep 'scsi1');
|
||||||
|
[ "$(echo "$DISK_ID" | wc -l)" -eq 1 ];
|
||||||
|
DISK_PATH="/dev/disk/by-id/$DISK_ID";
|
||||||
|
BLKID_RC=0;
|
||||||
|
sudo blkid -p "$DISK_PATH" >/dev/null 2>&1 || BLKID_RC=$?;
|
||||||
|
if [ "$BLKID_RC" -eq 2 ]; then sudo mkfs.ext4 "$DISK_PATH"; elif [ "$BLKID_RC" -ne 0 ]; then exit "$BLKID_RC"; fi;
|
||||||
|
sudo mkdir -p /mnt/longhorn-extra;
|
||||||
|
grep -qs " /mnt/longhorn-extra " /etc/fstab || echo "$DISK_PATH /mnt/longhorn-extra ext4 defaults,nofail 0 2" | sudo tee -a /etc/fstab;
|
||||||
|
sudo mount -a;
|
||||||
|
mountpoint -q /mnt/longhorn-extra;
|
||||||
|
df -h /mnt/longhorn-extra`,
|
||||||
|
},
|
||||||
|
{ dependsOn: workerSshReader[i] },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 7: Read kubeconfig from master-1, patch server URL to the VIP
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const getKubeconfig = new command.remote.Command(
|
||||||
|
"get-kubeconfig",
|
||||||
|
{
|
||||||
|
connection: conn(master1Ip),
|
||||||
|
create: `sudo cat /etc/rancher/k3s/k3s.yaml`,
|
||||||
|
triggers: [master1VmId],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
dependsOn: [joinWorker1, joinWorker2, joinWorker3],
|
||||||
|
additionalSecretOutputs: ["stdout"],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// Step 8: Install additional packages
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
const allVms = [
|
||||||
|
{
|
||||||
|
id: master1VmId,
|
||||||
|
ip: master1Ip,
|
||||||
|
name: "master-1",
|
||||||
|
readiness: waitMaster1Ssh,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: master2VmId,
|
||||||
|
ip: master2Ip,
|
||||||
|
name: "master-2",
|
||||||
|
readiness: waitMaster2Ssh,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: master3VmId,
|
||||||
|
ip: master3Ip,
|
||||||
|
name: "master-3",
|
||||||
|
readiness: waitMaster3Ssh,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: worker1VmId,
|
||||||
|
ip: worker1Ip,
|
||||||
|
name: "worker-1",
|
||||||
|
readiness: waitWorker1Ssh,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: worker2VmId,
|
||||||
|
ip: worker2Ip,
|
||||||
|
name: "worker-2",
|
||||||
|
readiness: waitWorker2Ssh,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: worker3VmId,
|
||||||
|
ip: worker3Ip,
|
||||||
|
name: "worker-3",
|
||||||
|
readiness: waitWorker3Ssh,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
allVms.forEach(({ id, ip, name, readiness }) => {
|
||||||
|
new command.remote.Command(
|
||||||
|
`install-packages-${name}`,
|
||||||
|
{
|
||||||
|
connection: conn(ip),
|
||||||
|
// cloud-init exit code 2 means it finished with recoverable errors.
|
||||||
|
create: pulumi.interpolate`{ sudo cloud-init status --wait >/dev/null || [ $? -eq 2 ]; } && sudo apt-get -o DPkg::Lock::Timeout=300 update && sudo apt-get -o DPkg::Lock::Timeout=300 install -y qemu-guest-agent && sudo systemctl enable --now qemu-guest-agent`,
|
||||||
|
triggers: [id],
|
||||||
|
},
|
||||||
|
{ dependsOn: readiness },
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const kubeconfig = pulumi.secret(
|
||||||
|
pulumi
|
||||||
|
.all([getKubeconfig.stdout, controlPlaneVipAddress])
|
||||||
|
.apply(([kc, vip]) => kc.replaceAll("127.0.0.1", vip as string).trim()),
|
||||||
|
);
|
||||||
Generated
+1344
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "k8s-bootstrap",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.0.0",
|
||||||
|
"typescript": "^6.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pulumi/command": "^1.2.1",
|
||||||
|
"@pulumi/pulumi": "^3.244.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"outDir": "bin",
|
"outDir": "bin",
|
||||||
"target": "es2020",
|
"target": "es2024",
|
||||||
"module": "nodenext",
|
"module": "nodenext",
|
||||||
"moduleResolution": "nodenext",
|
"moduleResolution": "nodenext",
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# k8s-infra
|
||||||
|
|
||||||
|
- **k3s's built-in ServiceLB is not used.** kube-vip ARP-announces LoadBalancer VIPs, and kube-vip-cloud-provider allocates them from a single-address pool (`kubeVipAddress`). Traefik's LoadBalancer IP is pinned to that address.
|
||||||
|
- **Longhorn stays off the root disk.** Worker nodes get an extra `longhorn-extra` disk at `/mnt/longhorn-extra` (mounted by `k8s-bootstrap`, registered on the Longhorn `Node` CR here) to avoid `DiskPressure`. `nodeDownPodDeletionPolicy` deletes StatefulSet and Deployment pods on node-down so stateful workloads reschedule.
|
||||||
|
- The TrueNAS dataset and NFS share are created by hand before deploying, see [the runbook](../docs/runbooks/truenas-nfs.md).
|
||||||
|
- Needs the `helm` CLI; CI installs it with `azure/setup-helm`.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
name: k8s-infra
|
||||||
|
description: Cluster-level infrastructure for the k3s homelab cluster
|
||||||
|
runtime:
|
||||||
|
name: nodejs
|
||||||
|
options:
|
||||||
|
packagemanager: npm
|
||||||
|
stackConfigDir: ../.pulumi-config/03-k8s-infra
|
||||||
@@ -0,0 +1,561 @@
|
|||||||
|
import * as pulumi from "@pulumi/pulumi";
|
||||||
|
import * as k8s from "@pulumi/kubernetes";
|
||||||
|
|
||||||
|
const config = new pulumi.Config();
|
||||||
|
|
||||||
|
const bootstrapRef = new pulumi.StackReference(
|
||||||
|
`${pulumi.getOrganization()}/k8s-bootstrap/dev`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeconfig = bootstrapRef.requireOutput("kubeconfig");
|
||||||
|
|
||||||
|
export const nfsStorageClass = "truenas-nfs";
|
||||||
|
const truenasHost = config.requireSecret("truenasHost");
|
||||||
|
const truenasNfsPath = config.requireSecret("truenasNfsPath");
|
||||||
|
|
||||||
|
const cloudflareToken = config.requireSecret("cloudflareApiToken");
|
||||||
|
const letsencryptEmail = config.requireSecret("letsencryptEmail");
|
||||||
|
|
||||||
|
const kubeVipAddress = config.requireSecret("kubeVipAddress");
|
||||||
|
const kubeVipInterface = config.require("kubeVipInterface");
|
||||||
|
|
||||||
|
const domain = config.requireSecret("domain");
|
||||||
|
const longhornUiUser = config.requireSecret("longhornUiUser");
|
||||||
|
const longhornUiPassword = config.requireSecret("longhornUiPassword");
|
||||||
|
|
||||||
|
// A fixed identifier makes kubeconfig changes (e.g. a new API address) provider
|
||||||
|
// updates. Without it, they replace the provider and every resource in this
|
||||||
|
// stack. Changing this value triggers that replacement, so never change it.
|
||||||
|
const k8sProvider = new k8s.Provider("k3s", {
|
||||||
|
kubeconfig,
|
||||||
|
clusterIdentifier: "homelab-k3s",
|
||||||
|
});
|
||||||
|
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
|
||||||
|
provider: k8sProvider,
|
||||||
|
...extras,
|
||||||
|
});
|
||||||
|
|
||||||
|
// ── NFS CSI Driver ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const nfsCsiDriver = new k8s.helm.v3.Release(
|
||||||
|
"nfs-csi-driver",
|
||||||
|
{
|
||||||
|
name: "csi-driver-nfs",
|
||||||
|
chart: "csi-driver-nfs",
|
||||||
|
repositoryOpts: {
|
||||||
|
repo: "https://raw.githubusercontent.com/kubernetes-csi/csi-driver-nfs/master/charts",
|
||||||
|
},
|
||||||
|
namespace: "kube-system",
|
||||||
|
version: "4.12.0",
|
||||||
|
values: {
|
||||||
|
kubeletDir: "/var/lib/kubelet",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
new k8s.storage.v1.StorageClass(
|
||||||
|
nfsStorageClass,
|
||||||
|
{
|
||||||
|
metadata: { name: nfsStorageClass },
|
||||||
|
provisioner: "nfs.csi.k8s.io",
|
||||||
|
parameters: {
|
||||||
|
server: truenasHost,
|
||||||
|
share: truenasNfsPath,
|
||||||
|
mountPermissions: "0",
|
||||||
|
},
|
||||||
|
reclaimPolicy: "Retain",
|
||||||
|
volumeBindingMode: "Immediate",
|
||||||
|
allowVolumeExpansion: true,
|
||||||
|
mountOptions: ["nfsvers=4.1"],
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [nfsCsiDriver] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ── cert-manager ──────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const certManager = new k8s.helm.v3.Release(
|
||||||
|
"cert-manager",
|
||||||
|
{
|
||||||
|
name: "cert-manager",
|
||||||
|
chart: "cert-manager",
|
||||||
|
version: "v1.21.1",
|
||||||
|
repositoryOpts: { repo: "https://charts.jetstack.io" },
|
||||||
|
namespace: "cert-manager",
|
||||||
|
createNamespace: true,
|
||||||
|
timeout: 600,
|
||||||
|
values: {
|
||||||
|
crds: { enabled: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ── Cloudflare token secret + ClusterIssuer ───────────────────────────────
|
||||||
|
|
||||||
|
const cfSecret = new k8s.core.v1.Secret(
|
||||||
|
"cloudflare-token",
|
||||||
|
{
|
||||||
|
metadata: { name: "cloudflare-api-token", namespace: "cert-manager" },
|
||||||
|
stringData: { "api-token": cloudflareToken },
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [certManager] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
new k8s.apiextensions.CustomResource(
|
||||||
|
"letsencrypt-prod",
|
||||||
|
{
|
||||||
|
apiVersion: "cert-manager.io/v1",
|
||||||
|
kind: "ClusterIssuer",
|
||||||
|
metadata: { name: "letsencrypt-prod" },
|
||||||
|
spec: {
|
||||||
|
acme: {
|
||||||
|
server: "https://acme-v02.api.letsencrypt.org/directory",
|
||||||
|
email: letsencryptEmail,
|
||||||
|
privateKeySecretRef: { name: "letsencrypt-prod-account-key" },
|
||||||
|
solvers: [
|
||||||
|
{
|
||||||
|
dns01: {
|
||||||
|
cloudflare: {
|
||||||
|
apiTokenSecretRef: {
|
||||||
|
name: cfSecret.metadata.name,
|
||||||
|
key: "api-token",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [certManager, cfSecret] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ── Longhorn ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const longhorn = new k8s.helm.v3.Release(
|
||||||
|
"longhorn",
|
||||||
|
{
|
||||||
|
name: "longhorn",
|
||||||
|
chart: "longhorn",
|
||||||
|
repositoryOpts: { repo: "https://charts.longhorn.io" },
|
||||||
|
namespace: "longhorn-system",
|
||||||
|
createNamespace: true,
|
||||||
|
version: "1.12.0",
|
||||||
|
values: {
|
||||||
|
defaultSettings: {
|
||||||
|
defaultReplicaCount: 3,
|
||||||
|
nodeDownPodDeletionPolicy: "delete-both-statefulset-and-deployment-pod",
|
||||||
|
createDefaultDiskLabeledNodes: true,
|
||||||
|
orphanResourceAutoDeletion: "replica-data;instance",
|
||||||
|
// Longhorn's recommendation for dedicated disks (longhorn-extra).
|
||||||
|
// Docs: https://longhorn.io/docs/1.12.0/best-practices/
|
||||||
|
storageMinimalAvailablePercentage: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Purges system snapshots, which can otherwise grow to a full volume's size
|
||||||
|
// on every replica. Docs:
|
||||||
|
// https://longhorn.io/docs/1.12.0/snapshots-and-backups/scheduling-backups-and-snapshots/
|
||||||
|
new k8s.apiextensions.CustomResource(
|
||||||
|
"longhorn-snapshot-cleanup",
|
||||||
|
{
|
||||||
|
apiVersion: "longhorn.io/v1beta2",
|
||||||
|
kind: "RecurringJob",
|
||||||
|
metadata: { name: "snapshot-cleanup", namespace: "longhorn-system" },
|
||||||
|
spec: {
|
||||||
|
name: "snapshot-cleanup",
|
||||||
|
task: "snapshot-cleanup",
|
||||||
|
cron: "30 3 * * *",
|
||||||
|
groups: ["default"],
|
||||||
|
retain: 0,
|
||||||
|
concurrency: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Returns blocks deleted inside a volume (e.g. expired Prometheus data) to the
|
||||||
|
// disk. Runs after snapshot-cleanup, since trim can't reclaim valid snapshots.
|
||||||
|
// Docs: https://longhorn.io/docs/1.12.0/nodes-and-volumes/volumes/trim-filesystem/
|
||||||
|
new k8s.apiextensions.CustomResource(
|
||||||
|
"longhorn-filesystem-trim",
|
||||||
|
{
|
||||||
|
apiVersion: "longhorn.io/v1beta2",
|
||||||
|
kind: "RecurringJob",
|
||||||
|
metadata: { name: "filesystem-trim", namespace: "longhorn-system" },
|
||||||
|
spec: {
|
||||||
|
name: "filesystem-trim",
|
||||||
|
task: "filesystem-trim",
|
||||||
|
cron: "30 4 * * *",
|
||||||
|
groups: ["default"],
|
||||||
|
retain: 0,
|
||||||
|
concurrency: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Patches Longhorn instances to use the mountend Longhorn storage on the worker nodes.
|
||||||
|
["k3s-worker-1", "k3s-worker-2", "k3s-worker-3"].forEach(
|
||||||
|
(nodeName) =>
|
||||||
|
new k8s.apiextensions.CustomResourcePatch(
|
||||||
|
`${nodeName}-longhorn-disks`,
|
||||||
|
{
|
||||||
|
apiVersion: "longhorn.io/v1beta2",
|
||||||
|
kind: "Node",
|
||||||
|
metadata: {
|
||||||
|
name: nodeName,
|
||||||
|
namespace: "longhorn-system",
|
||||||
|
annotations: { "pulumi.com/patchForce": "true" },
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
disks: {
|
||||||
|
"longhorn-extra": {
|
||||||
|
allowScheduling: true,
|
||||||
|
diskDriver: "",
|
||||||
|
diskType: "filesystem",
|
||||||
|
evictionRequested: false,
|
||||||
|
path: "/mnt/longhorn-extra",
|
||||||
|
storageReserved: 0,
|
||||||
|
tags: [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn] }),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ── Longhorn UI ───────────────────────────────────────────────────────────
|
||||||
|
// Docs: https://longhorn.io/docs/1.12.0/deploy/accessing-the-ui/longhorn-ingress-traefik/
|
||||||
|
// https://doc.traefik.io/traefik/reference/routing-configuration/http/middlewares/basicauth/
|
||||||
|
|
||||||
|
const longhornUiAuthSecret = new k8s.core.v1.Secret(
|
||||||
|
"longhorn-ui-basic-auth",
|
||||||
|
{
|
||||||
|
metadata: { name: "longhorn-ui-basic-auth", namespace: "longhorn-system" },
|
||||||
|
type: "kubernetes.io/basic-auth",
|
||||||
|
stringData: { username: longhornUiUser, password: longhornUiPassword },
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fixed name: the Ingress references it as <namespace>-<name>@kubernetescrd.
|
||||||
|
const longhornUiAuth = new k8s.apiextensions.CustomResource(
|
||||||
|
"longhorn-ui-auth",
|
||||||
|
{
|
||||||
|
apiVersion: "traefik.io/v1alpha1",
|
||||||
|
kind: "Middleware",
|
||||||
|
metadata: { name: "longhorn-ui-auth", namespace: "longhorn-system" },
|
||||||
|
spec: { basicAuth: { secret: longhornUiAuthSecret.metadata.name } },
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const longhornUiHost = pulumi.interpolate`longhorn.${domain}`;
|
||||||
|
|
||||||
|
new k8s.networking.v1.Ingress(
|
||||||
|
"longhorn-ui",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "longhorn-ui",
|
||||||
|
namespace: "longhorn-system",
|
||||||
|
annotations: {
|
||||||
|
"cert-manager.io/cluster-issuer": "letsencrypt-prod",
|
||||||
|
"traefik.ingress.kubernetes.io/router.middlewares":
|
||||||
|
"longhorn-system-longhorn-ui-auth@kubernetescrd",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
ingressClassName: "traefik",
|
||||||
|
tls: [{ hosts: [longhornUiHost], secretName: "longhorn-ui-tls" }],
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
host: longhornUiHost,
|
||||||
|
http: {
|
||||||
|
paths: [
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
pathType: "Prefix",
|
||||||
|
backend: {
|
||||||
|
service: { name: "longhorn-frontend", port: { number: 80 } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [longhorn, longhornUiAuth] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// ── kube-vip ────────────
|
||||||
|
|
||||||
|
const kubeVipNamespace = "kube-system";
|
||||||
|
const controlPlaneTolerations = [
|
||||||
|
{ key: "node-role.kubernetes.io/master", effect: "NoSchedule" },
|
||||||
|
{ key: "node-role.kubernetes.io/control-plane", effect: "NoSchedule" },
|
||||||
|
];
|
||||||
|
|
||||||
|
// Keeps regular workloads off the master nodes; kube-vip and
|
||||||
|
// kube-vip-cloud-provider below explicitly tolerate these same taints.
|
||||||
|
["k3s-master-1", "k3s-master-2", "k3s-master-3"].forEach((nodeName) => {
|
||||||
|
new k8s.core.v1.NodePatch(
|
||||||
|
`${nodeName}-control-plane-taint`,
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: nodeName,
|
||||||
|
annotations: { "pulumi.com/patchForce": "true" },
|
||||||
|
},
|
||||||
|
spec: { taints: controlPlaneTolerations },
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
const kubeVipServiceAccount = new k8s.core.v1.ServiceAccount(
|
||||||
|
"kube-vip",
|
||||||
|
{ metadata: { name: "kube-vip", namespace: kubeVipNamespace } },
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeVipClusterRole = new k8s.rbac.v1.ClusterRole(
|
||||||
|
"kube-vip-role",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "system:kube-vip-role",
|
||||||
|
annotations: { "rbac.authorization.kubernetes.io/autoupdate": "true" },
|
||||||
|
},
|
||||||
|
rules: [
|
||||||
|
{ apiGroups: [""], resources: ["services/status"], verbs: ["update"] },
|
||||||
|
{
|
||||||
|
apiGroups: [""],
|
||||||
|
resources: ["services", "endpoints"],
|
||||||
|
verbs: ["list", "get", "watch", "update"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
apiGroups: [""],
|
||||||
|
resources: ["nodes"],
|
||||||
|
verbs: ["list", "get", "watch", "update", "patch"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
apiGroups: ["coordination.k8s.io"],
|
||||||
|
resources: ["leases"],
|
||||||
|
verbs: ["list", "get", "watch", "update", "create"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
apiGroups: ["discovery.k8s.io"],
|
||||||
|
resources: ["endpointslices"],
|
||||||
|
verbs: ["list", "get", "watch", "update"],
|
||||||
|
},
|
||||||
|
{ apiGroups: [""], resources: ["pods"], verbs: ["list"] },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeVipClusterRoleBinding = new k8s.rbac.v1.ClusterRoleBinding(
|
||||||
|
"kube-vip-binding",
|
||||||
|
{
|
||||||
|
metadata: { name: "system:kube-vip-binding" },
|
||||||
|
roleRef: {
|
||||||
|
apiGroup: "rbac.authorization.k8s.io",
|
||||||
|
kind: "ClusterRole",
|
||||||
|
name: kubeVipClusterRole.metadata.name,
|
||||||
|
},
|
||||||
|
subjects: [
|
||||||
|
{
|
||||||
|
kind: "ServiceAccount",
|
||||||
|
name: kubeVipServiceAccount.metadata.name,
|
||||||
|
namespace: kubeVipNamespace,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeVipLabels = { name: "kube-vip-ds" };
|
||||||
|
|
||||||
|
const kubeVip = new k8s.apps.v1.DaemonSet(
|
||||||
|
"kube-vip",
|
||||||
|
{
|
||||||
|
metadata: { name: "kube-vip-ds", namespace: kubeVipNamespace },
|
||||||
|
spec: {
|
||||||
|
selector: { matchLabels: kubeVipLabels },
|
||||||
|
template: {
|
||||||
|
metadata: { labels: kubeVipLabels },
|
||||||
|
spec: {
|
||||||
|
serviceAccountName: kubeVipServiceAccount.metadata.name,
|
||||||
|
hostNetwork: true,
|
||||||
|
tolerations: [
|
||||||
|
...controlPlaneTolerations.map((t) => ({
|
||||||
|
...t,
|
||||||
|
operator: "Exists",
|
||||||
|
})),
|
||||||
|
{ effect: "NoExecute", operator: "Exists" },
|
||||||
|
],
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: "kube-vip",
|
||||||
|
image: "ghcr.io/kube-vip/kube-vip:v1.2.0",
|
||||||
|
imagePullPolicy: "Always",
|
||||||
|
args: ["manager"],
|
||||||
|
env: [
|
||||||
|
{ name: "vip_arp", value: "true" },
|
||||||
|
{ name: "vip_interface", value: kubeVipInterface },
|
||||||
|
{ name: "vip_subnet", value: "32" },
|
||||||
|
{ name: "cp_enable", value: "false" },
|
||||||
|
{ name: "svc_enable", value: "true" },
|
||||||
|
{ name: "svc_election", value: "true" },
|
||||||
|
{ name: "vip_leaderelection", value: "true" },
|
||||||
|
],
|
||||||
|
securityContext: {
|
||||||
|
capabilities: { add: ["NET_ADMIN", "NET_RAW"] },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [kubeVipClusterRoleBinding] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
// -- kube-vip-cloud-provider: allocates LoadBalancer IPs for Services on bare-metal
|
||||||
|
// k3s (replacing the disabled ServiceLB). The DaemonSet above only *announces* IPs
|
||||||
|
// via ARP; this controller is what actually assigns them to Service.status.
|
||||||
|
|
||||||
|
const cloudProviderServiceAccount = new k8s.core.v1.ServiceAccount(
|
||||||
|
"kube-vip-cloud-controller",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "kube-vip-cloud-controller",
|
||||||
|
namespace: kubeVipNamespace,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const cloudProviderClusterRole = new k8s.rbac.v1.ClusterRole(
|
||||||
|
"kube-vip-cloud-controller-role",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "system:kube-vip-cloud-controller-role",
|
||||||
|
annotations: { "rbac.authorization.kubernetes.io/autoupdate": "true" },
|
||||||
|
},
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
apiGroups: ["coordination.k8s.io"],
|
||||||
|
resources: ["leases"],
|
||||||
|
verbs: ["get", "create", "update", "list", "watch"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
apiGroups: [""],
|
||||||
|
resources: [
|
||||||
|
"configmaps",
|
||||||
|
"endpoints",
|
||||||
|
"events",
|
||||||
|
"services/status",
|
||||||
|
"leases",
|
||||||
|
],
|
||||||
|
verbs: ["*"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
apiGroups: [""],
|
||||||
|
resources: ["nodes", "services"],
|
||||||
|
verbs: ["list", "get", "watch", "update"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const cloudProviderClusterRoleBinding = new k8s.rbac.v1.ClusterRoleBinding(
|
||||||
|
"kube-vip-cloud-controller-binding",
|
||||||
|
{
|
||||||
|
metadata: { name: "system:kube-vip-cloud-controller-binding" },
|
||||||
|
roleRef: {
|
||||||
|
apiGroup: "rbac.authorization.k8s.io",
|
||||||
|
kind: "ClusterRole",
|
||||||
|
name: cloudProviderClusterRole.metadata.name,
|
||||||
|
},
|
||||||
|
subjects: [
|
||||||
|
{
|
||||||
|
kind: "ServiceAccount",
|
||||||
|
name: cloudProviderServiceAccount.metadata.name,
|
||||||
|
namespace: kubeVipNamespace,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeVipCloudProviderLabels = {
|
||||||
|
app: "kube-vip",
|
||||||
|
component: "kube-vip-cloud-provider",
|
||||||
|
};
|
||||||
|
|
||||||
|
// IP pool the cloud-provider allocates from — scoped to exactly the one VIP we
|
||||||
|
// want, so it can never hand the address to some other LoadBalancer Service.
|
||||||
|
const kubeVipPool = new k8s.core.v1.ConfigMap(
|
||||||
|
"kube-vip-pool",
|
||||||
|
{
|
||||||
|
metadata: { name: "kubevip", namespace: kubeVipNamespace },
|
||||||
|
data: {
|
||||||
|
"range-global": pulumi.interpolate`${kubeVipAddress}-${kubeVipAddress}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeVipCloudProvider = new k8s.apps.v1.Deployment(
|
||||||
|
"kube-vip-cloud-provider",
|
||||||
|
{
|
||||||
|
metadata: { name: "kube-vip-cloud-provider", namespace: kubeVipNamespace },
|
||||||
|
spec: {
|
||||||
|
replicas: 1,
|
||||||
|
selector: {
|
||||||
|
matchLabels: kubeVipCloudProviderLabels,
|
||||||
|
},
|
||||||
|
template: {
|
||||||
|
metadata: {
|
||||||
|
labels: kubeVipCloudProviderLabels,
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
serviceAccountName: cloudProviderServiceAccount.metadata.name,
|
||||||
|
tolerations: controlPlaneTolerations,
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: "kube-vip-cloud-provider",
|
||||||
|
image: "ghcr.io/kube-vip/kube-vip-cloud-provider:v0.0.12",
|
||||||
|
imagePullPolicy: "Always",
|
||||||
|
command: [
|
||||||
|
"/kube-vip-cloud-provider",
|
||||||
|
"--leader-elect-resource-name=kube-vip-cloud-controller",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [cloudProviderClusterRoleBinding, kubeVipPool] }),
|
||||||
|
);
|
||||||
|
|
||||||
|
new k8s.core.v1.ServicePatch(
|
||||||
|
"traefik-vip",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "traefik",
|
||||||
|
namespace: kubeVipNamespace,
|
||||||
|
annotations: { "kube-vip.io/loadbalancerIPs": kubeVipAddress },
|
||||||
|
},
|
||||||
|
spec: { loadBalancerIP: kubeVipAddress },
|
||||||
|
},
|
||||||
|
opts({ dependsOn: [kubeVip, kubeVipCloudProvider] }),
|
||||||
|
);
|
||||||
Generated
+1509
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "k8s-infra",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.19.4",
|
||||||
|
"typescript": "^6.0.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pulumi/kubernetes": "^4.31.1",
|
||||||
|
"@pulumi/pulumi": "^3.278.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"outDir": "bin",
|
||||||
|
"target": "es2024",
|
||||||
|
"module": "nodenext",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"pretty": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"forceConsistentCasingInFileNames": true
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# k8s-apps
|
||||||
|
|
||||||
|
- heimdall runs with one replica on purpose: it can't run with more than one. Node-failure recovery relies on rescheduling, not replicas.
|
||||||
|
- The `domain` output is consumed by `monitoring` for its ingress hostnames. Renaming or removing it breaks that stack.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
name: k8s-apps
|
||||||
|
description: Application workloads for the k3s homelab cluster
|
||||||
|
runtime:
|
||||||
|
name: nodejs
|
||||||
|
options:
|
||||||
|
packagemanager: npm
|
||||||
|
stackConfigDir: ../.pulumi-config/04-k8s-apps
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
import * as pulumi from "@pulumi/pulumi";
|
||||||
|
import * as k8s from "@pulumi/kubernetes";
|
||||||
|
|
||||||
|
const config = new pulumi.Config();
|
||||||
|
|
||||||
|
const bootstrapRef = new pulumi.StackReference(
|
||||||
|
`${pulumi.getOrganization()}/k8s-bootstrap/dev`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeconfig = bootstrapRef.requireOutput("kubeconfig");
|
||||||
|
export const domain = config.requireSecret("domain");
|
||||||
|
|
||||||
|
// A fixed identifier makes kubeconfig changes (e.g. a new API address) provider
|
||||||
|
// updates. Without it, they replace the provider and every resource in this
|
||||||
|
// stack. Changing this value triggers that replacement, so never change it.
|
||||||
|
const k8sProvider = new k8s.Provider("k3s", {
|
||||||
|
kubeconfig,
|
||||||
|
clusterIdentifier: "homelab-k3s",
|
||||||
|
});
|
||||||
|
const opts = (extras?: pulumi.ResourceOptions): pulumi.ResourceOptions => ({
|
||||||
|
provider: k8sProvider,
|
||||||
|
...extras,
|
||||||
|
});
|
||||||
|
|
||||||
|
const heimdallNs = new k8s.core.v1.Namespace(
|
||||||
|
"heimdall",
|
||||||
|
{ metadata: { name: "heimdall" } },
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const pvc = new k8s.core.v1.PersistentVolumeClaim(
|
||||||
|
"heimdall-config",
|
||||||
|
{
|
||||||
|
metadata: { name: "heimdall-config", namespace: heimdallNs.metadata.name },
|
||||||
|
spec: {
|
||||||
|
accessModes: ["ReadWriteOnce"],
|
||||||
|
storageClassName: "longhorn",
|
||||||
|
resources: { requests: { storage: "50Mi" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const labels = { app: "heimdall" };
|
||||||
|
|
||||||
|
new k8s.apps.v1.Deployment(
|
||||||
|
"heimdall",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "heimdall",
|
||||||
|
namespace: heimdallNs.metadata.name,
|
||||||
|
annotations: { "pulumi.com/patchForce": "true" },
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
replicas: 1,
|
||||||
|
strategy: { type: "Recreate" },
|
||||||
|
selector: { matchLabels: labels },
|
||||||
|
template: {
|
||||||
|
metadata: { labels },
|
||||||
|
spec: {
|
||||||
|
containers: [
|
||||||
|
{
|
||||||
|
name: "heimdall",
|
||||||
|
image: "lscr.io/linuxserver/heimdall:latest",
|
||||||
|
env: [
|
||||||
|
{ name: "PUID", value: "1000" },
|
||||||
|
{ name: "PGID", value: "1000" },
|
||||||
|
],
|
||||||
|
ports: [{ containerPort: 80 }],
|
||||||
|
volumeMounts: [{ name: "config", mountPath: "/config" }],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
volumes: [
|
||||||
|
{
|
||||||
|
name: "config",
|
||||||
|
persistentVolumeClaim: { claimName: pvc.metadata.name },
|
||||||
|
},
|
||||||
|
],
|
||||||
|
terminationGracePeriodSeconds: 5,
|
||||||
|
tolerations: [
|
||||||
|
{
|
||||||
|
key: "node.kubernetes.io/unreachable",
|
||||||
|
operator: "Exists",
|
||||||
|
effect: "NoExecute",
|
||||||
|
tolerationSeconds: 30,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "node.kubernetes.io/not-ready",
|
||||||
|
operator: "Exists",
|
||||||
|
effect: "NoExecute",
|
||||||
|
tolerationSeconds: 30,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const svc = new k8s.core.v1.Service(
|
||||||
|
"heimdall",
|
||||||
|
{
|
||||||
|
metadata: { name: "heimdall", namespace: heimdallNs.metadata.name },
|
||||||
|
spec: {
|
||||||
|
selector: labels,
|
||||||
|
ports: [{ port: 80, targetPort: 80 }],
|
||||||
|
type: "ClusterIP",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
const host = pulumi.interpolate`heimdall.${domain}`;
|
||||||
|
|
||||||
|
new k8s.networking.v1.Ingress(
|
||||||
|
"heimdall",
|
||||||
|
{
|
||||||
|
metadata: {
|
||||||
|
name: "heimdall",
|
||||||
|
namespace: heimdallNs.metadata.name,
|
||||||
|
annotations: {
|
||||||
|
"cert-manager.io/cluster-issuer": "letsencrypt-prod",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
spec: {
|
||||||
|
ingressClassName: "traefik",
|
||||||
|
tls: [{ hosts: [host], secretName: "heimdall-tls" }],
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
host,
|
||||||
|
http: {
|
||||||
|
paths: [
|
||||||
|
{
|
||||||
|
path: "/",
|
||||||
|
pathType: "Prefix",
|
||||||
|
backend: {
|
||||||
|
service: {
|
||||||
|
name: svc.metadata.name,
|
||||||
|
port: { number: 80 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
opts(),
|
||||||
|
);
|
||||||
|
|
||||||
|
export const ingressHost = host;
|
||||||
Generated
+1509
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "k8s-apps",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.0.0",
|
||||||
|
"typescript": "^6.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pulumi/kubernetes": "^4.31.1",
|
||||||
|
"@pulumi/pulumi": "^3.244.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"outDir": "bin",
|
||||||
|
"target": "es2024",
|
||||||
|
"module": "nodenext",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"pretty": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"forceConsistentCasingInFileNames": true
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# monitoring
|
||||||
|
|
||||||
|
- The `monitoring` namespace and the `kube-prometheus-stack` Helm release were originally adopted from existing cluster resources and are now `protected`. Be careful with renames or changes that would force a replace.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
name: Monitoring
|
||||||
|
description: Monitoring stack (Prometheus + Grafana via kube-prometheus-stack)
|
||||||
|
runtime:
|
||||||
|
name: nodejs
|
||||||
|
options:
|
||||||
|
packagemanager: npm
|
||||||
|
stackConfigDir: ../.pulumi-config/05-monitoring
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import * as pulumi from "@pulumi/pulumi";
|
||||||
|
import * as k8s from "@pulumi/kubernetes";
|
||||||
|
|
||||||
|
const config = new pulumi.Config();
|
||||||
|
|
||||||
|
const bootstrapRef = new pulumi.StackReference(
|
||||||
|
`${pulumi.getOrganization()}/k8s-bootstrap/dev`,
|
||||||
|
);
|
||||||
|
const appsRef = new pulumi.StackReference(
|
||||||
|
`${pulumi.getOrganization()}/k8s-apps/dev`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const kubeconfig = bootstrapRef.requireOutput("kubeconfig");
|
||||||
|
const domain = appsRef.requireOutput("domain");
|
||||||
|
const grafanaAdminPassword = config.requireSecret("grafanaAdminPassword");
|
||||||
|
const grafanaDbUser = config.requireSecret("grafanaDbUser");
|
||||||
|
const grafanaDbPassword = config.requireSecret("grafanaDbPassword");
|
||||||
|
const grafanaDbHost = config.requireSecret("grafanaDbHost");
|
||||||
|
const grafanaDbName = config.require("grafanaDbName");
|
||||||
|
|
||||||
|
// A fixed identifier makes kubeconfig changes (e.g. a new API address) provider
|
||||||
|
// updates. Without it, they replace the provider and every resource in this
|
||||||
|
// stack. Changing this value triggers that replacement, so never change it.
|
||||||
|
const k8sProvider = new k8s.Provider("k3s", {
|
||||||
|
kubeconfig,
|
||||||
|
clusterIdentifier: "homelab-k3s",
|
||||||
|
});
|
||||||
|
|
||||||
|
const monitoringNs = new k8s.core.v1.Namespace(
|
||||||
|
"monitoring",
|
||||||
|
{ metadata: { name: "monitoring" } },
|
||||||
|
{ provider: k8sProvider, protect: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
const grafanaHost = pulumi.interpolate`grafana.${domain}`;
|
||||||
|
|
||||||
|
const grafanaDbSecret = new k8s.core.v1.Secret(
|
||||||
|
"grafana-db-credentials",
|
||||||
|
{
|
||||||
|
metadata: { namespace: monitoringNs.metadata.name },
|
||||||
|
stringData: { password: grafanaDbPassword },
|
||||||
|
},
|
||||||
|
{ provider: k8sProvider },
|
||||||
|
);
|
||||||
|
|
||||||
|
new k8s.helm.v3.Release(
|
||||||
|
"kube-prometheus-stack",
|
||||||
|
{
|
||||||
|
name: "kube-prometheus-stack",
|
||||||
|
chart: "kube-prometheus-stack",
|
||||||
|
version: "86.2.0",
|
||||||
|
namespace: monitoringNs.metadata.name,
|
||||||
|
repositoryOpts: {
|
||||||
|
repo: "https://prometheus-community.github.io/helm-charts",
|
||||||
|
},
|
||||||
|
timeout: 600,
|
||||||
|
values: {
|
||||||
|
grafana: {
|
||||||
|
adminPassword: grafanaAdminPassword,
|
||||||
|
replicas: 2,
|
||||||
|
ingress: {
|
||||||
|
enabled: true,
|
||||||
|
ingressClassName: "traefik",
|
||||||
|
annotations: { "cert-manager.io/cluster-issuer": "letsencrypt-prod" },
|
||||||
|
hosts: [grafanaHost],
|
||||||
|
tls: [{ secretName: "grafana-tls", hosts: [grafanaHost] }],
|
||||||
|
},
|
||||||
|
env: {
|
||||||
|
GF_DATABASE_TYPE: "postgres",
|
||||||
|
GF_DATABASE_HOST: grafanaDbHost,
|
||||||
|
GF_DATABASE_NAME: grafanaDbName,
|
||||||
|
GF_DATABASE_USER: grafanaDbUser,
|
||||||
|
GF_DATABASE_SSL_MODE: "disable",
|
||||||
|
},
|
||||||
|
envValueFrom: {
|
||||||
|
GF_DATABASE_PASSWORD: {
|
||||||
|
secretKeyRef: {
|
||||||
|
name: grafanaDbSecret.metadata.name,
|
||||||
|
key: "password",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
prometheus: {
|
||||||
|
prometheusSpec: {
|
||||||
|
retention: "14d",
|
||||||
|
retentionSize: "15GB",
|
||||||
|
scrapeInterval: "60s",
|
||||||
|
evaluationInterval: "60s",
|
||||||
|
replicas: "1",
|
||||||
|
storageSpec: {
|
||||||
|
volumeClaimTemplate: {
|
||||||
|
spec: {
|
||||||
|
storageClassName: "longhorn",
|
||||||
|
resources: { requests: { storage: "18Gi" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
alertmanager: { enabled: false },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ provider: k8sProvider, protect: true },
|
||||||
|
);
|
||||||
Generated
+1509
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "monitoring",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"typecheck": "tsc --noEmit"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^24.0.0",
|
||||||
|
"typescript": "^6.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@pulumi/kubernetes": "^4.31.1",
|
||||||
|
"@pulumi/pulumi": "^3.244.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"strict": true,
|
||||||
|
"outDir": "bin",
|
||||||
|
"target": "ES2024",
|
||||||
|
"module": "nodenext",
|
||||||
|
"moduleResolution": "nodenext",
|
||||||
|
"sourceMap": true,
|
||||||
|
"experimentalDecorators": true,
|
||||||
|
"pretty": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noImplicitReturns": true,
|
||||||
|
"forceConsistentCasingInFileNames": true
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
<!-- Notes for the human, stripped before this file reaches Claude:
|
||||||
|
- Start Claude Code sessions from the repository root: the permission rules and
|
||||||
|
hooks in .claude/settings.json only load from there.
|
||||||
|
- Keep this file to what Claude can't work out from the code. Stack-specific notes
|
||||||
|
go in the stack's own CLAUDE.md, which loads when Claude touches that stack. -->
|
||||||
|
|
||||||
|
Pulumi (TypeScript) IaC for a Proxmox-based k3s homelab. Each `0N-*` directory is an independent Pulumi project ("stack"), all using the Pulumi stack name `dev`.
|
||||||
|
|
||||||
|
## Deployment order & StackReferences
|
||||||
|
|
||||||
|
```
|
||||||
|
proxmox-infra → k8s-bootstrap → k8s-infra
|
||||||
|
↘ k8s-apps → monitoring
|
||||||
|
```
|
||||||
|
|
||||||
|
- `k8s-bootstrap` reads VM IDs, node IPs, Proxmox credentials, and the SSH private key from `proxmox-infra`.
|
||||||
|
- `k8s-infra`, `k8s-apps`, and `monitoring` read `kubeconfig` from `k8s-bootstrap` (`requireOutput("kubeconfig")`). Never set `kubeconfig` as Pulumi config in these stacks.
|
||||||
|
- `monitoring` additionally reads `domain` from `k8s-apps`.
|
||||||
|
- StackReference format: `${pulumi.getOrganization()}/<stack-name>/dev`.
|
||||||
|
- A stack's outputs must exist (it must have been deployed) before a downstream stack referencing it will succeed.
|
||||||
|
|
||||||
|
## Shared conventions
|
||||||
|
|
||||||
|
- **Secrets**: read via `config.requireSecret()`, never via environment variables or hardcoded values.
|
||||||
|
- **`Pulumi.dev.yaml`**: in `.pulumi-config/<stack-dir>/` (set by `stackConfigDir`). `.pulumi-config/` is a separate private repo, gitignored here and not a submodule, so this repo's `git status` doesn't show its changes; use `git -C .pulumi-config status`. These files contain the encryption salt: never delete them or secrets become unrecoverable, and never commit them to this repo. Any `0N-*/Pulumi.dev.yaml` is an unused old copy; don't edit it.
|
||||||
|
- **Config changes**: CI checks out the config repo's `main`, so a local preview can use config that CI doesn't have yet. After config changes, remind me to commit and push them there, before opening or updating a PR that needs them. That push doesn't start a deploy. The commit rule below applies to that repo too. Setup steps are in `.pulumi-config/README.md`.
|
||||||
|
- **Private repos**: don't write a private repo's name, owner/name path or URL in READMEs or other docs. Say "the private config repo", or use a placeholder. Naming it in workflows is fine, and so is the local folder name `.pulumi-config/`.
|
||||||
|
- **Environment**: `PULUMI_BACKEND_URL` (self-hosted Postgres backend) and `PULUMI_CONFIG_PASSPHRASE` must be set.
|
||||||
|
- **CI**: PRs run `pulumi preview`. `01` and `03`–`05` deploy on push to `main`; `02` deploys only via manual dispatch. Automatic `01` deploys skip `pulumi refresh`, so run its workflow manually after changing VMs in the Proxmox GUI.
|
||||||
|
|
||||||
|
## Git conventions
|
||||||
|
|
||||||
|
Branch names, commit messages and PR titles follow @CONVENTIONS.md. The commit-msg hook needs `git config core.hooksPath .githooks` once per clone.
|
||||||
|
|
||||||
|
Only commit when I explicitly say "commit" for that change. A yes to a question that also mentioned committing is not enough; when unsure, ask.
|
||||||
|
|
||||||
|
The remote is a self-hosted Gitea, so `gh` doesn't work. For PRs and their CI status use `.claude/scripts/gitea.sh` (acts as `claude-bot`), e.g. `.claude/scripts/gitea.sh GET '/repos/kasun/homelab-infrastructure-as-code/pulls?state=open'`. Use it for PRs only, and ask before opening or merging one.
|
||||||
|
|
||||||
|
## Live infrastructure
|
||||||
|
|
||||||
|
- Don't change live systems (cluster, pfSense, Proxmox, VMs, my local kubeconfig) on your own initiative, even for small or reversible changes. Give me the exact steps and let me decide who runs them.
|
||||||
|
- Code edits in the repo are fine without asking.
|
||||||
|
- Never recreate VMs to apply a change. Write code for a clean fresh install, plus separate manual steps for the running cluster.
|
||||||
|
|
||||||
|
## Looking things up
|
||||||
|
|
||||||
|
- Reading is free: files in this repo, git history, read-only kubectl and pulumi commands.
|
||||||
|
- Search targeted. If two or three searches don't find it, stop and ask me where it is instead of searching the whole filesystem.
|
||||||
|
- Stay inside this repo unless I point you somewhere else.
|
||||||
|
|
||||||
|
## Verifying changes
|
||||||
|
|
||||||
|
After editing a stack, run `npm run typecheck` in that stack's directory, then `pulumi preview`, and show the output of both. A passing typecheck only proves the code compiles; the preview is what shows which resources would be created, updated or replaced.
|
||||||
|
|
||||||
|
Don't silence a check to make it pass (`@ts-ignore`, `as any`, `git commit --no-verify`) without a stated reason and my OK.
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
# Git Conventions
|
||||||
|
|
||||||
|
## Branch Naming
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>/<short-kebab-case-description>
|
||||||
|
```
|
||||||
|
|
||||||
|
- All lowercase, hyphens only — no camelCase or Title-Case
|
||||||
|
- Keep the description short (3–5 words); the branch name is not the place for detail
|
||||||
|
- No ticket tracker is used on this project, so branch names don't carry an ID
|
||||||
|
|
||||||
|
| Type | Use for |
|
||||||
|
|---|---|
|
||||||
|
| `feature/` | New functionality (e.g. a new stack, a new resource type) |
|
||||||
|
| `bug/` | Bug fixes |
|
||||||
|
| `enhancement/` | Improvements or refactors to existing functionality, no new capability |
|
||||||
|
| `chore/` | Dependency bumps, tooling, CI/CD, cleanup |
|
||||||
|
| `docs/` | Documentation only (README, CLAUDE.md files) |
|
||||||
|
|
||||||
|
**Examples:** `feature/add-3rd-proxmox-node`, `bug/fix-longhorn-disk-pressure`, `enhancement/refactor-k8s-bootstrap`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Commit Messages
|
||||||
|
|
||||||
|
```
|
||||||
|
<type>: <imperative, present-tense summary>
|
||||||
|
|
||||||
|
<optional body — explain WHY, not WHAT>
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Type** — same list as branch types above (`feature`, `bug`, `enhancement`, `chore`, `docs`)
|
||||||
|
- **Scope is optional** and, if used, should be one of the stack directories this repo is organized into — `proxmox-infra`, `k8s-bootstrap`, `k8s-infra`, `k8s-apps`, `monitoring` — or `ci` for `.gitea/workflows` changes: `bug(k8s-infra): ...`
|
||||||
|
- **Summary** — imperative mood ("add", not "added" or "adds"); no period at the end
|
||||||
|
- **Body** — only when the reasoning isn't obvious from the diff (a constraint, a workaround for a Proxmox/k3s quirk, a decision between StackReference outputs). Skip it for simple/self-explanatory changes.
|
||||||
|
|
||||||
|
**Examples:**
|
||||||
|
```
|
||||||
|
feature: add pfsense provider for automating static IP setup
|
||||||
|
bug: prune stale kube-vip leases after node replacement
|
||||||
|
chore: upgrade Pulumi provider packages across all stacks
|
||||||
|
docs: update CLAUDE.md with new Longhorn mount settings
|
||||||
|
enhancement(k8s-bootstrap): cache dependencies to speed up deployment
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Pull Request Titles
|
||||||
|
|
||||||
|
This repo uses Gitea Actions (see root `CLAUDE.md`); Gitea's merge commit reuses the PR title verbatim as the merge summary, so the title should stand on its own in `git log`. Frame it as the outcome, not a task log:
|
||||||
|
|
||||||
|
```
|
||||||
|
<Type>: <what changes for the cluster/infra>
|
||||||
|
```
|
||||||
|
|
||||||
|
**Examples:**
|
||||||
|
- `Feature: Add 3rd Proxmox node to the cluster`
|
||||||
|
- `Bug: Fix Longhorn disk pressure from root disk usage`
|
||||||
|
- `Enhancement: Refactor k8s-bootstrap for clearer deployment order`
|
||||||
|
- `Chore: Upgrade Pulumi packages across all stacks`
|
||||||
|
|
||||||
|
Since `02` deploys are manual (`workflow_dispatch`) and `01` and `03`–`05` deploy on merge to `main`, a clear PR title also doubles as a quick changelog of what just went live.
|
||||||
@@ -1,168 +1,162 @@
|
|||||||
# Homelab Infrastructure as Code
|
# Homelab Infrastructure as Code
|
||||||
|
|
||||||
A Pulumi-based IaC template for managing a Proxmox homelab. The goal is to replace manual GUI configuration and ad-hoc YAML stacks (LXC, VM, Docker, etc.) with version-controlled, reproducible infrastructure — starting with a highly available k3s cluster across multiple Proxmox nodes.
|
A Pulumi-based IaC project for a Proxmox homelab: a highly-available k3s cluster, its cluster-level infrastructure, and the applications running on top of it — all provisioned and configured from code.
|
||||||
|
|
||||||
This repo is intentionally abstract: credentials are never hardcoded, making it easy to fork and adapt as a template for your own homelab.
|
This repo is intentionally abstract: credentials are never hardcoded, making it easy to fork and adapt as a template for your own homelab.
|
||||||
|
|
||||||
## Why IaC for a homelab?
|
## Why IaC for a homelab?
|
||||||
|
|
||||||
- **Reproducibility** — rebuild your entire environment from scratch with a single command
|
- **Reproducibility** — rebuild the entire environment from scratch from code
|
||||||
- **Version history** — every change is tracked in git; roll back at any time
|
- **Version history** — every change is tracked in git; roll back at any time
|
||||||
- **Auditability** — diff infrastructure changes before applying them (`pulumi preview`)
|
- **Auditability** — `pulumi preview` diffs infrastructure changes before they're applied
|
||||||
- **Automation** — CI/CD handles deploys; no manual SSH into nodes
|
- **Automation** — CI/CD handles deploys; no manual SSH into nodes for routine changes
|
||||||
- **Portability** — swap node names, datastores, or credentials without touching logic
|
- **Portability** — swap node names, datastores, domains, or credentials without touching logic
|
||||||
|
|
||||||
## Repository layout
|
## Repository layout
|
||||||
|
|
||||||
```
|
```
|
||||||
.
|
.
|
||||||
├── proxmox-infra/ # Pulumi TypeScript stack — VMs & LXC on Proxmox
|
├── 01-proxmox-infra/ # Stack 1 — k3s VMs + DHCP on Proxmox/pfSense
|
||||||
│ ├── index.ts # All Pulumi resources
|
├── 02-k8s-bootstrap/ # Stack 2 — install k3s on the VMs over SSH
|
||||||
│ ├── Pulumi.yaml # Stack project definition
|
├── 03-k8s-infra/ # Stack 3 — storage, cert-manager, kube-vip
|
||||||
│ ├── Pulumi.dev.yaml # Encrypted stack config (gitignored)
|
├── 04-k8s-apps/ # Stack 4 — application workloads
|
||||||
│ └── sdks/
|
├── 05-monitoring/ # Stack 5 — kube-prometheus-stack (Prometheus + Grafana)
|
||||||
│ └── pfsense/ # Locally bundled @pulumi/pfsense SDK
|
├── .gitea/workflows/ # CI/CD — one workflow per stack
|
||||||
├── .gitea/
|
└── CLAUDE.md # Conventions & architecture notes (root + one per stack)
|
||||||
│ └── workflows/
|
|
||||||
│ └── deploy-proxmox-infra.yaml # Gitea Actions CI/CD pipeline
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Current stack: `proxmox-infra`
|
Each stack is an independent Pulumi project (own `Pulumi.yaml`/`package.json`), all using the Pulumi stack name `dev`.
|
||||||
|
|
||||||
Provisions a 5-node k3s cluster spread across two Proxmox hosts (`pve` and `pve-bckp`, third bare metal host to be added later for actual parity):
|
## Stacks
|
||||||
|
|
||||||
| VM name | Role | Proxmox node |
|
Stacks are deployed in order and linked via `pulumi.StackReference` — outputs from one stack flow automatically into the next, so a stack must be deployed before anything depending on it will work.
|
||||||
| ------------ | ------ | ------------ |
|
|
||||||
| k3s-master-1 | master | pve |
|
|
||||||
| k3s-master-2 | master | pve |
|
|
||||||
| k3s-worker-1 | worker | pve |
|
|
||||||
| k3s-master-3 | master | pve-bckp |
|
|
||||||
| k3s-worker-2 | worker | pve-bckp |
|
|
||||||
|
|
||||||
Each node is a full clone of an Ubuntu Noble (24.04) cloud-image template, with cloud-init injecting hostname, user credentials, and SSH keys at boot. Each VM's MAC address is registered as a DHCPv4 static mapping in pfSense so that nodes always receive their designated IPs.
|
```
|
||||||
|
proxmox-infra → k8s-bootstrap → k8s-infra
|
||||||
|
↘ k8s-apps → monitoring
|
||||||
|
```
|
||||||
|
|
||||||
An ED25519 SSH key pair is generated once and stored in Pulumi state. The public key is injected into every VM at boot; the private key is exported as a stack output so `k8s-bootstrap` can consume it via StackReference without any manual key distribution.
|
### 1. proxmox-infra
|
||||||
|
|
||||||
**Tech stack:**
|
Provisions a 6-node k3s cluster across three Proxmox hosts, each VM a clone of an Ubuntu Noble (24.04) cloud-image template:
|
||||||
|
|
||||||
- [Pulumi](https://www.pulumi.com/) with TypeScript
|
| VM | Role | Proxmox host |
|
||||||
- [`@muhlba91/pulumi-proxmoxve`](https://github.com/muhlba91/pulumi-provider-proxmoxve) v8.x community provider
|
| --- | --- | --- |
|
||||||
- [`@pulumi/pfsense`](https://github.com/marshallford/terraform-provider-pfsense) — locally bundled SDK bridged from the Terraform pfSense provider; installed automatically via `npm install`
|
| k3s-master-1 | master | pve-b550 |
|
||||||
- [`@pulumi/tls`](https://www.pulumi.com/registry/packages/tls/) — SSH key pair generation
|
| k3s-worker-1 | worker | pve-b550 |
|
||||||
- Self-hosted Pulumi state backend (PostgreSQL)
|
| k3s-master-2 | master | pve-esprimo |
|
||||||
- Gitea Actions for CI/CD
|
| k3s-worker-3 | worker | pve-esprimo |
|
||||||
|
| k3s-master-3 | master | pve-optiplex |
|
||||||
|
| k3s-worker-2 | worker | pve-optiplex |
|
||||||
|
|
||||||
|
It also generates an ED25519 SSH keypair (stored in Pulumi state, public key injected via cloud-init) and registers each VM's MAC address as a DHCPv4 static mapping in pfSense.
|
||||||
|
|
||||||
|
**Providers:** `@muhlba91/pulumi-proxmoxve`, `@pulumi/pfsense` (locally bundled), `@pulumi/tls`
|
||||||
|
|
||||||
|
### 2. k8s-bootstrap
|
||||||
|
|
||||||
|
Starts the VMs via the Proxmox API and installs k3s over SSH: `k3s-master-1` initializes the cluster (`--cluster-init`, embedded etcd), `k3s-master-2`/`k3s-master-3` join as additional etcd nodes, and the three workers join as agents. Exports the cluster's `kubeconfig` as a secret for downstream stacks.
|
||||||
|
|
||||||
|
### 3. k8s-infra
|
||||||
|
|
||||||
|
Cluster-level infrastructure via Helm and `@pulumi/kubernetes`:
|
||||||
|
|
||||||
|
| Component | What it does |
|
||||||
|
| --- | --- |
|
||||||
|
| NFS CSI Driver + `truenas-nfs` StorageClass | Dynamic NFS-backed PVCs from a TrueNAS share |
|
||||||
|
| Longhorn | Default block storage (`longhorn` StorageClass, 2 replicas) |
|
||||||
|
| cert-manager + `letsencrypt-prod` ClusterIssuer | TLS certs via Let's Encrypt, DNS-01 through Cloudflare |
|
||||||
|
| kube-vip + kube-vip-cloud-provider | Announces a virtual IP and allocates it to LoadBalancer Services (e.g. Traefik) |
|
||||||
|
|
||||||
|
### 4. k8s-apps
|
||||||
|
|
||||||
|
Application workloads exposed at `app.<domain>` via Traefik with a Let's Encrypt cert.
|
||||||
|
|
||||||
|
### 5. monitoring
|
||||||
|
|
||||||
|
`kube-prometheus-stack` Helm release — Prometheus (20Gi Longhorn PVC) and Grafana (2Gi PVC, ingress at `grafana.<domain>`).
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- [Pulumi CLI](https://www.pulumi.com/docs/install/) installed
|
- [Pulumi CLI](https://www.pulumi.com/docs/install/), Node.js 24+ and npm
|
||||||
- Node.js 18+ and npm
|
- One or more Proxmox nodes with API tokens
|
||||||
- Access to a Proxmox node with an API token
|
- pfSense (DHCPv4 static mappings)
|
||||||
- pfSense instance with API credentials (used for DHCPv4 static mappings)
|
- TrueNAS with an NFS share (connected directly — no API key needed)
|
||||||
|
- A domain with DNS managed by Cloudflare (cert-manager DNS-01 + ingress hostnames)
|
||||||
- A self-hosted Pulumi state backend (PostgreSQL connection string)
|
- A self-hosted Pulumi state backend (PostgreSQL connection string)
|
||||||
- Gitea instance for CI/CD (optional for local use)
|
- Gitea instance for CI/CD (optional for local-only use)
|
||||||
|
|
||||||
## Getting started
|
## Getting started
|
||||||
|
|
||||||
### 1. Clone and install
|
Deploy stacks **in order** — each must be fully `pulumi up`'d before the next stack's `StackReference` resolves. Set the shared backend env vars once per shell:
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone <your-repo-url>
|
|
||||||
cd proxmox-infra
|
|
||||||
npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
> **pfSense SDK** — The `@pulumi/pfsense` SDK is bundled locally under `sdks/pfsense/` and referenced as a `file:` dependency in `package.json`. Running `npm install` compiles it automatically via its postinstall hook. No separate installation or build step is required.
|
|
||||||
|
|
||||||
### 2. Configure credentials
|
|
||||||
|
|
||||||
All secrets are stored as encrypted Pulumi config values — never in plain environment variables or committed files.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Proxmox API credentials
|
|
||||||
pulumi config set --secret pve1Endpoint https://<proxmox-host-1>:8006
|
|
||||||
pulumi config set --secret pve1ApiToken <user>@pam!<token-id>=<uuid>
|
|
||||||
pulumi config set --secret pve2Endpoint https://<proxmox-host-2>:8006
|
|
||||||
pulumi config set --secret pve2ApiToken <user>@pam!<token-id>=<uuid>
|
|
||||||
|
|
||||||
# VM credentials
|
|
||||||
pulumi config set --secret k3sVmPassword <vm-password>
|
|
||||||
pulumi config set --secret sshPvePublicKey "ssh-ed25519 AAAA..."
|
|
||||||
|
|
||||||
# pfSense credentials (used for DHCPv4 static mappings)
|
|
||||||
pulumi config set --secret pfSenseUrl https://<pfsense-host>
|
|
||||||
pulumi config set --secret pfSenseUser <admin-username>
|
|
||||||
pulumi config set --secret pfSensePassword <admin-password>
|
|
||||||
|
|
||||||
# Static IP addresses assigned to each k3s node
|
|
||||||
pulumi config set --secret master1Ip <ip-for-k3s-master-1>
|
|
||||||
pulumi config set --secret master2Ip <ip-for-k3s-master-2>
|
|
||||||
pulumi config set --secret worker1Ip <ip-for-k3s-worker-1>
|
|
||||||
pulumi config set --secret master3Ip <ip-for-k3s-master-3>
|
|
||||||
pulumi config set --secret worker2Ip <ip-for-k3s-worker-2>
|
|
||||||
```
|
|
||||||
|
|
||||||
Pulumi encrypts these values into `Pulumi.dev.yaml` using your `PULUMI_CONFIG_PASSPHRASE`.
|
|
||||||
|
|
||||||
### 3. Set the state backend
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
export PULUMI_BACKEND_URL=postgresql://<user>:<pass>@<host>/<db>
|
export PULUMI_BACKEND_URL=postgresql://<user>:<pass>@<host>/<db>
|
||||||
export PULUMI_CONFIG_PASSPHRASE=<your-passphrase>
|
export PULUMI_CONFIG_PASSPHRASE=<your-passphrase>
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4. Preview and deploy
|
Clone your private config repo into `.pulumi-config/` (see [Stack config](#stack-config)). For an existing setup, use the config from that repo and skip the `stack init` and `config set` commands below.
|
||||||
|
|
||||||
|
Then for each stack, in order:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# See what will change before touching anything
|
cd 0N-<stack-dir>
|
||||||
pulumi preview
|
npm install
|
||||||
|
pulumi stack init dev
|
||||||
# Sync Pulumi state with actual Proxmox state (run after any manual GUI changes)
|
pulumi config set ... # required keys and secrets
|
||||||
pulumi refresh --yes
|
pulumi up --yes
|
||||||
|
|
||||||
# Deploy
|
|
||||||
pulumi refresh --yes && pulumi up --yes
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Stack-specific notes:
|
||||||
|
|
||||||
|
1. **proxmox-infra** — set Proxmox API tokens, pfSense credentials, VM credentials/SSH public key, and a static IP per node.
|
||||||
|
2. **k8s-bootstrap** — set `k3sToken` (e.g. `openssl rand -hex 32`) and `controlPlaneVipAddress` (secret; a free IP outside the DHCP pool, fronted by pfSense + HAProxy, see [the runbook](docs/runbooks/pfsense-control-plane-vip.md)). Node IPs, Proxmox credentials and the SSH key come automatically from `proxmox-infra`.
|
||||||
|
3. **k8s-infra** — before deploying, create an NFS dataset/share on TrueNAS (POSIX ACLs, `root`/`root` maproot, restricted to your k3s nodes). Set `truenasHost`, `truenasNfsPath`, `cloudflareApiToken`, `letsencryptEmail`, `kubeVipAddress` (all secrets) and `kubeVipInterface`.
|
||||||
|
4. **k8s-apps** — set `domain`, the base domain used for ingress hostnames.
|
||||||
|
5. **monitoring** — set `grafanaAdminPassword`.
|
||||||
|
|
||||||
## CI/CD (Gitea Actions)
|
## CI/CD (Gitea Actions)
|
||||||
|
|
||||||
The workflow at `.gitea/workflows/deploy-proxmox-infra.yaml` runs automatically:
|
One workflow per stack, `.gitea/workflows/0N-deploy-<stack>.yaml`, scoped to changes under that stack's directory.
|
||||||
|
|
||||||
| Event | Action |
|
| Trigger | Stacks | Action |
|
||||||
| --------------------- | ------------------------------ |
|
| --- | --- | --- |
|
||||||
| Pull request → `main` | `pulumi preview` (read-only) |
|
| PR → `main` | all | `pulumi preview` (read-only) |
|
||||||
| Push to `main` | `pulumi refresh` + `pulumi up` |
|
| Push to `main` | 01 | `pulumi up` (no refresh) |
|
||||||
| Manual trigger | `pulumi refresh` + `pulumi up` |
|
| Push to `main` | 03–05 | `pulumi refresh` + `pulumi up` |
|
||||||
|
| Manual dispatch | all | `pulumi refresh` + `pulumi up` |
|
||||||
|
|
||||||
### Required Gitea secrets
|
Stack 02 (cluster bootstrap) deploys **only** via manual dispatch, because re-running it restarts the bootstrap sequence. Stack 01 (VM provisioning) skips the refresh on automatic deploys so a VM missing from Proxmox can't be recreated blank. After changing VMs in the Proxmox GUI, run its workflow manually to sync state.
|
||||||
|
|
||||||
Configure these under **Settings → Actions → Secrets** in your Gitea repo:
|
To rebuild the whole cluster from new VMs, follow [the rebuild runbook](docs/runbooks/full-cluster-rebuild.md). A normal `pulumi up` won't do it.
|
||||||
|
|
||||||
| Secret | Description |
|
### Required secrets
|
||||||
| -------------------------- | -------------------------------------------------- |
|
|
||||||
| `PULUMI_BACKEND_URL` | PostgreSQL connection string for the state backend |
|
|
||||||
| `PULUMI_CONFIG_PASSPHRASE` | Passphrase to decrypt secrets in `Pulumi.dev.yaml` |
|
|
||||||
| `PULUMI_DEV_YAML` | Base64-encoded content of `Pulumi.dev.yaml` |
|
|
||||||
|
|
||||||
`Pulumi.dev.yaml` is gitignored because it contains your encryption salt. Whenever it changes (e.g. after adding or rotating a secret), re-encode it and paste the output into the Gitea secret:
|
| Secret | Used by |
|
||||||
|
| --- | --- |
|
||||||
|
| `PULUMI_BACKEND_URL`, `PULUMI_CONFIG_PASSPHRASE` | all workflows |
|
||||||
|
| `PULUMI_CONFIG_REPO_TOKEN` (`ci-bot` token with read-only access to the config repo) | all workflows |
|
||||||
|
|
||||||
```bash
|
### Stack config
|
||||||
base64 -w 0 proxmox-infra/Pulumi.dev.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
## Adapting this as a template
|
Each stack's encrypted `Pulumi.dev.yaml` is in a private repo, cloned into the gitignored `.pulumi-config/` folder. CI checks out its `main` branch. After changing config, commit and push it there. That push doesn't start a deploy. See that repo's README for setup and usage.
|
||||||
|
|
||||||
|
CI reads the config repo as a separate user, so its token can't access your other private repos:
|
||||||
|
|
||||||
|
1. As a Gitea admin, create a regular (non-admin) user named `ci-bot`.
|
||||||
|
2. In the config repo's settings, add `ci-bot` as a collaborator with **Read** access. Don't add it to any other private repo.
|
||||||
|
3. Sign in as `ci-bot` and create an access token with only the `read:repository` permission.
|
||||||
|
4. In this repo's Actions secrets, add the token as `PULUMI_CONFIG_REPO_TOKEN`.
|
||||||
|
|
||||||
|
## Using this as a template
|
||||||
|
|
||||||
1. Fork or copy the repo
|
1. Fork or copy the repo
|
||||||
2. Update node names (`pve`, `pve-bckp`) and datastore IDs in `index.ts` to match your setup
|
2. Update Proxmox node names/datastores and the `nodeConfigs` array in `01-proxmox-infra/index.ts` for your VM topology
|
||||||
3. Add or remove VMs from the `nodeConfigs` array
|
3. Set your own config/secrets per stack with `pulumi config set [--secret]` — see each stack's `CLAUDE.md` for the full list of required keys
|
||||||
4. Set your own secrets with `pulumi config set --secret`
|
4. Create your own private config repo and a `ci-bot` user that can read it (see [Stack config](#stack-config)), then set the repo as `repository` in each workflow's `Checkout Stack Config` steps
|
||||||
5. Point the CI/CD workflow at your own Git instance
|
5. Point the CI/CD workflows at your own Gitea/GitOps instance and update the secrets above
|
||||||
|
|
||||||
## Roadmap
|
## Roadmap
|
||||||
|
|
||||||
- LXC container management
|
- Migrate secrets management to [OpenBao](https://openbao.org/) — replace `PULUMI_CONFIG_PASSPHRASE` and the encrypted config repo with a self-hosted vault
|
||||||
- Docker / Compose stack provisioning
|
- Add a third bare-metal Proxmox node for true 3-node HA parity
|
||||||
- Firewall rules (pfSense)
|
|
||||||
- Automated k3s bootstrapping (kubeconfig export)
|
|
||||||
- Additional worker nodes and storage volumes
|
|
||||||
- Migrate secrets management to [OpenBao](https://openbao.org/) — replace `PULUMI_CONFIG_PASSPHRASE` and manual `Pulumi.dev.yaml` encoding with a self-hosted vault
|
|
||||||
- Add a third bare metal proxmox instance to create an actual 3 node parity.
|
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
# 0001: Control-plane VIP via pfSense + HAProxy, not kube-vip
|
||||||
|
|
||||||
|
Status: accepted (September 2026)
|
||||||
|
|
||||||
|
## Context
|
||||||
|
|
||||||
|
The kubeconfig exported by `02-k8s-bootstrap` pointed at `master1Ip` only, and the other nodes joined through it. Losing master-1 therefore broke API access even though the cluster runs three embedded-etcd masters.
|
||||||
|
|
||||||
|
The fix needs one address that reaches any healthy API server. kube-vip documents a control-plane mode (`cp_enable`) for exactly this on k3s, and kube-vip already runs in this cluster as the DaemonSet that announces the Traefik LoadBalancer VIP.
|
||||||
|
|
||||||
|
## Decision
|
||||||
|
|
||||||
|
The control-plane VIP is a pfSense IP Alias Virtual IP with HAProxy load-balancing TCP 6443 across the three masters, as an opaque passthrough. It is not a second kube-vip instance.
|
||||||
|
|
||||||
|
In `02-k8s-bootstrap`:
|
||||||
|
|
||||||
|
- master-1 is installed with a `--tls-san` for both `master1Ip` and `controlPlaneVipAddress`.
|
||||||
|
- master-2, master-3 and all workers join through the VIP.
|
||||||
|
- The exported `kubeconfig` points at the VIP.
|
||||||
|
|
||||||
|
## Why not kube-vip control-plane mode
|
||||||
|
|
||||||
|
When this was decided, the existing kube-vip VIP for Traefik had an unresolved ARP-failover problem: a drained node kept announcing the VIP because drain does not evict DaemonSet pods. Putting API access behind a second ARP-announced VIP would have made the most critical endpoint depend on the same unproven failure mode. A VIP held by the router, outside the cluster, fails independently of it.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
|
||||||
|
- The pfSense side is manual. The `marshallford/pfsense` provider has no Virtual IP or HAProxy resources. Steps: [runbook](../runbooks/pfsense-control-plane-vip.md).
|
||||||
|
- pfSense becomes a dependency for API access.
|
||||||
|
- Existing masters need the extra TLS SAN before the VIP works for them; a fresh bootstrap gets it from the code.
|
||||||
|
- If API-server HA comes up again, kube-vip `cp_enable` was considered and rejected for the reason above. Revisit only if the ARP-failover behaviour is understood and fixed.
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
# Full cluster rebuild
|
||||||
|
|
||||||
|
Use this to rebuild the k3s cluster from new VMs. **It destroys everything stored in the cluster.** To change a running cluster, don't use this runbook.
|
||||||
|
|
||||||
|
> This procedure has not been run end to end. Stop at any checkpoint that doesn't match, and don't work around it with `--force` or by clicking through a preview.
|
||||||
|
|
||||||
|
## Why a normal `pulumi up` isn't enough
|
||||||
|
|
||||||
|
- **`02-k8s-bootstrap` commands run once.** They are recorded as done in state, so after new VMs appear, `pulumi up` would report them unchanged and install nothing.
|
||||||
|
- **`03`–`05` state describes the old cluster.** The fixed `clusterIdentifier` tells Pulumi it is still the same cluster, so it would try to update resources that no longer exist.
|
||||||
|
|
||||||
|
## Before you start
|
||||||
|
|
||||||
|
1. **Save your data.** Longhorn has no backup target configured, so its volumes are lost with the VMs. That includes `heimdall-config` and the Prometheus metrics. Grafana's database is external and is not affected.
|
||||||
|
2. **Stop automatic deploys.** In Gitea's **Actions** tab, disable the `01`, `03`, `04` and `05` workflows, and don't merge anything until the last step.
|
||||||
|
3. **Back up all state.** Run this from the repo root:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p ~/state-backups/rebuild
|
||||||
|
for S in 01-proxmox-infra 02-k8s-bootstrap 03-k8s-infra 04-k8s-apps 05-monitoring; do
|
||||||
|
pulumi stack export --stack dev --cwd "$S" --file ~/state-backups/rebuild/$S.json
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
These backups describe the old cluster. Once its VMs are deleted, don't restore them.
|
||||||
|
|
||||||
|
4. **Check what the rebuild depends on:**
|
||||||
|
- pfSense is running, with the [control-plane VIP and HAProxy](pfsense-control-plane-vip.md) configured. They are not managed by Pulumi. pfSense is VM 200 on the Optiplex, so if you reinstall that host, restore pfSense from a config backup first.
|
||||||
|
- The [TrueNAS NFS share](truenas-nfs.md) exists.
|
||||||
|
|
||||||
|
5. **If you reinstalled any Proxmox host:**
|
||||||
|
- Replace its CA in `02-k8s-bootstrap/certs/` (`pve1` is B550, `pve2` is Optiplex, `pve3` is Esprimo). Get it with `cat /etc/pve/pve-root-ca.pem`, and never copy anything from `/etc/pve/priv/`.
|
||||||
|
- Check that the host's certificate lists its current IP. `/etc/hosts` must have that IP before the certificate is generated.
|
||||||
|
- Recreate the API token, then update the token and endpoint in `01-proxmox-infra` config. Commit and push the change in `.pulumi-config` (see [Stack config](../../README.md#stack-config)), because CI uses the pushed version.
|
||||||
|
- The VM template on that host is gone too, so expect step 1 to recreate it.
|
||||||
|
|
||||||
|
## 1. Recreate the VMs (`01-proxmox-infra`)
|
||||||
|
|
||||||
|
1. In Proxmox, delete the six `k3s-*` VMs. Keep the `k3s-ubuntu-noble-template` VMs.
|
||||||
|
2. In pfSense, delete the six `k3s-*` DHCP static mappings. New VMs get new MAC addresses.
|
||||||
|
3. Sync state and preview:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pulumi refresh --stack dev --cwd 01-proxmox-infra
|
||||||
|
pulumi preview --stack dev --cwd 01-proxmox-infra
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** the preview creates six VMs and six DHCP mappings, plus a template for any reinstalled host. It must show no replace or delete. These resources are protected, so if one is still in state after the refresh, find its URN with `pulumi stack --show-urns` and remove only that entry:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pulumi state delete --force --stack dev --cwd 01-proxmox-infra '<urn>'
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Deploy. The VMs stay stopped until step 3.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pulumi up --stack dev --cwd 01-proxmox-infra
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. Clear the state of `02`–`05`
|
||||||
|
|
||||||
|
Only do this after the old VMs are gone. It removes Pulumi's records and doesn't touch real resources or `Pulumi.dev.yaml`. `--force` is needed because `05-monitoring` protects its namespace and Helm release, so check that the old cluster is really gone before running it.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
for S in 05-monitoring 04-k8s-apps 03-k8s-infra 02-k8s-bootstrap; do
|
||||||
|
pulumi state delete --all --force --yes --stack dev --cwd "$S"
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
Previews of `03`–`05` fail until step 3 is done, because `02` has no `kubeconfig` output yet.
|
||||||
|
|
||||||
|
## 3. Bootstrap k3s (`02-k8s-bootstrap`)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pulumi preview --stack dev --cwd 02-k8s-bootstrap
|
||||||
|
pulumi up --stack dev --cwd 02-k8s-bootstrap
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** the preview only creates resources. The deploy starts the VMs, installs k3s on master-1, waits for the VIP, then joins the other nodes through it. If a step fails, fix the cause and run `pulumi up` again.
|
||||||
|
|
||||||
|
Check the new cluster with its own kubeconfig:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
(umask 077; pulumi stack output kubeconfig --show-secrets --stack dev --cwd 02-k8s-bootstrap > ~/k3s-rebuilt.yaml)
|
||||||
|
KUBECONFIG=~/k3s-rebuilt.yaml kubectl get nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
Secret encryption is configured with `secretbox`.
|
||||||
|
|
||||||
|
**Checkpoint:** all six nodes are `Ready`. Then replace your normal kubeconfig with this file, because the old one no longer works.
|
||||||
|
|
||||||
|
## 4. Deploy `03`, `04` and `05`
|
||||||
|
|
||||||
|
Deploy these through Gitea, because the runners have the `helm` CLI that `03` needs. Re-enable each workflow as you reach it, and wait for each run to finish.
|
||||||
|
|
||||||
|
1. Run the **Deploy k8s Infra** workflow manually.
|
||||||
|
2. Run the **Deploy k8s Apps** workflow manually.
|
||||||
|
3. Run the **Deploy Monitoring** workflow manually.
|
||||||
|
|
||||||
|
## 5. Verify
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get nodes
|
||||||
|
kubectl get pods -A --field-selector=status.phase!=Running,status.phase!=Succeeded
|
||||||
|
kubectl get pvc -A
|
||||||
|
kubectl get nodes.longhorn.io -n longhorn-system
|
||||||
|
kubectl get certificates -A
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** nodes are `Ready`, no pods are unhealthy, PVCs are `Bound`, and certificates become `Ready`. New certificates come from Let's Encrypt, which rate-limits repeated requests for the same hostnames, so avoid repeated rebuilds in a short period.
|
||||||
|
|
||||||
|
Run `pulumi preview --stack dev --cwd <stack>` for all five stacks. None should show changes. Re-enable the `01` workflow, restore any data you saved, and delete `~/k3s-rebuilt.yaml` and `~/state-backups/rebuild`.
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
# Turn on k3s Secret encryption
|
||||||
|
|
||||||
|
Use this once to encrypt the Secrets in an existing cluster with `secretbox`. Don't use it for fresh installs, because `02-k8s-bootstrap` turns on encryption during installation. Don't use it to rotate keys later either.
|
||||||
|
|
||||||
|
> Steps 1–5 worked on the live cluster on 2026-12-01 with `v1.36.2+k3s1`. They're based on the k3s guide for existing clusters and the source code for that version. The guide doesn't cover starting with `secretbox`. **If a check doesn't match, stop.** Don't repeat `rotate-keys`, use `--force` or delete k3s files.
|
||||||
|
|
||||||
|
Don't deploy `02`, run the k3s installer or recreate VMs for this change.
|
||||||
|
|
||||||
|
## Before you start
|
||||||
|
|
||||||
|
1. Check that you have current VM backups of all 3 masters. They contain unencrypted Secrets, so restrict access to them.
|
||||||
|
2. Pause deployments, and don't merge anything until you finish.
|
||||||
|
3. Check that you can reach each master directly over SSH, not only through the control-plane VIP.
|
||||||
|
4. From your workstation, check the nodes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** all six nodes are `Ready`, and the masters run `v1.36.2+k3s1`.
|
||||||
|
|
||||||
|
5. On **each master**, check etcd and look for existing settings. The last two commands only print file or setting names:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s kubectl get --raw=/readyz/etcd; echo
|
||||||
|
sudo grep -rls 'secrets-encryption' /etc/rancher/k3s/
|
||||||
|
{ systemctl cat k3s; sudo cat /etc/default/k3s /etc/sysconfig/k3s /etc/systemd/system/k3s.service.env 2>/dev/null; } | grep -oE -- '--config|--secrets-encryption|K3S_CONFIG_FILE'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** each master prints only `ok`. Any other output means etcd has a problem, encryption settings already exist or k3s uses a custom config path.
|
||||||
|
|
||||||
|
## Restarting the masters
|
||||||
|
|
||||||
|
Steps 2 and 4 use this procedure. Restart `k3s-master-1` first, then `k3s-master-2`, then `k3s-master-3`. On each one, run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo systemctl restart k3s
|
||||||
|
sudo k3s kubectl get --raw=/readyz/etcd; echo
|
||||||
|
sudo k3s kubectl get nodes
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** etcd returns `ok` and all nodes are `Ready` before you restart the next master. The API can take a minute to respond, so rerun the two checks if needed. Finish all 3 restarts without long breaks.
|
||||||
|
|
||||||
|
## 1. Enable encryption and add the settings
|
||||||
|
|
||||||
|
1. On `k3s-master-1`, check the status:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s secrets-encrypt status
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** it shows `Disabled, no configuration file found`.
|
||||||
|
|
||||||
|
2. On `k3s-master-1` **only**, run this. It doesn't create a key or encrypt anything yet:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s secrets-encrypt enable
|
||||||
|
```
|
||||||
|
|
||||||
|
3. On **all 3 masters**, add the settings in a separate file, so the existing config stays unchanged:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mkdir -p /etc/rancher/k3s/config.yaml.d
|
||||||
|
sudo install -m 600 /dev/stdin /etc/rancher/k3s/config.yaml.d/90-secrets-encryption.yaml <<'EOF'
|
||||||
|
secrets-encryption: true
|
||||||
|
secrets-encryption-provider: secretbox
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. Restart and check the settings
|
||||||
|
|
||||||
|
1. [Restart all 3 masters](#restarting-the-masters).
|
||||||
|
2. On `k3s-master-1`, check the status:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s secrets-encrypt status
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** it shows `Disabled`, stage `start` and `All hashes match`.
|
||||||
|
|
||||||
|
3. From your workstation, check which encryption settings each master uses:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl get nodes -l node-role.kubernetes.io/control-plane -o json | jq -r '.items[] | .metadata.name + ": " + (.metadata.annotations["k3s.io/node-args"] | fromjson | join(" ") | [scan("--secrets-encryption[^ ]*(?: (?!--)[^ ]+)?")] | join(" "))'
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** all 3 masters show `--secrets-encryption` set to `true` and `--secrets-encryption-provider` set to `secretbox`. **Don't continue without both**, because the next step uses the provider setting to choose the key type.
|
||||||
|
|
||||||
|
## 3. Encrypt the Secrets
|
||||||
|
|
||||||
|
**Don't interrupt this step or restart any masters until it finishes.** A crash could stop the cluster from starting ([k3s issue 13763](https://github.com/k3s-io/k3s/issues/13763)), and we haven't confirmed a fix.
|
||||||
|
|
||||||
|
1. On `k3s-master-1`, run this **once**. It creates the key and re-encrypts the existing Secrets:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s secrets-encrypt rotate-keys
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Check the status until the stage is `reencrypt_finished`:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s secrets-encrypt status
|
||||||
|
```
|
||||||
|
|
||||||
|
If there's an error or no progress, check the logs with `sudo journalctl -u k3s --since '15 min ago'`, then stop. Don't run `rotate-keys` again.
|
||||||
|
|
||||||
|
## 4. Restart and check the status
|
||||||
|
|
||||||
|
1. [Restart all 3 masters](#restarting-the-masters) again.
|
||||||
|
2. On `k3s-master-1`, check the status:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s secrets-encrypt status
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** it shows `Enabled`, `reencrypt_finished`, `All hashes match` and an active `XSalsa20-POLY1305` key.
|
||||||
|
|
||||||
|
## 5. Verify
|
||||||
|
|
||||||
|
1. On **each master**, check that its API can read all Secrets. This doesn't print them:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s kubectl get secrets -A -o name >/dev/null && echo ok
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** each master prints `ok`.
|
||||||
|
|
||||||
|
2. From your workstation, create a test Secret with a fake value:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n default create secret generic encryption-test --from-literal=value=not-a-real-secret
|
||||||
|
```
|
||||||
|
|
||||||
|
3. On `k3s-master-1`, check the test Secret and an existing Secret in etcd. This needs `etcdctl`. If it's missing, install it with `sudo apt install etcd-client`. The command only prints the first 21 characters of each stored value:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
for key in default/encryption-test heimdall/heimdall-tls; do
|
||||||
|
sudo env ETCDCTL_API=3 etcdctl \
|
||||||
|
--endpoints=https://127.0.0.1:2379 \
|
||||||
|
--cacert=/var/lib/rancher/k3s/server/tls/etcd/server-ca.crt \
|
||||||
|
--cert=/var/lib/rancher/k3s/server/tls/etcd/client.crt \
|
||||||
|
--key=/var/lib/rancher/k3s/server/tls/etcd/client.key \
|
||||||
|
get "/registry/secrets/$key" --print-value-only | head -c 21
|
||||||
|
echo
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** both lines are `k8s:enc:secretbox:v1:`.
|
||||||
|
|
||||||
|
4. From your workstation, delete the test Secret, then check that your apps still work:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
kubectl -n default delete secret encryption-test
|
||||||
|
kubectl get pods -A --field-selector=status.phase!=Running,status.phase!=Succeeded
|
||||||
|
```
|
||||||
|
|
||||||
|
**Checkpoint:** no pods are listed, and the apps work normally.
|
||||||
|
|
||||||
|
## 6. Clean up
|
||||||
|
|
||||||
|
1. Make new VM backups of all 3 masters. Once they finish, delete the older ones, because their Secrets aren't encrypted. The new backups contain both the encrypted data and its key, so keep access restricted.
|
||||||
|
2. On **each master**, take a new etcd snapshot, then list the snapshots:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s etcd-snapshot save --name after-secrets-encryption
|
||||||
|
sudo k3s etcd-snapshot ls
|
||||||
|
```
|
||||||
|
|
||||||
|
3. On the master that holds each snapshot, delete any taken before step 4 finished. Check the name and date first, and delete any copies stored elsewhere too:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo k3s etcd-snapshot delete <snapshot-name>
|
||||||
|
```
|
||||||
|
|
||||||
|
Keep the remaining snapshots separate from the k3s server token. Someone with both can decrypt the Secrets.
|
||||||
|
|
||||||
|
4. Merge the `02` change, then resume deployments. Don't deploy `02`.
|
||||||
|
|
||||||
|
## If something goes wrong
|
||||||
|
|
||||||
|
Stop and save the status output and logs. **Don't restore just one master from a VM backup.** Its old etcd data and encryption settings may not match the other masters. Plan the recovery for all 3 masters together first. Restoring them loses any Kubernetes changes made after the backups and can leave them out of sync with the workers and Longhorn volumes.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [k3s: Turn on Secrets encryption](https://docs.k3s.io/cli/secrets-encrypt)
|
||||||
|
- [k3s: Encryption types](https://docs.k3s.io/security/secrets-encryption)
|
||||||
|
- [k3s: Config files](https://docs.k3s.io/installation/configuration)
|
||||||
|
- [k3s: Snapshots](https://docs.k3s.io/cli/etcd-snapshot)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# pfSense: control-plane VIP and HAProxy (one-time setup)
|
||||||
|
|
||||||
|
Do this once, before deploying `02-k8s-bootstrap`. It creates the address that `controlPlaneVipAddress` points at.
|
||||||
|
|
||||||
|
The `@pulumi/pfsense` provider used by `01-proxmox-infra` doesn't expose Virtual IP or HAProxy resources (only DHCP static mappings, DNS overrides, and firewall aliases), so this is manual, not Pulumi-managed. For why the VIP lives on pfSense at all, see [the decision record](../decisions/0001-control-plane-vip-via-pfsense-haproxy.md).
|
||||||
|
|
||||||
|
1. Confirm `controlPlaneVipAddress` falls outside the DHCP pool (Services → DHCP Server → Range).
|
||||||
|
2. Firewall → Virtual IPs → Add: Type = `IP Alias`, Interface = `LAN`, Address = `<controlPlaneVipAddress>/32`.
|
||||||
|
3. System → Package Manager → install `haproxy` if not already installed.
|
||||||
|
4. Services → HAProxy → Backend: add a pool (e.g. `k3s-apiservers`), mode `TCP`, health check `TCP check` (or `ssl-hello-chk`), servers = `<master1Ip>:6443`, `<master2Ip>:6443`, `<master3Ip>:6443`.
|
||||||
|
5. Services → HAProxy → Frontend: add a frontend listening on `<controlPlaneVipAddress>:6443`, type `TCP` (not HTTP — this must stay an opaque passthrough so clients validate k3s's own TLS cert, not one terminated at pfSense), default backend = the pool from step 4.
|
||||||
|
6. Services → HAProxy → Settings: enable HAProxy, apply.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# TrueNAS: NFS share for the `truenas-nfs` StorageClass (one-time setup)
|
||||||
|
|
||||||
|
Do this once, before deploying `03-k8s-infra`. The share is what `truenasHost` and `truenasNfsPath` point at.
|
||||||
|
|
||||||
|
1. Create dataset `pool/k8s`
|
||||||
|
2. Add an NFS share for that dataset:
|
||||||
|
- ACL type: POSIX/generic Unix permissions (not SMB/NFSv4 ACLs) on TrueNAS SCALE
|
||||||
|
- Maproot User / Group: `root` / `root`
|
||||||
|
- Allowed Hosts/Networks: restrict to the k3s node IPs/CIDR
|
||||||
|
3. In Network → Allowed Networks, permit your LAN subnet (e.g. `192.168.1.0/24`)
|
||||||
@@ -1,87 +0,0 @@
|
|||||||
# k8s-bootstrap
|
|
||||||
|
|
||||||
Bootstraps a k3s cluster on the 5 Proxmox VMs created by `proxmox-infra`. Starts VMs via the Proxmox REST API, then provisions k3s over SSH using `@pulumi/command` remote.Command.
|
|
||||||
|
|
||||||
## How it works
|
|
||||||
|
|
||||||
1. Starts all 5 VMs via `POST /api2/json/nodes/{node}/qemu/{vmid}/status/start`
|
|
||||||
2. Waits for port 22 to open on each VM (bash `/dev/tcp`)
|
|
||||||
3. Installs k3s on `k3s-master-1` with `--cluster-init --tls-san <master1Ip>`
|
|
||||||
4. Joins `k3s-master-2` and `k3s-master-3` as embedded etcd nodes
|
|
||||||
5. Joins `k3s-worker-1` and `k3s-worker-2` as agent nodes
|
|
||||||
6. Reads `/etc/rancher/k3s/k3s.yaml` from master-1 via SSH, patches server URL, exports as secret stack output
|
|
||||||
|
|
||||||
VM IDs and the CI runner SSH private key are read automatically from the `proxmox-infra` stack output via `StackReference` — no manual setup needed for those.
|
|
||||||
|
|
||||||
## Required Pulumi config
|
|
||||||
|
|
||||||
Run in this directory after `pulumi stack init dev`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Pre-shared k3s token — any strong random string
|
|
||||||
pulumi config set --secret k3sToken "$(openssl rand -hex 32)"
|
|
||||||
|
|
||||||
# Node IPs — static DHCP leases from the router (not secrets)
|
|
||||||
pulumi config set master1Ip "192.168.1.x"
|
|
||||||
pulumi config set master2Ip "192.168.1.x"
|
|
||||||
pulumi config set master3Ip "192.168.1.x"
|
|
||||||
pulumi config set worker1Ip "192.168.1.x"
|
|
||||||
pulumi config set worker2Ip "192.168.1.x"
|
|
||||||
```
|
|
||||||
|
|
||||||
Proxmox credentials (`pve1Endpoint`, `pve1ApiToken`, `pve2Endpoint`, `pve2ApiToken`) are read automatically from the `proxmox-infra` stack outputs via StackReference — do **not** set them here.
|
|
||||||
|
|
||||||
## Deployment order
|
|
||||||
|
|
||||||
`proxmox-infra` must be deployed **before** k8s-bootstrap. The proxmox-infra stack exports the Proxmox credentials and VM IDs that k8s-bootstrap reads via StackReference. If proxmox-infra hasn't been re-deployed after its latest code changes, those outputs won't exist and k8s-bootstrap will fail.
|
|
||||||
|
|
||||||
In CI, both workflows run as previews on PRs (no deploy). Trigger `workflow_dispatch` on `deploy-proxmox-infra` first, then run k8s-bootstrap.
|
|
||||||
|
|
||||||
After setting config, re-encode `Pulumi.dev.yaml` and update the Gitea secret `K8S_BOOTSTRAP_DEV_YAML`:
|
|
||||||
```bash
|
|
||||||
base64 -w 0 Pulumi.dev.yaml
|
|
||||||
# Copy output → Gitea → Settings → Actions → Secrets → K8S_BOOTSTRAP_DEV_YAML
|
|
||||||
```
|
|
||||||
|
|
||||||
## Prerequisites
|
|
||||||
|
|
||||||
`proxmox-infra` must be deployed first. On first `pulumi up`, it generates an ed25519 SSH keypair via `@pulumi/tls`, writes the public key into every VM's cloud-init, and exports the private key as a secret stack output. VMs must be re-provisioned (or the public key manually added to `~/.ssh/authorized_keys`) before k8s-bootstrap can SSH in.
|
|
||||||
|
|
||||||
## After first run
|
|
||||||
|
|
||||||
The `kubeconfig` stack output must be propagated to `k8s-infra` and `k8s-apps`:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
KUBECONFIG=$(pulumi stack output kubeconfig --show-secrets)
|
|
||||||
cd ../k8s-infra && pulumi config set --secret kubeconfig "$KUBECONFIG"
|
|
||||||
cd ../k8s-apps && pulumi config set --secret kubeconfig "$KUBECONFIG"
|
|
||||||
```
|
|
||||||
|
|
||||||
Then re-encode each `Pulumi.dev.yaml` and update the corresponding Gitea secrets
|
|
||||||
(`K8S_INFRA_DEV_YAML`, `K8S_APPS_DEV_YAML`):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
base64 -w 0 k8s-infra/Pulumi.dev.yaml
|
|
||||||
base64 -w 0 k8s-apps/Pulumi.dev.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
## k8s-infra config changes (democratic-csi → NFS CSI)
|
|
||||||
|
|
||||||
The `k8s-infra` stack no longer needs `truenasApiKey` or `truenasDataset`.
|
|
||||||
Replace them with:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd ../k8s-infra
|
|
||||||
pulumi config set truenasHost "192.168.1.x"
|
|
||||||
pulumi config set truenasNfsPath "/mnt/tank/k8s"
|
|
||||||
# Remove old keys if present:
|
|
||||||
pulumi config rm truenasApiKey
|
|
||||||
pulumi config rm truenasDataset
|
|
||||||
```
|
|
||||||
|
|
||||||
## TrueNAS one-time setup (before deploying k8s-infra)
|
|
||||||
|
|
||||||
1. Create a dataset: `tank/k8s`
|
|
||||||
2. Add an NFS share for that dataset
|
|
||||||
3. In Network → Allowed Networks, permit `192.168.1.0/24`
|
|
||||||
4. No API key required — the NFS CSI driver connects directly via NFS protocol
|
|
||||||
@@ -1,235 +0,0 @@
|
|||||||
import * as pulumi from "@pulumi/pulumi";
|
|
||||||
import * as command from "@pulumi/command";
|
|
||||||
|
|
||||||
const config = new pulumi.Config();
|
|
||||||
|
|
||||||
//fetch credentials from proxmox-infra
|
|
||||||
const infraRef = new pulumi.StackReference(
|
|
||||||
`${pulumi.getOrganization()}/proxmox-infra/dev`,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Proxmox API credentials — same as proxmox-infra stack
|
|
||||||
const pve1Endpoint = infraRef.requireOutput(
|
|
||||||
"pve1Endpoint",
|
|
||||||
) as pulumi.Output<string>;
|
|
||||||
const pve1ApiToken = infraRef.requireOutput(
|
|
||||||
"pve1ApiToken",
|
|
||||||
) as pulumi.Output<string>;
|
|
||||||
const pve2Endpoint = infraRef.requireOutput(
|
|
||||||
"pve2Endpoint",
|
|
||||||
) as pulumi.Output<string>;
|
|
||||||
const pve2ApiToken = infraRef.requireOutput(
|
|
||||||
"pve2ApiToken",
|
|
||||||
) as pulumi.Output<string>;
|
|
||||||
|
|
||||||
// Node IPs — static DHCP leases set in the router
|
|
||||||
const master1Ip = infraRef.requireOutput("master1Ip");
|
|
||||||
const master2Ip = infraRef.requireOutput("master2Ip");
|
|
||||||
const master3Ip = infraRef.requireOutput("master3Ip");
|
|
||||||
const worker1Ip = infraRef.requireOutput("worker1Ip");
|
|
||||||
const worker2Ip = infraRef.requireOutput("worker2Ip");
|
|
||||||
|
|
||||||
// Pre-shared k3s cluster token
|
|
||||||
const k3sToken = config.requireSecret("k3sToken");
|
|
||||||
|
|
||||||
// VM IDs and CI runner SSH key — read from proxmox-infra stack outputs
|
|
||||||
const vmIdsOutput = infraRef.requireOutput("vmIds") as pulumi.Output<
|
|
||||||
Record<string, number>
|
|
||||||
>;
|
|
||||||
const ciRunnerPrivateKey = infraRef.requireOutput(
|
|
||||||
"ciRunnerPrivateKey",
|
|
||||||
) as pulumi.Output<string>;
|
|
||||||
|
|
||||||
const master1VmId = vmIdsOutput.apply((ids) => String(ids.master1));
|
|
||||||
const master2VmId = vmIdsOutput.apply((ids) => String(ids.master2));
|
|
||||||
const master3VmId = vmIdsOutput.apply((ids) => String(ids.master3));
|
|
||||||
const worker1VmId = vmIdsOutput.apply((ids) => String(ids.worker1));
|
|
||||||
const worker2VmId = vmIdsOutput.apply((ids) => String(ids.worker2));
|
|
||||||
|
|
||||||
// SSH connection helper
|
|
||||||
function conn(
|
|
||||||
ip: pulumi.Input<string>,
|
|
||||||
): command.types.input.remote.ConnectionArgs {
|
|
||||||
return { host: ip, user: "ubuntu", privateKey: ciRunnerPrivateKey };
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Step 1: Start all VMs (fire-and-forget — VMs are owned by proxmox-infra)
|
|
||||||
// triggers: vmId — forces re-run when VMs are deleted and recreated
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const startMaster1 = new command.local.Command("start-master-1", {
|
|
||||||
create: pulumi.interpolate`curl -sf -k -X POST -H "Authorization: PVEAPIToken=${pve1ApiToken}" "${pve1Endpoint}/api2/json/nodes/pve/qemu/${master1VmId}/status/start" 2>/dev/null || true`,
|
|
||||||
triggers: [master1VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startMaster2 = new command.local.Command("start-master-2", {
|
|
||||||
create: pulumi.interpolate`curl -sf -k -X POST -H "Authorization: PVEAPIToken=${pve1ApiToken}" "${pve1Endpoint}/api2/json/nodes/pve/qemu/${master2VmId}/status/start" 2>/dev/null || true`,
|
|
||||||
triggers: [master2VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startWorker1 = new command.local.Command("start-worker-1", {
|
|
||||||
create: pulumi.interpolate`curl -sf -k -X POST -H "Authorization: PVEAPIToken=${pve1ApiToken}" "${pve1Endpoint}/api2/json/nodes/pve/qemu/${worker1VmId}/status/start" 2>/dev/null || true`,
|
|
||||||
triggers: [worker1VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startMaster3 = new command.local.Command("start-master-3", {
|
|
||||||
create: pulumi.interpolate`curl -sf -k -X POST -H "Authorization: PVEAPIToken=${pve2ApiToken}" "${pve2Endpoint}/api2/json/nodes/pve-bckp/qemu/${master3VmId}/status/start" 2>/dev/null || true`,
|
|
||||||
triggers: [master3VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
const startWorker2 = new command.local.Command("start-worker-2", {
|
|
||||||
create: pulumi.interpolate`curl -sf -k -X POST -H "Authorization: PVEAPIToken=${pve2ApiToken}" "${pve2Endpoint}/api2/json/nodes/pve-bckp/qemu/${worker2VmId}/status/start" 2>/dev/null || true`,
|
|
||||||
triggers: [worker2VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
});
|
|
||||||
|
|
||||||
const allStarts = [
|
|
||||||
startMaster1,
|
|
||||||
startMaster2,
|
|
||||||
startMaster3,
|
|
||||||
startWorker1,
|
|
||||||
startWorker2,
|
|
||||||
];
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Step 2: Wait for SSH on master-1, install k3s
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const waitMaster1Ssh = new command.local.Command(
|
|
||||||
"wait-ssh-master-1",
|
|
||||||
{
|
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master1Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [master1VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: allStarts },
|
|
||||||
);
|
|
||||||
|
|
||||||
const installMaster1 = new command.remote.Command(
|
|
||||||
"install-k3s-master-1",
|
|
||||||
{
|
|
||||||
connection: conn(master1Ip),
|
|
||||||
create: pulumi.interpolate`curl -sfL https://get.k3s.io | sudo K3S_TOKEN='${k3sToken}' sh -s - server --cluster-init --tls-san ${master1Ip} --node-name k3s-master-1`,
|
|
||||||
triggers: [master1VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitMaster1Ssh] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const waitK3sMaster1Ready = new command.remote.Command(
|
|
||||||
"wait-k3s-master-1-ready",
|
|
||||||
{
|
|
||||||
connection: conn(master1Ip),
|
|
||||||
create: `for i in $(seq 1 60); do sudo kubectl --kubeconfig /etc/rancher/k3s/k3s.yaml get node k3s-master-1 --no-headers 2>/dev/null | grep -q " Ready" && exit 0; sleep 10; done; exit 1`,
|
|
||||||
triggers: [master1VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [installMaster1] },
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Step 3: Wait for SSH on remaining masters, join cluster
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const waitMaster2Ssh = new command.local.Command(
|
|
||||||
"wait-ssh-master-2",
|
|
||||||
{
|
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master2Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [master2VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitK3sMaster1Ready] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const waitMaster3Ssh = new command.local.Command(
|
|
||||||
"wait-ssh-master-3",
|
|
||||||
{
|
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${master3Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [master3VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitK3sMaster1Ready] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const joinMaster2 = new command.remote.Command(
|
|
||||||
"join-k3s-master-2",
|
|
||||||
{
|
|
||||||
connection: conn(master2Ip),
|
|
||||||
create: pulumi.interpolate`curl -sfL https://get.k3s.io | sudo K3S_TOKEN='${k3sToken}' sh -s - server --server https://${master1Ip}:6443 --node-name k3s-master-2`,
|
|
||||||
triggers: [master2VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitMaster2Ssh] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const joinMaster3 = new command.remote.Command(
|
|
||||||
"join-k3s-master-3",
|
|
||||||
{
|
|
||||||
connection: conn(master3Ip),
|
|
||||||
create: pulumi.interpolate`curl -sfL https://get.k3s.io | sudo K3S_TOKEN='${k3sToken}' sh -s - server --server https://${master1Ip}:6443 --node-name k3s-master-3`,
|
|
||||||
triggers: [master3VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitMaster3Ssh, joinMaster2] },
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Step 4: Join worker nodes
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const waitWorker1Ssh = new command.local.Command(
|
|
||||||
"wait-ssh-worker-1",
|
|
||||||
{
|
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker1Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [worker1VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [joinMaster3] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const waitWorker2Ssh = new command.local.Command(
|
|
||||||
"wait-ssh-worker-2",
|
|
||||||
{
|
|
||||||
create: pulumi.interpolate`for i in $(seq 1 60); do (timeout 5 bash -c "echo > /dev/tcp/${worker2Ip}/22") 2>/dev/null && exit 0; sleep 5; done; exit 1`,
|
|
||||||
triggers: [worker2VmId],
|
|
||||||
interpreter: ["/bin/bash", "-c"],
|
|
||||||
},
|
|
||||||
{ dependsOn: [joinMaster3] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const joinWorker1 = new command.remote.Command(
|
|
||||||
"join-k3s-worker-1",
|
|
||||||
{
|
|
||||||
connection: conn(worker1Ip),
|
|
||||||
create: pulumi.interpolate`curl -sfL https://get.k3s.io | sudo K3S_URL=https://${master1Ip}:6443 K3S_TOKEN='${k3sToken}' sh -s - --node-name k3s-worker-1`,
|
|
||||||
triggers: [worker1VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitWorker1Ssh] },
|
|
||||||
);
|
|
||||||
|
|
||||||
const joinWorker2 = new command.remote.Command(
|
|
||||||
"join-k3s-worker-2",
|
|
||||||
{
|
|
||||||
connection: conn(worker2Ip),
|
|
||||||
create: pulumi.interpolate`curl -sfL https://get.k3s.io | sudo K3S_URL=https://${master1Ip}:6443 K3S_TOKEN='${k3sToken}' sh -s - --node-name k3s-worker-2`,
|
|
||||||
triggers: [worker2VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [waitWorker2Ssh] },
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Step 5: Read kubeconfig from master-1, patch server URL for external access
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const getKubeconfig = new command.remote.Command(
|
|
||||||
"get-kubeconfig",
|
|
||||||
{
|
|
||||||
connection: conn(master1Ip),
|
|
||||||
create: `sudo cat /etc/rancher/k3s/k3s.yaml`,
|
|
||||||
triggers: [master1VmId],
|
|
||||||
},
|
|
||||||
{ dependsOn: [joinWorker1, joinWorker2] },
|
|
||||||
);
|
|
||||||
|
|
||||||
export const kubeconfig = pulumi.secret(
|
|
||||||
pulumi
|
|
||||||
.all([getKubeconfig.stdout, master1Ip])
|
|
||||||
.apply(([kc, ip]) => kc.replaceAll("127.0.0.1", ip as string).trim()),
|
|
||||||
);
|
|
||||||
Generated
-2670
File diff suppressed because it is too large.
Load diff
@@ -1,12 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "k8s-bootstrap",
|
|
||||||
"main": "index.ts",
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^18",
|
|
||||||
"typescript": "^5.0.0"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@pulumi/command": "^0.11.0",
|
|
||||||
"@pulumi/pulumi": "^3.113.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
# CLAUDE.md
|
|
||||||
|
|
||||||
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
||||||
|
|
||||||
## Project Overview
|
|
||||||
|
|
||||||
This is a Pulumi TypeScript project (`proxmox-infra`) for provisioning VMs and LXC containers in Proxmox using the `@muhlba91/pulumi-proxmoxve` provider. The stack name is `dev`.
|
|
||||||
|
|
||||||
## Common Commands
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Install dependencies
|
|
||||||
npm install
|
|
||||||
|
|
||||||
# Preview infrastructure changes
|
|
||||||
pulumi preview
|
|
||||||
|
|
||||||
# Sync Pulumi state with actual Proxmox state (run before up if resources were changed manually)
|
|
||||||
pulumi refresh --yes
|
|
||||||
|
|
||||||
# Deploy infrastructure
|
|
||||||
pulumi refresh --yes && pulumi up --yes
|
|
||||||
|
|
||||||
# Destroy infrastructure
|
|
||||||
pulumi destroy
|
|
||||||
|
|
||||||
# View current stack outputs
|
|
||||||
pulumi stack output
|
|
||||||
|
|
||||||
# View stack config
|
|
||||||
pulumi config
|
|
||||||
```
|
|
||||||
|
|
||||||
## Architecture
|
|
||||||
|
|
||||||
- **Entry point**: `index.ts` — all Pulumi resources are declared here
|
|
||||||
- **Provider**: `@muhlba91/pulumi-proxmoxve` v8.x — community Proxmox provider (not an official Pulumi provider)
|
|
||||||
- **Stack**: `dev` — configured in `Pulumi.dev.yaml`
|
|
||||||
- **Runtime**: Node.js with `npm`, TypeScript compiled to `bin/` (excluded from git)
|
|
||||||
|
|
||||||
## CI/CD (Gitea Actions)
|
|
||||||
|
|
||||||
Workflow file: `../.gitea/workflows/deploy-proxmox-infra.yaml`
|
|
||||||
|
|
||||||
Triggers: push to `main` and pull requests targeting `main`, scoped to changes under `proxmox-infra/**` or `.gitea/workflows/**`.
|
|
||||||
|
|
||||||
- **Pull request** → `pulumi preview` (no changes deployed)
|
|
||||||
- **Push to main** → `pulumi refresh` then `pulumi up`
|
|
||||||
|
|
||||||
Secrets required in Gitea (`Settings → Actions → Secrets`):
|
|
||||||
|
|
||||||
- `PULUMI_BACKEND_URL` — PostgreSQL connection string for the self-hosted state backend
|
|
||||||
- `PULUMI_CONFIG_PASSPHRASE` — passphrase used to decrypt secrets in `Pulumi.dev.yaml`
|
|
||||||
- `PULUMI_DEV_YAML` — base64-encoded content of `Pulumi.dev.yaml`; update manually whenever the file changes: `base64 -w 0 Pulumi.dev.yaml`
|
|
||||||
|
|
||||||
## Key Notes
|
|
||||||
|
|
||||||
- Credentials for both Proxmox nodes are stored as encrypted secrets in `Pulumi.dev.yaml` and decrypted at runtime using `PULUMI_CONFIG_PASSPHRASE`. Do not pass Proxmox credentials via environment variables — the code uses `config.requireSecret()`.
|
|
||||||
- There are two Proxmox providers: `pveProvider` (main node `pve`) and `pveBckpProvider` (backup node `pve-bckp`). Always pass the correct provider when adding resources.
|
|
||||||
- `Pulumi.dev.yaml` contains the encryption salt — never delete it or secrets become unrecoverable.
|
|
||||||
- TypeScript is compiled with strict mode, `nodenext` module resolution, and `noImplicitReturns` — all functions must have explicit return types when TypeScript cannot infer them.
|
|
||||||
- Don't add a co-author when committing to git.
|
|
||||||
@@ -1,321 +0,0 @@
|
|||||||
import * as pulumi from "@pulumi/pulumi";
|
|
||||||
import * as proxmox from "@muhlba91/pulumi-proxmoxve";
|
|
||||||
import * as tls from "@pulumi/tls";
|
|
||||||
import * as pfsense from "@pulumi/pfsense";
|
|
||||||
|
|
||||||
const config = new pulumi.Config();
|
|
||||||
|
|
||||||
const pve1Endpoint = config.requireSecret("pve1Endpoint");
|
|
||||||
const pve1ApiToken = config.requireSecret("pve1ApiToken");
|
|
||||||
const pve2Endpoint = config.requireSecret("pve2Endpoint");
|
|
||||||
const pve2ApiToken = config.requireSecret("pve2ApiToken");
|
|
||||||
|
|
||||||
const pfSenseUrl = config.requireSecret("pfSenseUrl");
|
|
||||||
const pfSenseUser = config.requireSecret("pfSenseUser");
|
|
||||||
const pfSensePassword = config.requireSecret("pfSensePassword");
|
|
||||||
|
|
||||||
const master1Ip = config.requireSecret("master1Ip");
|
|
||||||
const master2Ip = config.requireSecret("master2Ip");
|
|
||||||
const worker1Ip = config.requireSecret("worker1Ip");
|
|
||||||
const master3Ip = config.requireSecret("master3Ip");
|
|
||||||
const worker2Ip = config.requireSecret("worker2Ip");
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Providers — one per standalone Proxmox machine
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const pveProvider = new proxmox.Provider("pve", {
|
|
||||||
endpoint: pve1Endpoint,
|
|
||||||
apiToken: pve1ApiToken,
|
|
||||||
insecure: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
const pveBckpProvider = new proxmox.Provider("pve-bckp", {
|
|
||||||
endpoint: pve2Endpoint,
|
|
||||||
apiToken: pve2ApiToken,
|
|
||||||
insecure: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Providers — PfSense
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const pfSenseProvider = new pfsense.Provider("pfsense", {
|
|
||||||
url: pfSenseUrl,
|
|
||||||
username: pfSenseUser,
|
|
||||||
password: pfSensePassword,
|
|
||||||
tlsSkipVerify: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// CI runner SSH keypair — generated once, stored in Pulumi state backend.
|
|
||||||
// Public key goes into every VM; private key is exported for k8s-bootstrap.
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const ciRunnerKey = new tls.PrivateKey("ci-runner-key", {
|
|
||||||
algorithm: "ED25519",
|
|
||||||
});
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// Download Ubuntu Noble cloud image to each node's ISO storage
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const ubuntuNobleUrl =
|
|
||||||
"https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img";
|
|
||||||
|
|
||||||
const ubuntuImagePve = new proxmox.download.File(
|
|
||||||
"ubuntu-noble-pve",
|
|
||||||
{
|
|
||||||
nodeName: "pve",
|
|
||||||
datastoreId: "pve-local-ext1",
|
|
||||||
contentType: "import",
|
|
||||||
fileName: "noble-server-cloudimg-amd64.qcow2",
|
|
||||||
url: ubuntuNobleUrl,
|
|
||||||
overwrite: true,
|
|
||||||
overwriteUnmanaged: true,
|
|
||||||
},
|
|
||||||
{ provider: pveProvider },
|
|
||||||
);
|
|
||||||
|
|
||||||
const ubuntuImagePveBckp = new proxmox.download.File(
|
|
||||||
"ubuntu-noble-pve-bckp",
|
|
||||||
{
|
|
||||||
nodeName: "pve-bckp",
|
|
||||||
datastoreId: "local",
|
|
||||||
contentType: "import",
|
|
||||||
fileName: "noble-server-cloudimg-amd64.qcow2",
|
|
||||||
url: ubuntuNobleUrl,
|
|
||||||
overwrite: true,
|
|
||||||
overwriteUnmanaged: true,
|
|
||||||
},
|
|
||||||
{ provider: pveBckpProvider },
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// VM templates — one per node, cloned from the downloaded cloud image.
|
|
||||||
// Templates are not started and have no cloud-init config; that is applied
|
|
||||||
// per-clone so each node gets its own hostname (derived from VM name).
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const templateSettings = {
|
|
||||||
template: true,
|
|
||||||
started: false,
|
|
||||||
stopOnDestroy: true,
|
|
||||||
scsiHardware: "virtio-scsi-pci",
|
|
||||||
cpu: {
|
|
||||||
cores: 2,
|
|
||||||
sockets: 1,
|
|
||||||
type: "host",
|
|
||||||
numa: true,
|
|
||||||
},
|
|
||||||
memory: {
|
|
||||||
dedicated: 2048,
|
|
||||||
floating: 0,
|
|
||||||
},
|
|
||||||
networkDevices: [{ bridge: "vmbr0", model: "virtio" }],
|
|
||||||
serialDevices: [{}],
|
|
||||||
vga: { type: "serial0" },
|
|
||||||
agent: { enabled: true },
|
|
||||||
};
|
|
||||||
|
|
||||||
const pveTemplate = new proxmox.VmLegacy(
|
|
||||||
"k3s-template-pve",
|
|
||||||
{
|
|
||||||
...templateSettings,
|
|
||||||
nodeName: "pve",
|
|
||||||
name: "k3s-ubuntu-noble-template",
|
|
||||||
disks: [
|
|
||||||
{
|
|
||||||
interface: "scsi0",
|
|
||||||
datastoreId: "local-lvm",
|
|
||||||
importFrom: pulumi.interpolate`${ubuntuImagePve.datastoreId}:import/${ubuntuImagePve.fileName}`,
|
|
||||||
size: 10,
|
|
||||||
ssd: true,
|
|
||||||
discard: "on",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ provider: pveProvider },
|
|
||||||
);
|
|
||||||
|
|
||||||
const pveBckpTemplate = new proxmox.VmLegacy(
|
|
||||||
"k3s-template-pve-bckp",
|
|
||||||
{
|
|
||||||
...templateSettings,
|
|
||||||
nodeName: "pve-bckp",
|
|
||||||
name: "k3s-ubuntu-noble-template",
|
|
||||||
disks: [
|
|
||||||
{
|
|
||||||
interface: "scsi0",
|
|
||||||
datastoreId: "local",
|
|
||||||
importFrom: pulumi.interpolate`${ubuntuImagePveBckp.datastoreId}:import/${ubuntuImagePveBckp.fileName}`,
|
|
||||||
size: 10,
|
|
||||||
ssd: true,
|
|
||||||
discard: "on",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ provider: pveBckpProvider },
|
|
||||||
);
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
// k3s nodes — full clones of their respective templates
|
|
||||||
// ---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
const k3sVmPassword = config.requireSecret("k3sVmPassword");
|
|
||||||
const sshPvePublicKey = config.requireSecret("sshPvePublicKey");
|
|
||||||
|
|
||||||
interface NodeConfig {
|
|
||||||
name: string;
|
|
||||||
role: "master" | "worker";
|
|
||||||
nodeName: string;
|
|
||||||
provider: proxmox.Provider;
|
|
||||||
template: proxmox.VmLegacy;
|
|
||||||
diskDatastore: string;
|
|
||||||
ip: pulumi.Output<string>;
|
|
||||||
}
|
|
||||||
|
|
||||||
const nodeConfigs: NodeConfig[] = [
|
|
||||||
{
|
|
||||||
name: "k3s-master-1",
|
|
||||||
role: "master",
|
|
||||||
nodeName: "pve",
|
|
||||||
provider: pveProvider,
|
|
||||||
template: pveTemplate,
|
|
||||||
diskDatastore: "local-lvm",
|
|
||||||
ip: master1Ip,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "k3s-master-2",
|
|
||||||
role: "master",
|
|
||||||
nodeName: "pve",
|
|
||||||
provider: pveProvider,
|
|
||||||
template: pveTemplate,
|
|
||||||
diskDatastore: "local-lvm",
|
|
||||||
ip: master2Ip,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "k3s-worker-1",
|
|
||||||
role: "worker",
|
|
||||||
nodeName: "pve",
|
|
||||||
provider: pveProvider,
|
|
||||||
template: pveTemplate,
|
|
||||||
diskDatastore: "local-lvm",
|
|
||||||
ip: worker1Ip,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "k3s-master-3",
|
|
||||||
role: "master",
|
|
||||||
nodeName: "pve-bckp",
|
|
||||||
provider: pveBckpProvider,
|
|
||||||
template: pveBckpTemplate,
|
|
||||||
diskDatastore: "local",
|
|
||||||
ip: master3Ip,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "k3s-worker-2",
|
|
||||||
role: "worker",
|
|
||||||
nodeName: "pve-bckp",
|
|
||||||
provider: pveBckpProvider,
|
|
||||||
template: pveBckpTemplate,
|
|
||||||
diskDatastore: "local",
|
|
||||||
ip: worker2Ip,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const k3sVms = nodeConfigs.map(
|
|
||||||
(node) =>
|
|
||||||
new proxmox.VmLegacy(
|
|
||||||
node.name,
|
|
||||||
{
|
|
||||||
nodeName: node.nodeName,
|
|
||||||
name: node.name,
|
|
||||||
description: "k3s " + node.role + " node — managed by Pulumi",
|
|
||||||
tags: ["k3s", node.role],
|
|
||||||
clone: {
|
|
||||||
vmId: node.template.vmId,
|
|
||||||
full: true,
|
|
||||||
datastoreId: node.diskDatastore,
|
|
||||||
},
|
|
||||||
cpu: {
|
|
||||||
cores: 2,
|
|
||||||
sockets: 1,
|
|
||||||
type: "host",
|
|
||||||
numa: true,
|
|
||||||
},
|
|
||||||
memory: {
|
|
||||||
dedicated: 2048,
|
|
||||||
floating: 0,
|
|
||||||
},
|
|
||||||
disks: [
|
|
||||||
{
|
|
||||||
interface: "scsi0",
|
|
||||||
datastoreId: node.diskDatastore,
|
|
||||||
size: 10,
|
|
||||||
ssd: true,
|
|
||||||
discard: "on",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
initialization: {
|
|
||||||
datastoreId: node.diskDatastore,
|
|
||||||
ipConfigs: [{ ipv4: { address: "dhcp" } }],
|
|
||||||
userAccount: {
|
|
||||||
username: "ubuntu",
|
|
||||||
password: k3sVmPassword,
|
|
||||||
keys: [
|
|
||||||
sshPvePublicKey.apply((k) => k.trim()),
|
|
||||||
ciRunnerKey.publicKeyOpenssh.apply((k) => k.trim()),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
networkDevices: [{ bridge: "vmbr0", model: "virtio" }],
|
|
||||||
scsiHardware: "virtio-scsi-pci",
|
|
||||||
serialDevices: [{}],
|
|
||||||
vga: { type: "serial0" },
|
|
||||||
agent: { enabled: true },
|
|
||||||
started: false,
|
|
||||||
stopOnDestroy: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
provider: node.provider,
|
|
||||||
retainOnDelete: true,
|
|
||||||
ignoreChanges: ["clone"],
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
k3sVms.forEach((vmResource, i) => {
|
|
||||||
const assignedMac = vmResource.networkDevices.apply(
|
|
||||||
(nic) => nic[0].macAddress,
|
|
||||||
);
|
|
||||||
|
|
||||||
return new pfsense.Dhcpv4Staticmapping(
|
|
||||||
`${nodeConfigs[i].name}-dhcp`,
|
|
||||||
{
|
|
||||||
interface: "lan",
|
|
||||||
macAddress: assignedMac,
|
|
||||||
ipAddress: nodeConfigs[i].ip,
|
|
||||||
hostname: nodeConfigs[i].name,
|
|
||||||
},
|
|
||||||
{ dependsOn: vmResource, provider: pfSenseProvider },
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Individual vmId exports — used by k8s-bootstrap to start VMs.
|
|
||||||
// Order matches nodeConfigs: master-1, master-2, worker-1, master-3, worker-2.
|
|
||||||
export const vmIds = {
|
|
||||||
master1: k3sVms[0].vmId,
|
|
||||||
master2: k3sVms[1].vmId,
|
|
||||||
worker1: k3sVms[2].vmId,
|
|
||||||
master3: k3sVms[3].vmId,
|
|
||||||
worker2: k3sVms[4].vmId,
|
|
||||||
};
|
|
||||||
|
|
||||||
// CI runner SSH private key — consumed by k8s-bootstrap via StackReference.
|
|
||||||
export const ciRunnerPrivateKey = pulumi.secret(ciRunnerKey.privateKeyOpenssh);
|
|
||||||
|
|
||||||
// Proxmox API credentials — consumed by k8s-bootstrap via StackReference.
|
|
||||||
export { pve1Endpoint, pve1ApiToken, pve2Endpoint, pve2ApiToken };
|
|
||||||
|
|
||||||
//k3s instance ips consumed by k8s-bootstrap.
|
|
||||||
export { master1Ip, master2Ip, worker1Ip, master3Ip, worker2Ip };
|
|
||||||
Generated
-2722
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user