From 6f044f86065a4aaf9f9a5128312db9e7bc2a4e64 Mon Sep 17 00:00:00 2001 From: Manju M S <105440084+manjumsgithub@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:03:57 +0530 Subject: [PATCH 1/7] Update master.sh Updated master.sh 08/01/2025 --- scripts/master.sh | 51 +++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/scripts/master.sh b/scripts/master.sh index a48118c..705dd85 100755 --- a/scripts/master.sh +++ b/scripts/master.sh @@ -1,43 +1,50 @@ - #!/bin/bash # # Setup for Control Plane (Master) servers set -euxo pipefail -# If you need public access to API server using the servers Public IP adress, change PUBLIC_IP_ACCESS to true. - +# Configuration PUBLIC_IP_ACCESS="false" NODENAME=$(hostname -s) POD_CIDR="192.168.0.0/16" -# Pull required images +# Validate PUBLIC_IP_ACCESS +if [[ "$PUBLIC_IP_ACCESS" != "true" && "$PUBLIC_IP_ACCESS" != "false" ]]; then + echo "Error: Invalid value for PUBLIC_IP_ACCESS: $PUBLIC_IP_ACCESS" + exit 1 +fi -sudo kubeadm config images pull +# Disable swap +sudo swapoff -a +sudo sed -i '/swap/d' /etc/fstab -# Initialize kubeadm based on PUBLIC_IP_ACCESS +# Pull required images +sudo kubeadm config images pull +# Initialize kubeadm if [[ "$PUBLIC_IP_ACCESS" == "false" ]]; then - - MASTER_PRIVATE_IP=$(ip addr show eth1 | awk '/inet / {print $2}' | cut -d/ -f1) + MASTER_PRIVATE_IP=$(ip route get 8.8.8.8 | awk '{print $7; exit}') sudo kubeadm init --apiserver-advertise-address="$MASTER_PRIVATE_IP" --apiserver-cert-extra-sans="$MASTER_PRIVATE_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap - -elif [[ "$PUBLIC_IP_ACCESS" == "true" ]]; then - - MASTER_PUBLIC_IP=$(curl ifconfig.me && echo "") - sudo kubeadm init --control-plane-endpoint="$MASTER_PUBLIC_IP" --apiserver-cert-extra-sans="$MASTER_PUBLIC_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap - else - echo "Error: MASTER_PUBLIC_IP has an invalid value: $PUBLIC_IP_ACCESS" - exit 1 + MASTER_PUBLIC_IP=$(curl -s ifconfig.me) + sudo kubeadm init --control-plane-endpoint="$MASTER_PUBLIC_IP" --apiserver-cert-extra-sans="$MASTER_PUBLIC_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap fi -# Configure kubeconfig +# Capture the join command +JOIN_COMMAND=$(kubeadm token create --print-join-command) +echo "$JOIN_COMMAND" > join-command.txt +echo "Use the following command to join worker nodes to the cluster:" +cat join-command.txt -mkdir -p "$HOME"/.kube -sudo cp -i /etc/kubernetes/admin.conf "$HOME"/.kube/config -sudo chown "$(id -u)":"$(id -g)" "$HOME"/.kube/config +# Configure kubeconfig +mkdir -p "$HOME/.kube" +sudo cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config" +sudo chown "$(id -u):$(id -g)" "$HOME/.kube/config" -# Install Claico Network Plugin Network +# Wait for the control plane to be ready +kubectl wait --for=condition=Ready node/"$NODENAME" --timeout=300s -kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml +# Install Calico Network Plugin +CALICO_VERSION="v3.26.0" +kubectl apply -f https://docs.projectcalico.org/$CALICO_VERSION/manifests/calico.yaml From 10cd7b08510e58f9c516066777d412135f9beef4 Mon Sep 17 00:00:00 2001 From: Manju M S <105440084+manjumsgithub@users.noreply.github.com> Date: Wed, 8 Jan 2025 08:17:17 +0530 Subject: [PATCH 2/7] Installation Steps updated K8S configuring master and worker nodes --- Installation Steps updated | 99 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Installation Steps updated diff --git a/Installation Steps updated b/Installation Steps updated new file mode 100644 index 0000000..f61c1b8 --- /dev/null +++ b/Installation Steps updated @@ -0,0 +1,99 @@ +K8S INSTALLATION + +1)launch t2 medium ubuntu 22.04 version instance with 2core cpu 4gb ram - For master node only - Give name as k8s-Master +2)launch ubuntu 22.04 version instance with t2 micro only - For worker node- Launch 2 worker nodes - Give name as Worker1 and Worker2 +3)Open All Traffic in Master and worker nodes +4)login as root user in all the three nodes : sudo -i +5)Run this command in all the three nodes + + 1) git clone https://github.com/techiescamp/kubeadm-scripts + 2) cd kubeadm-scripts + 3) cd scripts + 4) Run the script in all the three nodes --- ./common.sh + 5) Run the script in only Master node -- ./master.sh + Before running master file, edit the master file as join key script is missing in it. vi to master file, delete all content and paste the below content: +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- +#!/bin/bash +# +# Setup for Control Plane (Master) servers + +set -euxo pipefail + +# Configuration +PUBLIC_IP_ACCESS="false" +NODENAME=$(hostname -s) +POD_CIDR="192.168.0.0/16" + +# Validate PUBLIC_IP_ACCESS +if [[ "$PUBLIC_IP_ACCESS" != "true" && "$PUBLIC_IP_ACCESS" != "false" ]]; then + echo "Error: Invalid value for PUBLIC_IP_ACCESS: $PUBLIC_IP_ACCESS" + exit 1 +fi + +# Disable swap +sudo swapoff -a +sudo sed -i '/swap/d' /etc/fstab + +# Pull required images +sudo kubeadm config images pull + +# Initialize kubeadm +if [[ "$PUBLIC_IP_ACCESS" == "false" ]]; then + MASTER_PRIVATE_IP=$(ip route get 8.8.8.8 | awk '{print $7; exit}') + sudo kubeadm init --apiserver-advertise-address="$MASTER_PRIVATE_IP" --apiserver-cert-extra-sans="$MASTER_PRIVATE_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap +else + MASTER_PUBLIC_IP=$(curl -s ifconfig.me) + sudo kubeadm init --control-plane-endpoint="$MASTER_PUBLIC_IP" --apiserver-cert-extra-sans="$MASTER_PUBLIC_IP" --pod-network-cidr="$POD_CIDR" --node-name "$NODENAME" --ignore-preflight-errors Swap +fi + +# Capture the join command +JOIN_COMMAND=$(kubeadm token create --print-join-command) +echo "$JOIN_COMMAND" > join-command.txt +echo "Use the following command to join worker nodes to the cluster:" +cat join-command.txt + +# Configure kubeconfig +mkdir -p "$HOME/.kube" +sudo cp -i /etc/kubernetes/admin.conf "$HOME/.kube/config" +sudo chown "$(id -u):$(id -g)" "$HOME/.kube/config" + +# Wait for the control plane to be ready +kubectl wait --for=condition=Ready node/"$NODENAME" --timeout=300s + +# Install Calico Network Plugin +CALICO_VERSION="v3.26.0" +kubectl apply -f https://docs.projectcalico.org/$CALICO_VERSION/manifests/calico.yaml + +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + 6) copy the join key into your notepad + 7) Run this command in master node - kubectl get nodes + 8) paste the join key in two worker node + 9) Run this command in master node - kubectl get nodes - and nodes should be in ready state + + 10) Run this in two of the worker nodes to rename the nodes + kubectl label node node-role.kubernetes.io/worker=worker for both worker nodes ( replace ip adrerss name by running kubectl get nodes command into for both worker nodes ) + + Run all these commands in master node + + 11) Run This command to install network plugins + kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml + + To verify --- kubectl get pods -n kube-system + + + 12) Run This command to install metrics server + kubectl apply -f https://github.com/kubernetes-sigs/metrics- server/releases/latest/download/components.yaml + + 13) Run this command to verify metrics are showing + kubectl get pods -n kube-system + + kubectl top nodes + + 14) Go into to this directory /kubeadm-scripts/manifests and run + cd . + cd /kubeadm-scripts/manifests + kubectl apply -f sample-app.yaml and wait for sometime and run below command + kubectl get pods once pods are in run state access the master public ip address with +-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + + From afacd84410c6b92109979994e4ecc827395dec29 Mon Sep 17 00:00:00 2001 From: Manju M S <105440084+manjumsgithub@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:10:28 +0530 Subject: [PATCH 3/7] Update master.sh on 12/01/2025 --- scripts/master.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/master.sh b/scripts/master.sh index 705dd85..3c3f523 100755 --- a/scripts/master.sh +++ b/scripts/master.sh @@ -47,4 +47,5 @@ kubectl wait --for=condition=Ready node/"$NODENAME" --timeout=300s # Install Calico Network Plugin CALICO_VERSION="v3.26.0" -kubectl apply -f https://docs.projectcalico.org/$CALICO_VERSION/manifests/calico.yaml +kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml + From e5ecc1211794259bd4674c43d22a4759dc82239e Mon Sep 17 00:00:00 2001 From: Manju M S <105440084+manjumsgithub@users.noreply.github.com> Date: Tue, 28 Jan 2025 12:04:57 +0530 Subject: [PATCH 4/7] Update Installation Steps updated --- Installation Steps updated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Installation Steps updated b/Installation Steps updated index f61c1b8..fd24c50 100644 --- a/Installation Steps updated +++ b/Installation Steps updated @@ -3,7 +3,7 @@ K8S INSTALLATION 1)launch t2 medium ubuntu 22.04 version instance with 2core cpu 4gb ram - For master node only - Give name as k8s-Master 2)launch ubuntu 22.04 version instance with t2 micro only - For worker node- Launch 2 worker nodes - Give name as Worker1 and Worker2 3)Open All Traffic in Master and worker nodes -4)login as root user in all the three nodes : sudo -i +4)login as root user in all the three nodes : sudo -i (or) sudo su 5)Run this command in all the three nodes 1) git clone https://github.com/techiescamp/kubeadm-scripts From 43e8e99e820dacfbe43e97debaea368fc35cdd2b Mon Sep 17 00:00:00 2001 From: Manju M S <105440084+manjumsgithub@users.noreply.github.com> Date: Tue, 28 Jan 2025 12:06:18 +0530 Subject: [PATCH 5/7] Update common.sh --- scripts/common.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/common.sh b/scripts/common.sh index 0ee3b1a..5711dda 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -82,3 +82,6 @@ local_ip="$(ip --json addr show eth1 | jq -r '.[0].addr_info[] | select(.family cat > /etc/default/kubelet << EOF KUBELET_EXTRA_ARGS=--node-ip=$local_ip EOF +#copy the key from master node paste it in worker nodes + + From a8b0c46277f1f6acbf7f3b71cef60b48335ef3c5 Mon Sep 17 00:00:00 2001 From: Manju M S <105440084+manjumsgithub@users.noreply.github.com> Date: Tue, 28 Jan 2025 13:24:26 +0530 Subject: [PATCH 6/7] Update Installation Steps updated (28-01-2025) --- Installation Steps updated | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Installation Steps updated b/Installation Steps updated index fd24c50..cf67164 100644 --- a/Installation Steps updated +++ b/Installation Steps updated @@ -2,7 +2,7 @@ K8S INSTALLATION 1)launch t2 medium ubuntu 22.04 version instance with 2core cpu 4gb ram - For master node only - Give name as k8s-Master 2)launch ubuntu 22.04 version instance with t2 micro only - For worker node- Launch 2 worker nodes - Give name as Worker1 and Worker2 -3)Open All Traffic in Master and worker nodes +3)Open All Traffic in Master and worker nodes **(go to security groups allow all traffic and allow alltrafficipv4 in both worker and master nodes)** 4)login as root user in all the three nodes : sudo -i (or) sudo su 5)Run this command in all the three nodes From 88e61666db601539da36691e47790ffbd0a98b08 Mon Sep 17 00:00:00 2001 From: Manju M S <105440084+manjumsgithub@users.noreply.github.com> Date: Sat, 1 Feb 2025 06:47:07 +0530 Subject: [PATCH 7/7] Create youtube video for installation --- youtube video for installation | 1 + 1 file changed, 1 insertion(+) create mode 100644 youtube video for installation diff --git a/youtube video for installation b/youtube video for installation new file mode 100644 index 0000000..c9ea6df --- /dev/null +++ b/youtube video for installation @@ -0,0 +1 @@ +https://www.youtube.com/watch?v=xX52dc3u2HU&t=606s ****YOUTUBE VIDEO FOR DOWNLOADING KUBERENETS ****