commit db19bc72f7fe8b0bdf14857ab033da405b53b5a9541618ea793de6ec7bfc34b6
| author | 斟酌 鵬兄 <tgckpg@gmail.com> |
| date | 2026-03-24T22:29:07Z |
| subject | make cluster-config |
commit db19bc72f7fe8b0bdf14857ab033da405b53b5a9541618ea793de6ec7bfc34b6
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date: 2026-03-24T22:29:07Z
make cluster-config
---
README.md | 7 ++++++-
configs/cluster.env.default | 26 ++++++++++++++++++++++++++
makefile | 22 ++++++++++++++++++----
scripts/merge-env.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 95 insertions(+), 5 deletions(-)
diff --git a/README.md b/README.md
index 6e6b24d..5cad91a 100644
--- a/README.md
+++ b/README.md
@@ -20,12 +20,17 @@ Then run
make release
```
+Then run, follow the instructions
+```
+make cluster-config
+```
+
## Flashing
#### USB Drive
1. `make release`
2. Format the USB in vfat
-3. Copy out/[RELEASE].img.gz and out/board.itb your usb drive's root
+3. Copy out/[RELEASE].img.gz and out/board.itb to your usb drive's root
4. Run
```
usb start
diff --git a/configs/cluster.env.default b/configs/cluster.env.default
new file mode 100644
index 0000000..c326e84
--- /dev/null
+++ b/configs/cluster.env.default
@@ -0,0 +1,26 @@
+# Required
+KUBERNETES_VERSION=v1.35.3
+NODE_NAME=monok8s-master
+APISERVER_ADVERTISE_ADDRESS=192.168.1.50
+
+# Optional but strongly recommended
+CLUSTER_NAME=monok8s
+POD_SUBNET=10.244.0.0/16
+SERVICE_SUBNET=10.96.0.0/12
+CLUSTER_DOMAIN=cluster.local
+
+# Optional
+# Extra API server SANs, comma-separated
+SANS=127.0.0.1,localhost,monok8s-master
+
+# Single-node mode: allow workloads on the control plane
+ALLOW_SCHEDULING_ON_CONTROL_PLANE=yes
+
+# CRI-O socket
+CONTAINER_RUNTIME_ENDPOINT=unix:///var/run/crio/crio.sock
+
+# Usually leave this alone
+KUBECONFIG_USER_HOME=/root
+
+# Emergency override only
+SKIP_IMAGE_CHECK=no
diff --git a/makefile b/makefile
index a6c81f1..01285b6 100644
--- a/makefile
+++ b/makefile
@@ -16,6 +16,11 @@ KUBELET_BIN := $(PACKAGES_DIR)/kubernetes/kubelet
KUBEADM_BIN := $(PACKAGES_DIR)/kubernetes/kubeadm
KUBECTL_BIN := $(PACKAGES_DIR)/kubernetes/kubectl
+CONFIGS_DIR := configs
+SCRIPTS_DIR := scripts
+CLUSTER_ENV_DEFAULT := $(CONFIGS_DIR)/cluster.env.default
+CLUSTER_ENV := $(OUT_DIR)/cluster.env
+
BOARD_ITB := $(OUT_DIR)/board.itb
INITRAMFS := $(OUT_DIR)/initramfs.cpio.gz
RELEASE_IMAGE := $(OUT_DIR)/monok8s-$(TAG).img.gz
@@ -101,9 +106,6 @@ $(KUBEADM_BIN): | $(PACKAGES_DIR)
$(KUBECTL_BIN): | $(PACKAGES_DIR)
curl -L -o $@ "https://dl.k8s.io/$(KUBE_VERSION)/bin/linux/$(ARCH)/kubectl"
-$(KUBEADM_BIN): | $(PACKAGES_DIR)
- curl -L -o $@ "https://dl.k8s.io/$(KUBE_VERSION)/bin/linux/$(ARCH)/kubeadm"
-
$(BUSYBOX_TAR): | $(PACKAGES_DIR)
curl -L -o $@ "https://github.com/mirror/busybox/archive/refs/tags/$(BUSYBOX_VERSION).tar.gz"
@@ -217,6 +219,17 @@ check-functions:
@echo "Missing functions:"
@comm -23 /tmp/called.txt /tmp/defined.txt || true
+# ---- cluster targets ------------------------------------------------------------
+
+cluster-config: $(CLUSTER_ENV_DEFAULT) $(SCRIPTS_DIR)/merge-env.sh | $(OUT_DIR)
+ sh $(SCRIPTS_DIR)/merge-env.sh $(CLUSTER_ENV_DEFAULT) $(CLUSTER_ENV)
+
+cluster-defconfig: $(CLUSTER_ENV_DEFAULT) | $(OUT_DIR)
+ cp $(CLUSTER_ENV_DEFAULT) $(CLUSTER_ENV)
+
+cluster-print:
+ @cat $(CLUSTER_ENV)
+
# ---- User targets ------------------------------------------------------------
release: $(RELEASE_IMAGE)
@@ -240,4 +253,5 @@ distclean: clean
pkgclean:
rm -rf $(PACKAGES_DIR)
-.PHONY: release kernel initramfs itb build-base clean distclean
+.PHONY: release kernel initramfs itb build-base clean distclean pkgclean \
+ cluster-config cluster-defconfig cluster-print
diff --git a/scripts/merge-env.sh b/scripts/merge-env.sh
new file mode 100755
index 0000000..66783e3
--- /dev/null
+++ b/scripts/merge-env.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+set -eu
+
+INPUT="${1:?input file required}"
+OUTPUT="${2:?output file required}"
+
+mkdir -p "$(dirname "$OUTPUT")"
+
+awk '
+function trim(s) {
+ sub(/^[[:space:]]+/, "", s)
+ sub(/[[:space:]]+$/, "", s)
+ return s
+}
+
+BEGIN {
+ for (k in ENVIRON) {
+ env[k] = ENVIRON[k]
+ }
+}
+
+/^[[:space:]]*#/ || /^[[:space:]]*$/ {
+ print
+ next
+}
+
+{
+ line = $0
+ eq = index(line, "=")
+
+ if (eq == 0) {
+ print line
+ next
+ }
+
+ key = trim(substr(line, 1, eq - 1))
+ val = substr(line, eq + 1)
+
+ if (key in env) {
+ print key "=" env[key]
+ } else {
+ print line
+ }
+}
+' "$INPUT" > "$OUTPUT"
\ No newline at end of file