-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkasu.sh
86 lines (67 loc) · 6.07 KB
/
kasu.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
if [ "$EUID" -ne 0 ]; then
echo "This script must be run as the root user."
exit 1
fi
apt-get install -y curl
mkdir -p /etc/apt/keyrings &&
curl -fsSL https://repo.charm.sh/apt/gpg.key | gpg --batch --yes --dearmor -o /etc/apt/keyrings/charm.gpg &&
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | tee /etc/apt/sources.list.d/charm.list &&
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | gpg --batch --yes --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg &&
echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list &&
apt update && apt upgrade -y &&
apt-get -y install gum
gum style --foreground 255 'Pick the mode'
MODE=$(gum choose "worker" "control-plane")
echo "$MODE deps will be installed"
# assuming you're root
gum spin --spinner line --title "🛜 Turning swap off, setting ip-forwarding on" -- apt-get install -y apt-transport-https ca-certificates
gum spin --spinner line --title "🛜 Turning swap off, setting ip-forwarding on" -- swapoff -a
{ head -n -1 /etc/fstab && tail -n 1 /etc/fstab | sed 's/^/#/'; } > /etc/fstab-temp && mv /etc/fstab-temp /etc/fstab
gum spin --spinner line --title "🛜 Turning swap off, setting ip-forwarding on" -- sysctl net.ipv4.ip_forward=1
gum spin --spinner line --title "🛜 Turning swap off, setting ip-forwarding on" -- sed -i '/#net.ipv4.ip_forward=1/s/^#//' /etc/sysctl.conf
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- wget https://github.com/containerd/containerd/releases/download/v1.7.13/containerd-1.7.13-linux-amd64.tar.gz
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- tar Cxzvf /usr/local containerd-1.7.13-linux-amd64.tar.gz
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- wget https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.amd64
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- install -m 755 runc.amd64 /usr/local/sbin/runc
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- wget https://github.com/containernetworking/plugins/releases/download/v1.4.0/cni-plugins-linux-amd64-v1.4.0.tgz
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- mkdir -p /opt/cni/bin
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.4.0.tgz
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- mkdir /etc/containerd
containerd config default | tee /etc/containerd/config.toml
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- curl -L https://raw.githubusercontent.com/containerd/containerd/main/containerd.service -o /etc/systemd/system/containerd.service
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- systemctl daemon-reload
gum spin --spinner line --title "🚢 Installing containerd-1.7.13 and runc-1.1.12" -- systemctl enable --now containerd
echo "# these first two endpoint setting is where you configure crictl to containerd
runtime-endpoint: unix:///run/containerd/containerd.sock
image-endpoint: unix:///run/containerd/containerd.sock
timeout: 2
debug: true
pull-image-on-create: false" | sudo tee /etc/crictl.yaml
gum spin --spinner line --title "☸️ Installing kubelet kubeadm kubectl, version 1.29" --show-output -- apt-get install -y kubelet kubeadm kubectl;
gum spin --spinner line --title "☸️ Installing kubelet kubeadm kubectl, version 1.29" -- apt-mark hold kubelet kubeadm kubectl;
gum spin --spinner line --title "🐝 Installing cilium" -- modprobe br_netfilter;
gum spin --spinner line --title "🐝 Installing cilium" -- echo "br_netfilter" | sudo tee /etc/modules-load.d/k8s.conf;
gum spin --spinner line --title "🐝 Installing cilium" -- systemctl restart systemd-modules-load;
gum spin --spinner line --title "🐝 Installing cilium" -- wget https://get.helm.sh/helm-v3.14.1-linux-amd64.tar.gz;
gum spin --spinner line --title "🐝 Installing cilium" -- tar -zxvf helm-v3.14.1-linux-amd64.tar.gz;
gum spin --spinner line --title "🐝 Installing cilium" -- mv linux-amd64/helm /usr/local/bin/helm;
gum spin --spinner line --title "🐝 Installing cilium" -- helm repo add cilium https://helm.cilium.io/;
gum spin --spinner line --title "📦 Pulling k8s images" -- kubeadm config images pull
if [ $MODE == "control-plane" ]; then
echo "⚙️ Initialising the control plane"
kubeadm init --skip-phases=addon/kube-proxy # TODO: allow possible VPN IP(s) in front for the TLS cert
gum spin --spinner line --title "✨ Final touches: activating cilium" -- mkdir -p $HOME/.kube
gum spin --spinner line --title "✨ Final touches: activating cilium" -- cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
gum spin --spinner line --title "✨ Final touches: activating cilium" -- chown $(id -u):$(id -g) $HOME/.kube/config
gum spin --spinner line --title "✨ Final touches: activating cilium" -- export KUBECONFIG=/etc/kubernetes/admin.conf
gum spin --spinner line --title "✨ Final touches: activating cilium" -- curl -LO https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz
gum spin --spinner line --title "✨ Final touches: activating cilium" -- sudo tar xzvfC cilium-linux-amd64.tar.gz /usr/local/bin
gum spin --spinner line --title "✨ Final touches: activating cilium" -- rm cilium-linux-amd64.tar.gz
gum spin --spinner line --title "✨ Final touches: activating cilium" -- cilium install
echo "✅ Done! Check it yourself with crictl ps"
elif [ $MODE == "worker" ]; then
JOIN_COMMAND=$(gum input --width 500 --placeholder "copy-paste your 'kubeadm join YOUR_TOKENS_HERE' (as 1 line!!!)")
eval "$JOIN_COMMAND"
fi