Add common script.

This commit is contained in:
Jagrit Thapar 2024-07-09 15:15:00 +05:30
commit 1b742bbcaa
1 changed files with 62 additions and 0 deletions

62
scripts/0-common.sh Normal file
View File

@ -0,0 +1,62 @@
#!/bin/bash
cat << "EOF"
_ _ _ _
(_) (_) | | | |
_ __ _ __ _ _ __ _ | |_ __| | ___ __ __
| | / _` | / _` | | '__| | | | __| / _` | / _ \ \ \ / /
| | | (_| | | (_| | | | | | | |_ _ | (_| | | __/ \ V /
| | \__,_| \__, | |_| |_| \__| (_) \__,_| \___| \_/
_/ | __/ |
|__/ |___/
Kubernetes Setup Script for All Nodes
EOF
# Set Kubernetes version
# K8S_VERSION="1.30"
sudo mkdir -p /etc/apt/keyrings
# Update package index and install dependencies
sudo apt-get update -y
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg lsb-release
# Disable swap
sudo swapoff -a
sudo sed -i '/ swap / s/^/#/' /etc/fstab
# Configure kernel parameters
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF
sudo modprobe overlay
sudo modprobe br_netfilter
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
EOF
sudo sysctl --system
# Add Kubernetes apt repository
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
sudo chmod 644 /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.30/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo chmod 644 /etc/apt/sources.list.d/kubernetes.list
# Install kubeadm, kubelet, and kubectl
sudo apt-get update -y
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-get update -y
sudo apt-mark hold kubelet kubeadm kubectl