Skip to content

Instantly share code, notes, and snippets.

@tangingw
Created February 25, 2022 10:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tangingw/5dcc276582023014cf5c7b45461b4300 to your computer and use it in GitHub Desktop.
Save tangingw/5dcc276582023014cf5c7b45461b4300 to your computer and use it in GitHub Desktop.
# Create Static Ip on master and worker's nodes
1. sudo nano /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
2. Enter in /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
network: {config: disabled}
3. sudo nano /etc/netplan/01-netcfg.yaml
4. Enter in /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
ens33: # Your network interface name
dhcp4: no
addresses:
- 192.168.121.221/24 # Static Ip that you want to set
gateway4: 192.168.121.1 # Your IP gateway
nameservers:
addresses: [8.8.8.8, 1.1.1.1] # List of nameservers
5. Off the swap
sudo swapoff -a
6. Comment the swap in /etc/fstab
# Installation on all the nodes
7. Follow the Installation steps below
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add
sudo apt-add-repository 'deb http://apt.kubernetes.io/ kubernetes-xenial main'
sudo apt-get update && sudo apt-get install -y kubelet=1.20.0-00 kubeadm=1.20.0-00 kubectl=1.20.0-00 docker.io
or
sudo apt-get update && sudo apt-get install -y kubelet=1.22.4-00 kubeadm=1.22.4-00 kubectl=1.22.4-00 docker.io
# Before you start the docker service, please add the json below to /etc/docker/daemon.json. Create the file if it doesn't exist
vi /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
This is to ensure that kubeadm runs with the same cgroups driver as docker
8. Start the docker service
sudo systemctl start docker && sudo systemctl enable docker
# Control Plane Installation
9. Start the control plane
sudo kubeadm init --apiserver-advertise-address 192.168.0.82 --pod-network-cidr=172.16.0.0/16
note: pod-network-cidr -> please follow your docker's cidr. For that please check your docker0
note: please set your apiserver-advertise-address to master node's ip address
10. Once this is done please do the step below
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
11. Save your token and kubeadm join command that shows at the end of the output in this format
kubeadm join 192.168.0.82:6443 --token vois8r.3wx957459ooxm2dq \
--discovery-token-ca-cert-hash sha256:5f1896c485802502f8059fae06b2688ef6771ec53cc2e5bd1a6dc433eaccd4bc
note: The token is important for your worker's node to join master node
12. Install a pod network to the cluster using calico
curl https://projectcalico.docs.tigera.io/manifests/calico.yaml -O
kubectl apply -f calico.yaml
# Worker's node
1. Make sure that you have
a. swap is Off
b. docker's cgroupdriver is systemd
2. Run the following command
kubeadm join 192.168.0.82:6443 --token vois8r.3wx957459ooxm2dq \
--discovery-token-ca-cert-hash sha256:5f1896c485802502f8059fae06b2688ef6771ec53cc2e5bd1a6dc433eaccd4bc
3. If the worker's node join successfully, it will show:
This node has joined the cluster:
* Certificate signing request was sent to apiserver and a response was received.
* The Kubelet was informed of the new secure connection details.
4. Wait for a good 2 minutes, check the status of the nodes
kubectl get nodes
5. You will see the status Ready for all the nodes
NAME STATUS ROLES AGE VERSION
k8s-2 Ready <none> 8m19s v1.23.4
k8s-3 Ready <none> 32s v1.23.4
k8s-cluster Ready control-plane,master 16m v1.23.4
#Reference
a. https://github.com/justmeandopensource/kubernetes/blob/master/docs/install-cluster-ubuntu-20.md
b. https://www.digitalocean.com/community/tutorials/how-to-create-a-kubernetes-cluster-using-kubeadm-on-ubuntu-20-04
c. https://computingforgeeks.com/deploy-kubernetes-cluster-on-ubuntu-with-kubeadm/
d. https://linuxconfig.org/how-to-install-kubernetes-on-ubuntu-20-04-focal-fossa-linux
e. https://stackoverflow.com/questions/54728254/kubernetes-kubeadm-init-fails-due-to-dial-tcp-127-0-0-110248-connect-connecti
f. https://kubernetes.io/docs/tasks/administer-cluster/kubeadm/configure-cgroup-driver/
g. https://projectcalico.docs.tigera.io/getting-started/kubernetes/self-managed-onprem/onpremises
h. https://www.learnitguide.net/2021/12/install-kubernetes-cluster-on-ubuntu-20.html
i. https://linuxize.com/post/how-to-configure-static-ip-address-on-ubuntu-20-04/
j. https://kubernetes.io/docs/concepts/cluster-administration/addons/
k. https://www.devopsschool.com/blog/how-to-change-the-cgroup-driver-from-cgroupfs-systemd-in-docker/
l. https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-20-04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment