22set -e
33
44# Set hostname
5- echo " -------------Setting Hostname -------------"
6- hostnamectl set-hostname " $1 "
5+ echo " -------------Setting hostname -------------"
6+ hostnamectl set-hostname $1
77
8- # Disable Swap
9- echo " -------------Disabling Swap -------------"
8+ # Disable swap
9+ echo " -------------Disabling swap -------------"
1010swapoff -a
1111sed -i ' / swap / s/^\(.*\)$/#\1/g' /etc/fstab
1212
13- # Install Dependencies
14- echo " -------------Installing Required Packages-------------"
15- apt-get update -y
16- apt-get install -y curl wget gpg apt-transport-https ca-certificates
17-
18- # Enable IP forward
19- grep -qxF ' net.ipv4.ip_forward = 1' /etc/sysctl.conf || echo ' net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf
20- sysctl -p
21-
22- # Download and extract containerd
23- CONTAINERD_VERSION=" 1.7.4"
24- CONTAINERD_TARBALL=" containerd-${CONTAINERD_VERSION} -linux-amd64.tar.gz"
25-
26- if [ ! -f " /usr/local/bin/containerd" ]; then
27- wget https://github.com/containerd/containerd/releases/download/v${CONTAINERD_VERSION} /${CONTAINERD_TARBALL}
28- tar -C /usr/local -xzf ${CONTAINERD_TARBALL}
29- rm -f ${CONTAINERD_TARBALL}
30- else
31- echo " Containerd already installed, skipping..."
32- fi
33-
34- # Install containerd service file from the correct version
35- wget https://raw.githubusercontent.com/containerd/containerd/v${CONTAINERD_VERSION} /containerd.service
13+ # Install Containerd
14+ echo " -------------Installing Containerd-------------"
15+ wget https://github.com/containerd/containerd/releases/download/v1.7.4/containerd-1.7.4-linux-amd64.tar.gz
16+ tar Cxzvf /usr/local containerd-1.7.4-linux-amd64.tar.gz
17+ wget https://raw.githubusercontent.com/containerd/containerd/main/containerd.service
3618mkdir -p /usr/local/lib/systemd/system
3719mv containerd.service /usr/local/lib/systemd/system/containerd.service
3820systemctl daemon-reload
39-
40- mkdir -p /etc/containerd
41- containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
42- sed -i ' s/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
43-
4421systemctl enable --now containerd
45- systemctl restart containerd
4622
47- # Install runc
48- wget https://github.com/opencontainers/runc/releases/download/v1.2.3/runc.amd64
23+ # Install Runc
24+ echo " -------------Installing Runc-------------"
25+ wget https://github.com/opencontainers/runc/releases/download/v1.1.9/runc.amd64
4926install -m 755 runc.amd64 /usr/local/sbin/runc
50- rm -f runc.amd64
51-
52- echo " -------------Installing CNI Plugins-------------"
53-
54- # Define variables
55- CNI_VERSION=" 1.6.2"
56- CNI_TARBALL=" cni-plugins-linux-amd64-v${CNI_VERSION} .tgz"
57- CNI_DIR=" /opt/cni/bin"
58-
59- mkdir -p ${CNI_DIR}
60- echo " Downloading CNI plugins..."
61- curl -O -L https://github.com/containernetworking/plugins/releases/download/v${CNI_VERSION} /${CNI_TARBALL}
62- tar Cxzvf ${CNI_DIR} ${CNI_TARBALL}
63- rm -f ${CNI_TARBALL}
64- echo " CNI plugins installed successfully!"
65-
66- # Create the directory with proper permissions (if not already exists)
67- sudo mkdir -p -m 755 /etc/apt/keyrings
68-
69- # Check if the key file already exists
70- if [ ! -f /etc/apt/keyrings/kubernetes-apt-keyring.gpg ]; then
71- # Download the key if it doesn't exist
72- curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.30/deb/Release.key | gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg
73- # Add the Kubernetes repository to the sources list
74- 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
75- fi
76-
77- apt-get update -y
78- apt-get install -y kubelet kubeadm kubectl
79- apt-mark hold kubelet kubeadm kubectl
80-
81- # Run kubeadm init
82- kubeadm init --pod-network-cidr=192.168.0.0/16
8327
84- # Set up kubeconfig for the ubuntu user (or your specific user)
85- mkdir -p $HOME /.kube
86- cp -i /etc/kubernetes/admin.conf $HOME /.kube/config
87- chown $( id -u) :$( id -g) $HOME /.kube/config
28+ # Install CNI
29+ echo " -------------Installing CNI-------------"
30+ wget https://github.com/containernetworking/plugins/releases/download/v1.2.0/cni-plugins-linux-amd64-v1.2.0.tgz
31+ mkdir -p /opt/cni/bin
32+ tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.2.0.tgz
33+
34+ # Install CRICTL
35+ echo " -------------Installing CRICTL-------------"
36+ VERSION=" v1.28.0" # check latest version in /releases page
37+ wget https://github.com/kubernetes-sigs/cri-tools/releases/download/$VERSION /crictl-$VERSION -linux-amd64.tar.gz
38+ tar zxvf crictl-$VERSION -linux-amd64.tar.gz -C /usr/local/bin
39+ rm -f crictl-$VERSION -linux-amd64.tar.gz
40+
41+ cat << EOF | sudo tee /etc/crictl.yaml
42+ runtime-endpoint: unix:///run/containerd/containerd.sock
43+ image-endpoint: unix:///run/containerd/containerd.sock
44+ timeout: 2
45+ debug: false
46+ pull-image-on-create: false
47+ EOF
48+
49+ # Forwarding IPv4 and letting iptables see bridged traffic
50+ echo " -------------Setting IPTables-------------"
51+ cat << EOF | sudo tee /etc/modules-load.d/k8s.conf
52+ overlay
53+ br_netfilter
54+
55+ EOF
56+ modprobe overlay
57+ modprobe br_netfilter
58+ cat << EOF | sudo tee /etc/sysctl.d/k8s.conf
59+ net.bridge.bridge-nf-call-iptables = 1
60+ net.bridge.bridge-nf-call-ip6tables = 1
61+ net.ipv4.ip_forward = 1
62+ EOF
63+
64+ sysctl --system
65+ sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables net.ipv4.ip_forward
66+ modprobe br_netfilter
67+ sysctl -p /etc/sysctl.conf
68+
69+ # Install kubectl, kubelet and kubeadm
70+ echo " -------------Installing Kubectl, Kubelet and Kubeadm-------------"
71+ apt-get update && sudo apt-get install -y apt-transport-https curl
72+ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
73+
74+ cat << EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
75+ deb https://apt.kubernetes.io/ kubernetes-xenial main
76+ EOF
77+
78+ apt update -y
79+ apt install -y kubelet kubeadm kubectl
80+ apt-mark hold kubelet kubeadm kubectl
8881
89- kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
82+ echo " -------------Printing Kubeadm version-------------"
83+ kubeadm version
9084
91- echo " Kubernetes initialization complete!"
85+ echo " -------------Pulling Kueadm Images -------------"
86+ kubeadm config images pull
9287
93- # Check if the join-command.sh file already exists
94- if [ ! -f /home/ubuntu/join-command.sh ]; then
95- echo " Creating join command file..."
88+ echo " -------------Running kubeadm init-------------"
89+ kubeadm init
9690
97- # Create a new token and print the join command
98- kubeadm token create --print-join-command > /home/ubuntu/join-command.sh
99-
100- # Make the script executable
101- chmod +x /home/ubuntu/join-command.sh
91+ echo " -------------Copying Kubeconfig-------------"
92+ mkdir -p /root/.kube
93+ cp -iv /etc/kubernetes/admin.conf /root/.kube/config
94+ sudo chown $( id -u) :$( id -g) /root/.kube/config
10295
103- echo " Join command created and file made executable."
104- else
105- echo " Join command file already exists, skipping creation."
106- fi
96+ echo " -------------Exporting Kubeconfig-------------"
97+ export KUBECONFIG=/etc/kubernetes/admin.conf
10798
108- kubeadm version
109- kubectl version
99+ echo " -------------Deploying Weavenet Pod Networking------------- "
100+ kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml
110101
102+ echo " -------------Creating file with join command-------------"
103+ kubeadm token create --print-join-command > /home/ubuntu/join-command.sh
104+ chmod +x /home/ubuntu/join-command.sh
0 commit comments