forked from ndiforfusi/kubernetes-kubeadm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kubeadmin.yaml
153 lines (104 loc) · 4.73 KB
/
kubeadmin.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
Installing Oracle Virtual Box
a. Windows OS
i. Microsoft Visual c+++ 2019
https://aka.ms/vs/17/release/vc_redist.x64.exe
ii. Oracle virtual box package
https://download.virtualbox.org/virtualbox/7.1.4/VirtualBox-7.1.4-165100-Win.exe
b. Mac OS
Check your processor model
if Intel host = https://download.virtualbox.org/virtualbox/7.1.4/VirtualBox-7.1.4-165100-OSX.dmg
Silicon apple = https://download.virtualbox.org/virtualbox/7.1.4/VirtualBox-7.1.4-165100-macOSArm64.dmg
Bootstrapping our vms using vagrant
a. Install vagrant
https://developer.hashicorp.com/vagrant/install
b. Clone vagrant script repo
https://github.com/ndiforfusi/kubernetes-kubeadm
cd kubernetes-kubeadm
Run: vagrant up
Here’s a step-by-step guide to building a Kubernetes cluster using kubeadm:
Prerequisites
Nodes:
1 master node and 2 worker nodes.
Minimum 2 GB RAM on the master and 1 GB RAM on each worker node.
Recommended OS: Ubuntu 20.04.
Networking:
Ensure all nodes can communicate with each other over the network.
Disable Swap (on all nodes):
sudo swapoff -a
sudo sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab
Step 1: Install Docker and Containerd
Install Dependencies:
sudo apt-get update -y
sudo apt-get install -y ca-certificates curl
Add Docker’s Official GPG Key:
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo tee /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
Set Up the Docker Repository:
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Install Docker and Containerd:
sudo apt-get update -y
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
Step 2: Configure Sysctl for Kubernetes Networking
Enable IP Forwarding and Configure Bridged Networking:
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
br_netfilter
EOF
sudo modprobe br_netfilter
Set Sysctl Parameters:
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
Step 3: Configure Containerd for Kubernetes
Generate Containerd Configuration:
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml
Edit /etc/containerd/config.toml:
Open the file:
sudo nano /etc/containerd/config.toml
In the [plugins."io.containerd.grpc.v1.cri"] section, ensure the sandbox_image is set and CRI is enabled. It should look like this:
toml
[plugins."io.containerd.grpc.v1.cri"]
sandbox_image = "registry.k8s.io/pause:3.9"
Restart and Enable containerd:
sudo systemctl restart containerd
sudo systemctl enable containerd
Verify CRI with crictl (Optional):
sudo apt-get install -y cri-tools
sudo crictl info
Step 4: Install kubeadm, kubelet, and kubectl
Add Kubernetes GPG Key and Repository:
sudo apt-get update -y
sudo apt-get install -y apt-transport-https ca-certificates curl gpg
sudo mkdir -p -m 755 /etc/apt/keyrings
curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.31/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.31/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
Install Kubernetes Components:
sudo apt-get update -y
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Step 5: Initialize Kubernetes Cluster (Master Node Only)
Initialize the Cluster with kubeadm:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=CRI
Configure kubectl for the Master Node:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Install Flannel Network Plugin:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
This will configure Flannel as the pod network.
Save the Join Command:
After initializing the cluster, kubeadm will display a join command (e.g., kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>).
Copy this command, as it will be used on each worker node to join the cluster.
Step 6: Join Worker Nodes to the Cluster (Worker Nodes Only)
Run the Join Command from Step 5 on each worker node:
sudo kubeadm join <master-ip>:6443 --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Verify the Join Process:
After running the command, each worker node should join the cluster.
Step 7: Verify the Cluster
Check Node Status (on the master node):
kubectl get nodes
You should see both the master and worker nodes listed with their status as Ready.