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.

Revisions

  1. pagottoo revised this gist May 19, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion r8pi-provision-node.sh
    Original file line number Diff line number Diff line change
    @@ -81,4 +81,4 @@ echo cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 net.ifnames=0 dwc
    echo "Applying sysctl"
    sysctl --system

    echo "NODE_PROVISIONED=true" | tee -a $LOGFILE
    echo "NODE_PROVISIONED=true" >> /etc/provisioning_phase;
  2. pagottoo revised this gist May 19, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions r8pi-provision-node.sh
    Original file line number Diff line number Diff line change
    @@ -80,3 +80,5 @@ echo cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 net.ifnames=0 dwc

    echo "Applying sysctl"
    sysctl --system

    echo "NODE_PROVISIONED=true" | tee -a $LOGFILE
  3. pagottoo revised this gist May 19, 2024. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions r8pi-provision-node.sh
    Original file line number Diff line number Diff line change
    @@ -80,6 +80,3 @@ echo cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 net.ifnames=0 dwc

    echo "Applying sysctl"
    sysctl --system

    echo "Rebooting by provision-node.sh"
    reboot now
  4. pagottoo revised this gist May 19, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions r8pi-provision-node.sh
    Original file line number Diff line number Diff line change
    @@ -80,3 +80,6 @@ echo cgroup_enable=cpuset cgroup_enable=memory cgroup_memory=1 net.ifnames=0 dwc

    echo "Applying sysctl"
    sysctl --system

    echo "Rebooting by provision-node.sh"
    reboot now
  5. pagottoo revised this gist May 19, 2024. 1 changed file with 74 additions and 6 deletions.
    80 changes: 74 additions & 6 deletions r8pi-provision-node.sh
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,81 @@
    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 "Running step 1: Updating packages" | tee -a $LOGFILE
    sudo apt-get update | tee -a $LOGFILE
    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 "Running step 2: Installing dependencies" | tee -a $LOGFILE
    sudo apt-get install -y some-package | tee -a $LOGFILE
    echo "Apt update"
    apt update # && apt-get upgrade -y

    # Other steps will come here...
    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 "Provisioning script completed." | tee -a $LOGFILE
    # 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
  6. pagottoo revised this gist May 19, 2024. 2 changed files with 6 additions and 2 deletions.
    4 changes: 3 additions & 1 deletion controlplane-init.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,4 @@
    #!/bin/bash
    LOGFILE=/var/log/controlplane-init.log
    LOGFILE=/var/log/controlplane-init.log

    echo "Starting controlplane-init script..." | tee -a $LOGFILE
    4 changes: 3 additions & 1 deletion node-join.sh
    Original file line number Diff line number Diff line change
    @@ -1,2 +1,4 @@
    #!/bin/bash
    LOGFILE=/var/log/node-join.log
    LOGFILE=/var/log/node-join.log

    echo "Starting node-join script..." | tee -a $LOGFILE
  7. pagottoo revised this gist May 19, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions node-join.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    #!/bin/bash
    LOGFILE=/var/log/node-join.log
  8. pagottoo revised this gist May 19, 2024. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions controlplane-init.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    #!/bin/bash
    LOGFILE=/var/log/controlplane-init.log
  9. pagottoo created this gist May 19, 2024.
    14 changes: 14 additions & 0 deletions r8pi-provision-node.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/bin/bash
    LOGFILE=/var/log/provision.log

    echo "Starting provisioning script..." | tee -a $LOGFILE

    echo "Running step 1: Updating packages" | tee -a $LOGFILE
    sudo apt-get update | tee -a $LOGFILE

    echo "Running step 2: Installing dependencies" | tee -a $LOGFILE
    sudo apt-get install -y some-package | tee -a $LOGFILE

    # Other steps will come here...

    echo "Provisioning script completed." | tee -a $LOGFILE