Loading configure-nodedeleted 100755 → 0 +0 −78 Original line number Diff line number Diff line #!/bin/bash set -eu USAGE="Usage: $0 [-h] [-i INTERFACE] [-d DOMAIN] [-t TOKEN] [-u <control|gateway>] -h|--help Show this usage and exit -i|--interface Use the first address of INTERFACE as a API advertisement address -d|--domain Use DOMAIN as the control plane nodes' shared DNS name -t|--token Join a cluster using TOKEN -u|--use Configure the node for the comma separated uses. Choices out of: control, gateway -f|--first-setup Force running the ./setup script " shopt -s lastpipe source "${SCRIPTS:=$(dirname "$0")}/lib.bash" declare -a packages declare -a kubeadm_args [[ -v USES ]] && split uses "$USES" while let $#; do case $1 in -h|--help) echo "$USAGE"; exit 0 ;; -i|--interface) INTERFACE=$2; shift ;; -d|--domain) API_DOMAIN=$2; shift ;; -t|--token) TOKEN=$2; shift ;; -u|--use) split uses "$2"; shift ;; -f|--first-setup) DO_SETUP=true ;; esac shift done # grep -q memory /proc/cgroups || fatal \ # "Memory cgroup is not enabled; either remove cgroup_disable=memory" \ # "or add cgroup_enable=memory to the kernel cmdline and restart." has jq || packages+=(jq) if [[ -v DO_SETUP ]] || ! has kubeadm || ! has kubectl; then "$SCRIPTS/setup" "${packages[@]}" elif [[ -v packages[0] ]]; then apt-get update apt-get install -y "${packages[@]}" fi if [[ -v INTERFACE ]]; then ip -j -4 addr show "$INTERFACE" | jq -r '.[].addr_info[] | select(.scope == "global") | .local' | readarray -t addresses [[ -v addresses[0] ]] || fatal "No inet address found for $INTERFACE" kubeadm_args+=(--node-ip="${addresses[0]}") fi if [[ ! -v TOKEN ]]; then # --domain/API_DOMAIN provides a DNS name which resolves to all control # plane nodes kubeadm_args+=(--control-plane-endpoint=${API_DOMAIN:=k8s.net.kodo.org.uk}) # We will use Cilium's kube-proxy replacement... kubeadm_args+=(--skip-phases=addon/kube-proxy) # Per node CIDR # https://docs.cilium.io/en/stable/network/kubernetes/requirements/#enable-automatic-node-cidr-allocation-recommended kubeadm_args+=(--pod-network-cidr=10.56.128.0/17) fi if [[ -v TOKEN ]]; then kubeadm join "${API_DOMAIN}" "$TOKEN" "${kubeadm_args[@]}" else kubeadm init "${kubeadm_args[@]}" export KUBECONFIG=/etc/kubernetes/admin.conf kubectl kustomize --enable-helm . | kubectl apply -f- uses+=(control) fi setup +69 −10 Original line number Diff line number Diff line #!/bin/bash set -eu USAGE="Usage: $0 [-h] [-i INTERFACE] [-d DOMAIN] [-t TOKEN] [-u <control|gateway>] -h|--help Show this usage and exit -i|--interface Use the first address of INTERFACE as a API advertisement address -d|--domain Use DOMAIN as the control plane nodes' shared DNS name -t|--token Join a cluster using TOKEN -u|--use Configure the node for the comma separated uses. Choices out of: control, gateway " shopt -s lastpipe source "${SCRIPTS:=$(dirname "$0")}/lib.bash" declare -a packages=("$@") declare -a packages declare -a kubeadm_args [[ $(id -u) -eq 0 ]] || fatal "Must be run as root" has containerd || packages+=(containerd) has helm || packages+=(helm) has kubeadm || packages+=(kubeadm) has kubectl || packages+=(kubectl) has kubelet || packages+=(kubelet) [[ -v USES ]] && split uses "$USES" while let $#; do case $1 in -h|--help) echo "$USAGE"; exit 0 ;; -i|--interface) INTERFACE=$2; shift ;; -d|--domain) API_DOMAIN=$2; shift ;; -t|--token) TOKEN=$2; shift ;; -u|--use) split uses "$2"; shift ;; esac shift done # Disable swap if has dphys-swapfile; then Loading @@ -23,21 +45,58 @@ else sleep 5 fi # grep -q memory /proc/cgroups || fatal \ # "Memory cgroup is not enabled; either remove cgroup_disable=memory" \ # "or add cgroup_enable=memory to the kernel cmdline and restart." has jq || packages+=(jq) has containerd || packages+=(containerd) has helm || packages+=(helm) has kubeadm || packages+=(kubeadm) has kubectl || packages+=(kubectl) has kubelet || packages+=(kubelet) add_repo k8s-io k8s-io.key 'https://pkgs.k8s.io/core:/stable:/v1.33/deb/' / add_repo helm helm.key 'https://baltocdn.com/helm/stable/debian/' all main apt-get update apt-get upgrade [[ -v packages[0] ]] && apt-get install -y "${packages[@]}" systemctl enable --now kubelet.service install --mode=0644 "$SCRIPTS/containerd.toml" /etc/containerd/config.toml systemctl restart containerd.service systemctl enable --now kubelet.service tee /etc/sysctl.d/k8s.conf <<-END net.ipv4.ip_forward = 1 END sysctl --system # Note: Debian or Ubuntu images required for RPi4, not Raspbian # https://github.com/envoyproxy/envoy/issues/23339 if [[ -v INTERFACE ]]; then ip -j -4 addr show "$INTERFACE" | jq -r '.[].addr_info[] | select(.scope == "global") | .local' | readarray -t addresses [[ -v addresses[0] ]] || fatal "No inet address found for $INTERFACE" kubeadm_args+=(--node-ip="${addresses[0]}") fi if [[ ! -v TOKEN ]]; then # --domain/API_DOMAIN provides a DNS name which resolves to all control # plane nodes kubeadm_args+=(--control-plane-endpoint=${API_DOMAIN:=k8s.net.kodo.org.uk}) # We will use Cilium's kube-proxy replacement... kubeadm_args+=(--skip-phases=addon/kube-proxy) # Per node CIDR # https://docs.cilium.io/en/stable/network/kubernetes/requirements/#enable-automatic-node-cidr-allocation-recommended kubeadm_args+=(--pod-network-cidr=10.56.128.0/17) fi if [[ -v TOKEN ]]; then kubeadm join "${API_DOMAIN}" "$TOKEN" "${kubeadm_args[@]}" else kubeadm init "${kubeadm_args[@]}" export KUBECONFIG=/etc/kubernetes/admin.conf kubectl kustomize --enable-helm . | kubectl apply -f- uses+=(control) fi Loading
configure-nodedeleted 100755 → 0 +0 −78 Original line number Diff line number Diff line #!/bin/bash set -eu USAGE="Usage: $0 [-h] [-i INTERFACE] [-d DOMAIN] [-t TOKEN] [-u <control|gateway>] -h|--help Show this usage and exit -i|--interface Use the first address of INTERFACE as a API advertisement address -d|--domain Use DOMAIN as the control plane nodes' shared DNS name -t|--token Join a cluster using TOKEN -u|--use Configure the node for the comma separated uses. Choices out of: control, gateway -f|--first-setup Force running the ./setup script " shopt -s lastpipe source "${SCRIPTS:=$(dirname "$0")}/lib.bash" declare -a packages declare -a kubeadm_args [[ -v USES ]] && split uses "$USES" while let $#; do case $1 in -h|--help) echo "$USAGE"; exit 0 ;; -i|--interface) INTERFACE=$2; shift ;; -d|--domain) API_DOMAIN=$2; shift ;; -t|--token) TOKEN=$2; shift ;; -u|--use) split uses "$2"; shift ;; -f|--first-setup) DO_SETUP=true ;; esac shift done # grep -q memory /proc/cgroups || fatal \ # "Memory cgroup is not enabled; either remove cgroup_disable=memory" \ # "or add cgroup_enable=memory to the kernel cmdline and restart." has jq || packages+=(jq) if [[ -v DO_SETUP ]] || ! has kubeadm || ! has kubectl; then "$SCRIPTS/setup" "${packages[@]}" elif [[ -v packages[0] ]]; then apt-get update apt-get install -y "${packages[@]}" fi if [[ -v INTERFACE ]]; then ip -j -4 addr show "$INTERFACE" | jq -r '.[].addr_info[] | select(.scope == "global") | .local' | readarray -t addresses [[ -v addresses[0] ]] || fatal "No inet address found for $INTERFACE" kubeadm_args+=(--node-ip="${addresses[0]}") fi if [[ ! -v TOKEN ]]; then # --domain/API_DOMAIN provides a DNS name which resolves to all control # plane nodes kubeadm_args+=(--control-plane-endpoint=${API_DOMAIN:=k8s.net.kodo.org.uk}) # We will use Cilium's kube-proxy replacement... kubeadm_args+=(--skip-phases=addon/kube-proxy) # Per node CIDR # https://docs.cilium.io/en/stable/network/kubernetes/requirements/#enable-automatic-node-cidr-allocation-recommended kubeadm_args+=(--pod-network-cidr=10.56.128.0/17) fi if [[ -v TOKEN ]]; then kubeadm join "${API_DOMAIN}" "$TOKEN" "${kubeadm_args[@]}" else kubeadm init "${kubeadm_args[@]}" export KUBECONFIG=/etc/kubernetes/admin.conf kubectl kustomize --enable-helm . | kubectl apply -f- uses+=(control) fi
setup +69 −10 Original line number Diff line number Diff line #!/bin/bash set -eu USAGE="Usage: $0 [-h] [-i INTERFACE] [-d DOMAIN] [-t TOKEN] [-u <control|gateway>] -h|--help Show this usage and exit -i|--interface Use the first address of INTERFACE as a API advertisement address -d|--domain Use DOMAIN as the control plane nodes' shared DNS name -t|--token Join a cluster using TOKEN -u|--use Configure the node for the comma separated uses. Choices out of: control, gateway " shopt -s lastpipe source "${SCRIPTS:=$(dirname "$0")}/lib.bash" declare -a packages=("$@") declare -a packages declare -a kubeadm_args [[ $(id -u) -eq 0 ]] || fatal "Must be run as root" has containerd || packages+=(containerd) has helm || packages+=(helm) has kubeadm || packages+=(kubeadm) has kubectl || packages+=(kubectl) has kubelet || packages+=(kubelet) [[ -v USES ]] && split uses "$USES" while let $#; do case $1 in -h|--help) echo "$USAGE"; exit 0 ;; -i|--interface) INTERFACE=$2; shift ;; -d|--domain) API_DOMAIN=$2; shift ;; -t|--token) TOKEN=$2; shift ;; -u|--use) split uses "$2"; shift ;; esac shift done # Disable swap if has dphys-swapfile; then Loading @@ -23,21 +45,58 @@ else sleep 5 fi # grep -q memory /proc/cgroups || fatal \ # "Memory cgroup is not enabled; either remove cgroup_disable=memory" \ # "or add cgroup_enable=memory to the kernel cmdline and restart." has jq || packages+=(jq) has containerd || packages+=(containerd) has helm || packages+=(helm) has kubeadm || packages+=(kubeadm) has kubectl || packages+=(kubectl) has kubelet || packages+=(kubelet) add_repo k8s-io k8s-io.key 'https://pkgs.k8s.io/core:/stable:/v1.33/deb/' / add_repo helm helm.key 'https://baltocdn.com/helm/stable/debian/' all main apt-get update apt-get upgrade [[ -v packages[0] ]] && apt-get install -y "${packages[@]}" systemctl enable --now kubelet.service install --mode=0644 "$SCRIPTS/containerd.toml" /etc/containerd/config.toml systemctl restart containerd.service systemctl enable --now kubelet.service tee /etc/sysctl.d/k8s.conf <<-END net.ipv4.ip_forward = 1 END sysctl --system # Note: Debian or Ubuntu images required for RPi4, not Raspbian # https://github.com/envoyproxy/envoy/issues/23339 if [[ -v INTERFACE ]]; then ip -j -4 addr show "$INTERFACE" | jq -r '.[].addr_info[] | select(.scope == "global") | .local' | readarray -t addresses [[ -v addresses[0] ]] || fatal "No inet address found for $INTERFACE" kubeadm_args+=(--node-ip="${addresses[0]}") fi if [[ ! -v TOKEN ]]; then # --domain/API_DOMAIN provides a DNS name which resolves to all control # plane nodes kubeadm_args+=(--control-plane-endpoint=${API_DOMAIN:=k8s.net.kodo.org.uk}) # We will use Cilium's kube-proxy replacement... kubeadm_args+=(--skip-phases=addon/kube-proxy) # Per node CIDR # https://docs.cilium.io/en/stable/network/kubernetes/requirements/#enable-automatic-node-cidr-allocation-recommended kubeadm_args+=(--pod-network-cidr=10.56.128.0/17) fi if [[ -v TOKEN ]]; then kubeadm join "${API_DOMAIN}" "$TOKEN" "${kubeadm_args[@]}" else kubeadm init "${kubeadm_args[@]}" export KUBECONFIG=/etc/kubernetes/admin.conf kubectl kustomize --enable-helm . | kubectl apply -f- uses+=(control) fi