Skip to content

Instantly share code, notes, and snippets.

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 Tej-Singh-Rana/5c4c0221ef75d80c4ea980f94335c0cb to your computer and use it in GitHub Desktop.
Save Tej-Singh-Rana/5c4c0221ef75d80c4ea980f94335c0cb to your computer and use it in GitHub Desktop.
kubernetes cluster installation from kubeadm-way
##################### Master Node ##################################################
# Set the hostname
$ hostnamectl set-hostname <enter-hostname>
# To get effect in the system without reboot, run the following command:
$ exec bash
# Do entry in the /etc/hosts for master and worker nodes to identify by it's hostname.
e.g. echo "172.16.238.10 master" >> /etc/hosts
echo "172.16.238.11 worker01" >> /etc/hosts
echo "172.16.238.12 worker02" >> /etc/hosts
# You can make it passwordless authentication. Easy to access.
# To check the product_uuid in the machine and should be unique otherwise the installation process can be fail.
# Because kubernetes uses these values to uniquely identify the nodes in the cluster, same terms applicable on MAC address.
# If not available then no issue.
$ sudo cat /sys/class/dmi/id/product_uuid
# To check the IP addr of the current system
$ ip a
# To load bridged Traffic
$ lsmod | grep br_netfilter
# If above result is empty then load it.
$ sudo modprobe br_netfilter
# Enable the kernel bridge traffic
$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
$ sudo sysctl --system
# Status of swap
$ swapon -s
# Disable the swap
$ swapoff -a
# To disable swap permanent go to /etc/fstab, comment it.
# firewall service should be disable
$ systemctl status firewalld
$ systemctl stop firewalld
$ systemctl disable firewalld
# Check the required port is not opt by other services.
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#control-plane-node-s
# Installation Container Runtime
$ apt-get update && apt-get install -y \
apt-transport-https ca-certificates curl software-properties-common gnupg2
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
$ add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
$ apt-get update && apt-get install -y \
containerd.io=1.2.13-2 \
docker-ce=5:19.03.11~3-0~ubuntu-$(lsb_release -cs) \
docker-ce-cli=5:19.03.11~3-0~ubuntu-$(lsb_release -cs)
$ cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
$ mkdir -p /etc/systemd/system/docker.service.d
# Daemon reload & start and enable docker
$ systemctl daemon-reload
$ systemctl enable --now docker
# Installation of kubeadm, kubelet, kubectl
$ sudo apt-get update && sudo apt-get install -y apt-transport-https curl
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
$ sudo apt-get update
$ sudo apt-get install -y kubelet kubeadm kubectl
$ sudo apt-mark hold kubelet kubeadm kubectl
# restarting the kubelet:
$ sudo systemctl daemon-reload
$ sudo systemctl restart kubelet
# Initializing your control-plane node through kubeadm
$ kubeadm init --apiserver-advertise-address=<main-ip-address> --pod-network-cidr=<ip-addr-pod>
# --pod-network-cidr=10.244.0.0/16
# If you are facing errors and wanna ignore it for now. Then use "--ignore-preflight-errors=all"
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ export KUBECONFIG=/root/.kube/config
# After completion of kubeadm. You will get kubeadm join script.
# SAVE it in the FILE for the worker node. Don't generate new one.
# Deploy network plugins only in the master node and before running join script into the worker node. Without network plugins coredns
# will not spin up. We are installing Weave.
$ kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
$ kubectl get nodes
$ kubectl get cs
$ kubectl get po -n kube-system
######################### Worker Node ##########################################################
# Set the hostname
$ hostnamectl set-hostname <enter-hostname>
# To get effect in the system without reboot, run the following command:
$ exec bash
# Do entry in the /etc/hosts for master and worker nodes to identify by it's hostname.
e.g. echo "172.16.238.10 master" >> /etc/hosts
echo "172.16.238.11 worker01" >> /etc/hosts
echo "172.16.238.12 worker02" >> /etc/hosts
# You can make it passwordless authentication. Easy to access.
# To check the product_uuid in the machine and should be unique otherwise the installation process can be fail.
# Because kubernetes uses these values to uniquely identify the nodes in the cluster, same terms applicable on MAC address.
# If not available then no issue.
$ sudo cat /sys/class/dmi/id/product_uuid
# To check the IP addr of the current system
$ ip a
# To load bridged Traffic
$ lsmod | grep br_netfilter
# If above result is empty then load it.
$ sudo modprobe br_netfilter
# Enable the kernel bridge traffic
$ cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
$ sudo sysctl --system
# Status of swap
$ swapon -s
# Disable the swap
$ swapoff -a
# To disable swap permanent go to /etc/fstab, comment it.
# firewall service should be disable
$ systemctl status firewalld
$ systemctl stop firewalld
$ systemctl disable firewalld
# Check the required port is not opt by other services.
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#control-plane-node-s
# Installation Container Runtime
$ apt-get update && apt-get install -y \
apt-transport-https ca-certificates curl software-properties-common gnupg2
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
$ add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
$ apt-get update && apt-get install -y \
containerd.io=1.2.13-2 \
docker-ce=5:19.03.11~3-0~ubuntu-$(lsb_release -cs) \
docker-ce-cli=5:19.03.11~3-0~ubuntu-$(lsb_release -cs)
$ cat > /etc/docker/daemon.json <<EOF
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
$ mkdir -p /etc/systemd/system/docker.service.d
# Daemon reload & start and enable docker
$ systemctl daemon-reload
$ systemctl enable --now docker
# Installation of kubeadm, kubelet, kubectl
$ sudo apt-get update && sudo apt-get install -y apt-transport-https curl
$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
$ cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
$ sudo apt-get update
$ sudo apt-get install -y kubelet kubeadm kubectl
$ sudo apt-mark hold kubelet kubeadm kubectl
# restarting the kubelet:
$ sudo systemctl daemon-reload
$ sudo systemctl restart kubelet
# AFTER this run the kubeadm join script which one you saved in the file. If you will face issue then use flag
# "--ignore-preflight-errors=all"
# Hope this will help you to install kubernetes cluster through kubeadm-way!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment