Skip to content

Instantly share code, notes, and snippets.

@febri4n
Last active July 31, 2024 04:01
Show Gist options
  • Save febri4n/4ae9d5c1e4a5fe4506346ba64e145be9 to your computer and use it in GitHub Desktop.
Save febri4n/4ae9d5c1e4a5fe4506346ba64e145be9 to your computer and use it in GitHub Desktop.
Pre-install Kamaji Worker TCP on Openstack Instance
#!/bin/bash
# Log file
LOG="/var/log/k8s_install.log"
echo "Starting Kubernetes components installation at $(date)" | tee -a $LOG
# Load required kernel modules
echo "Loading kernel modules" | tee -a $LOG
cat <<EOF | tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
# Set up required sysctl params
echo "Setting up sysctl params" | tee -a $LOG
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
modprobe overlay
modprobe br_netfilter
sysctl --system
# Install containerd
echo "Installing containerd" | tee -a $LOG
apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | 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 > /dev/null
apt update -y
apt install -y containerd.io
mkdir -p /etc/containerd
containerd config default | tee /etc/containerd/config.toml
sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
sed -i 's/disabled_plugins = \["cri"\]/disabled_plugins = \[""\]/' /etc/containerd/config.toml
systemctl restart containerd
# Install crictl
echo "Installing crictl" | tee -a $LOG
wget https://github.com/kubernetes-sigs/cri-tools/releases/download/v1.27.0/crictl-v1.27.0-linux-amd64.tar.gz
tar zxvf crictl-v1.27.0-linux-amd64.tar.gz -C /usr/local/bin
rm -f crictl-v1.27.0-linux-amd64.tar.gz
cat <<EOF | tee /etc/crictl.yaml
runtime-endpoint: unix:///run/containerd/containerd.sock
EOF
systemctl restart containerd
# Install kubeadm, kubelet, kubectl v1.27
echo "Installing kubeadm, kubelet, kubectl" | tee -a $LOG
apt-get update
apt-get install -y apt-transport-https ca-certificates curl
mkdir -p /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.27/deb/Release.key | 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.27/deb/ /' | tee /etc/apt/sources.list.d/kubernetes.list
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
echo "Kubernetes components installation completed at $(date)" | tee -a $LOG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment