Skip to content

Instantly share code, notes, and snippets.

@pagottoo
Last active May 19, 2024 17:33
Show Gist options
  • Save pagottoo/09d0d164510a33443d4357d29f717c8b to your computer and use it in GitHub Desktop.
Save pagottoo/09d0d164510a33443d4357d29f717c8b to your computer and use it in GitHub Desktop.
This Gist contains a provisioning script (provision.sh) designed for an Ubuntu Server running on a Raspberry Pi. The script is intended to be used with cloud-init to automate the initial setup and configuration of the server.
#!/bin/bash
LOGFILE=/var/log/controlplane-init.log
echo "Starting controlplane-init script..." | tee -a $LOGFILE
#!/bin/bash
LOGFILE=/var/log/node-join.log
echo "Starting node-join script..." | tee -a $LOGFILE
#!/bin/bash
LOGFILE=/var/log/provision.log
echo "Starting provisioning script..." | tee -a $LOGFILE
echo "Adding Containerd repository"
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list
echo "Adding k8s repository"
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --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/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
echo "Apt update"
apt update # && apt-get upgrade -y
echo "Apt install packages"
apt -y install apt-utils apt-transport-https ca-certificates gnupg-agent software-properties-common jq socat python3-software-properties conntrack nfs-common ebtables ethtool kubelet=1.29.5-1.1 kubeadm=1.29.5-1.1 kubectl=1.29.5-1.1 containerd.io
apt-mark hold kubelet kubeadm kubectl
# echo "Installing extra modules rasp"
# apt install -y linux-modules-extra-raspi
#download nerdctl
echo "Downloading nerdctl"
wget -q -c https://github.com/containerd/nerdctl/releases/download/v1.7.6/nerdctl-1.7.6-linux-arm64.tar.gz -O - | tar -zx -C /tmp
mv /tmp/nerdctl /usr/local/bin
#download cilium
echo "Downloading cilium"
CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/master/stable.txt)
CLI_ARCH=amd64
if [ "$(uname -m)" = "aarch64" ]; then CLI_ARCH=arm64; fi
curl -L --fail --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
sha256sum --check cilium-linux-${CLI_ARCH}.tar.gz.sha256sum
sudo tar xzvfC cilium-linux-${CLI_ARCH}.tar.gz /usr/local/bin
rm cilium-linux-${CLI_ARCH}.tar.gz{,.sha256sum}
# Load modules
cat <<EOF | tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
cat <<EOF | tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
# configure containerd
echo "Configuring containerd"
mkdir -p /etc/containerd
containerd config default | tee /etc/containerd/config.toml
sudo sed -i 's/SystemdCgroup \= false/SystemdCgroup \= true/g' /etc/containerd/config.toml
systemctl enable containerd && systemctl restart containerd
# Increase fs.inotify.max_user_{instances,whatches}
echo "Increasing limits"
cat <<EOF | tee /etc/sysctl.d/fs_inotify.conf
fs.inotify.max_user_instances=16384
fs.inotify.max_user_watches=524288
EOF
# Elasticsearch Requirements https://www.elastic.co/guide/en/elasticsearch/reference/current/vm-max-map-count.html
echo vm.max_map_count=262144 > /etc/sysctl.d/max_map_count.conf
# Increase nf_conntrack size
echo net.nf_conntrack_max=786432 > /etc/sysctl.d/nf_conntrack_max.conf
# Increase size of file handles and inode cache
echo fs.file-max=2097152 >> /etc/sysctl.conf
# Disable daily apt unattended updates.
echo 'APT::Periodic::Enable \"0\";' >> /etc/apt/apt.conf.d/10periodic
echo "Configuring cmdline.txt"
rm -rf /boot/firmware/cmdline.txt
echo cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 net.ifnames=0 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait > /boot/firmware/cmdline.txt
echo "Applying sysctl"
sysctl --system
echo "NODE_PROVISIONED=true" >> /etc/provisioning_phase;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment