Skip to content

fix: harden K3s and kubeadm installers and sync with DevOps-Security - #116

Merged
Stensel8 merged 2 commits into
mainfrom
fix/kubernetes-installers
Sep 17, 2026
Merged

Stensel8 merged 2 commits into
mainfrom
fix/kubernetes-installers

Conversation

@Stensel8

@Stensel8 Stensel8 commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the K3s installer after testing on two AWS EC2 nodes, and brings k8s_installer.sh up to the same level as a kubeadm cluster installer. Both scripts are now byte-identical to their copies in Stensel8/DevOps-Security.

Problems seen on EC2:

  • k3s kubectl get nodes as ubuntu on the control plane failed with permission denied, because /etc/rancher/k3s/k3s.yaml is root-only.
  • The worker printed "joined!" without checking the join. On the worker, kubectl falls back to localhost:8080, and the script did not explain that.

K3s (kubernetes/k3s_installer.sh)

  • Control plane: installs with --write-kubeconfig-mode 0640 --write-kubeconfig-group <group of the sudo user>, so kubectl works without sudo. The kubeconfig stays unreadable for other users.
  • Worker: checks https://<cp>:6443/ping before installing, and fails with a security group hint if the check fails.
  • Worker: waits for client-kubelet.crt, which only exists after the server accepts the token.
  • Script name in help and join hints comes from $0. Firewall hint lists TCP 6443, TCP 10250 and UDP 8472.

kubeadm (kubernetes/k8s_installer.sh)

  • ⚠️ Replaces the kubectl + minikube client installer with a cluster installer: --control-plane / --worker --url --token --ca-cert-hash.
  • Worker checks /livez before any node prep. The token is not printed or logged by the script.
  • kubelet/kubeadm/kubectl are pinned to K8S_VERSION (1.37.0-*), and Flannel is pinned to FLANNEL_VERSION.
  • Checks that SystemdCgroup = true was actually set, waits for the node to be Ready, and sets up a kubeconfig for root and the sudo user.
  • Stops early on a node that already joined a cluster.
  • Ubuntu/Debian only; for other systemd distros, use the K3s installer.

Renovate: the minikube rule becomes a Flannel rule. CONTRIBUTING is updated to match.

Type of change

  • fix — bug fix (broken link, incorrect command, layout issue)

Checklist

  • PR title follows the commit convention (e.g. fix: correct nmcli command)
  • Both EN (*.md) and NL (*.nl.md) versions updated (n/a, no src/content/ changes)
  • No broken internal links
  • Tested locally with cd src && hugo server (n/a, no site changes)

Testing: shellcheck passes on both scripts. In an Ubuntu 24.04 container, apt-get install -s kubelet=1.37.0-* selects 1.37.0-1.1, and the Flannel v0.28.9 manifest URL returns HTTP 200. The fixes have not been re-run end to end on EC2 yet.

Copilot AI lite review requested due to automatic review settings September 17, 2026 07:10
K3s:
- give the sudo user's group read access to the kubeconfig (0640), so
  kubectl works without sudo on the control plane
- worker: check /ping on the API before installing, and wait for the
  kubelet client cert instead of reporting success right away
- explain that kubectl does not work on a worker node

k8s_installer.sh is now a kubeadm cluster installer at the same level as
the K3s one (control plane / worker, --url/--token/--ca-cert-hash,
reachability check, pinned kubeadm/kubelet/kubectl and Flannel, node
Ready wait, kubectl for the sudo user). It replaces the kubectl +
minikube client installer.

Both scripts are byte-identical to kubernetes/install-k3s.sh and
kubernetes/install-k8s.sh in Stensel8/DevOps-Security. Renovate now tracks
Flannel instead of minikube.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical installer failures remain in K3s URL handling and kubeadm readiness validation.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Hardens the K3s and kubeadm installers with validation, pinned dependencies, improved kubeconfig handling, and updated Flannel documentation.

Changes:

  • Converts the kubeadm script into a control-plane/worker cluster installer.
  • Improves K3s connectivity and join validation.
  • Updates Renovate configuration and contributor documentation.
File summaries
File Description
renovate.json Tracks Flannel releases.
kubernetes/k8s_installer.sh Adds kubeadm cluster installation and joining logic.
kubernetes/k3s_installer.sh Improves kubeconfig access and worker validation.
CONTRIBUTING.md Updates dependency-management documentation.
Review details

Suppressed comments (1)

kubernetes/k8s_installer.sh:155

  • POD_CIDR is passed to kubeadm init, but the downloaded Flannel manifest still contains Flannel's fixed default network (10.244.0.0/16). If an operator sets POD_CIDR to another range, pods will be allocated from a range that Flannel does not configure and the cluster will not become functional. Reject non-default values or render/patch the manifest to use the selected CIDR.
POD_CIDR="${POD_CIDR:-10.244.0.0/16}"
FLANNEL_MANIFEST="https://github.com/flannel-io/flannel/releases/download/${FLANNEL_VERSION}/kube-flannel.yml"
  • Files reviewed: 4/4 changed files
  • Comments generated: 4
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread kubernetes/k3s_installer.sh Outdated
@@ -178,6 +210,12 @@ Install-Worker() {
[[ "$url" == https://* ]] || url="https://${url}:6443"
Comment thread kubernetes/k8s_installer.sh Outdated
Comment on lines +266 to +270
for _ in $(seq 1 60); do
kubectl get node 2>/dev/null | grep -q ' Ready ' && break
sleep 2
done
kubectl get node || Write-Log WARN "Node not Ready yet; re-check with 'kubectl get node'."
Comment thread kubernetes/k3s_installer.sh Outdated
echo -e "${BLUE}Use kubectl:${NC} export KUBECONFIG=/etc/rancher/k3s/k3s.yaml # or: k3s kubectl ..."
if [[ -n "$kube_group" ]]; then
echo -e "${BOLD}Use kubectl (as ${kube_user}, no sudo needed)${NC}"
echo -e " kubectl get nodes"
Comment thread kubernetes/k8s_installer.sh Outdated
Comment on lines +164 to +167
if command -v kubeadm &>/dev/null; then
Write-Log WARN "kubeadm already installed ($(kubeadm version -o short 2>/dev/null)); skipping node prep."
return 0
fi
@Stensel8 Stensel8 self-assigned this Sep 17, 2026
- K3s: accept --url HOST:PORT without appending a second :6443
- both: stop when the node is not Ready after 120s instead of printing
  "ready" and join instructions
- K3s: add KUBECONFIG to the kubectl hint when kubectl is not the k3s link
- kubeadm: make node prep idempotent instead of skipping it when kubeadm
  exists (re-applies pinned packages, containerd cgroup driver, fstab)
- kubeadm: patch POD_CIDR into the Flannel manifest and validate it
@Stensel8
Stensel8 merged commit d972fe3 into main Sep 17, 2026
7 checks passed
@Stensel8
Stensel8 deleted the fix/kubernetes-installers branch September 17, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants