fix: harden K3s and kubeadm installers and sync with DevOps-Security - #116
Merged
Merged
Conversation
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.
Stensel8
force-pushed
the
fix/kubernetes-installers
branch
from
September 17, 2026 07:10
4c82d2c to
f6a747a
Compare
Contributor
There was a problem hiding this comment.
🟡 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_CIDRis passed tokubeadm init, but the downloaded Flannel manifest still contains Flannel's fixed default network (10.244.0.0/16). If an operator setsPOD_CIDRto 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.
| @@ -178,6 +210,12 @@ Install-Worker() { | |||
| [[ "$url" == https://* ]] || url="https://${url}:6443" | |||
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'." |
| 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 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 |
- 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the K3s installer after testing on two AWS EC2 nodes, and brings
k8s_installer.shup 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 nodesasubuntuon the control plane failed withpermission denied, because/etc/rancher/k3s/k3s.yamlis root-only.kubectlfalls back tolocalhost:8080, and the script did not explain that.K3s (
kubernetes/k3s_installer.sh)--write-kubeconfig-mode 0640 --write-kubeconfig-group <group of the sudo user>, sokubectlworks without sudo. The kubeconfig stays unreadable for other users.https://<cp>:6443/pingbefore installing, and fails with a security group hint if the check fails.client-kubelet.crt, which only exists after the server accepts the token.$0. Firewall hint lists TCP 6443, TCP 10250 and UDP 8472.kubeadm (
kubernetes/k8s_installer.sh)--control-plane/--worker --url --token --ca-cert-hash./livezbefore any node prep. The token is not printed or logged by the script.kubelet/kubeadm/kubectlare pinned toK8S_VERSION(1.37.0-*), and Flannel is pinned toFLANNEL_VERSION.SystemdCgroup = truewas actually set, waits for the node to be Ready, and sets up a kubeconfig for root and the sudo user.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
fix: correct nmcli command)*.md) and NL (*.nl.md) versions updated (n/a, nosrc/content/changes)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-*selects1.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.