Unverified Commit 06d5f01f authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Add initial setup & configure-node script

parents
Loading
Loading
Loading
Loading

.gitignore

0 → 100644
+1 −0
Original line number Diff line number Diff line
charts/

configure-node

0 → 100755
+72 −0
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 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 ;;
	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 ! 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) 
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

helm.key

0 → 100644
+1.17 KiB

File added.

No diff preview for this file type.

k8s-io.key

0 → 100644
+1.17 KiB

File added.

No diff preview for this file type.

kustomization.yaml

0 → 100644
+10 −0
Original line number Diff line number Diff line
namespace: kube-system

helmCharts:
- name: cilium
  repo: https://helm.cilium.io/
  version: v1.17.4
  valuesInline:
    kubeProxyReplacement: true
    k8sServiceHost: k8s.net.kodo.org.uk
    k8sServicePort: 6443