# **Install Kubernetes Cluster** ## Login to Master Node and perform the following steps 1. Set the hostname ``` sudo hostnamectl set-hostname master ```  2. Letting iptables see bridged traffic ``` sudo modprobe br_netfilter 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 ```  3. Instaling Docker ``` sudo apt-get update ```  ``` sudo apt-get install docker.io -y ```   ``` sudo systemctl enable docker ```  ``` sudo systemctl start docker ```  ``` sudo usermod -aG docker <user_name_of_master> ```  4. Add the Kubernetes Repository ``` 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=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00 ```  ## Login to Worker Nodes and run following Commands 1. Setup the hostname in the second node ``` sudo hostnamectl set-hostname Worker-1 ``` 2. Letting iptables see bridged traffic ``` sudo modprobe br_netfilter 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 ``` 3. Instaling Docker on Worker ``` sudo apt-get update sudo apt-get install docker.io -y sudo systemctl enable docker sudo systemctl start docker ``` 4. Add the Kubernetes Repository ``` 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=1.21.0-00 kubeadm=1.21.0-00 kubectl=1.21.0-00 ```  ## Log back to Master Node and perform following steps: 1. Setup kubernetes master using kubeadm init ``` sudo kubeadm init ```   *Note: If you get swap error like following disable swap*  ``` swapoff -a && sed -i '/swap/d' /etc/fstab ```  2. Setup the kubectl config file ``` mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config ``` 3. Check the node status ``` kubectl get node ``` *Note: The node will be shown as not ready* 4. Check the pod status using ``` kubectl get pod -n kube-system ```  5. Apply the CNI plugin ``` kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" ```  6. Check the node status ``` kubectl get node ``` 7. Create Join Command on Master ``` sudo kubeadm token create --print-join-command ``` *Note: copy the kubeadm join command display as the output of the command and login to Worker Nodes and execute using sudo*  ## Login to Worker Nodes to add it to Master ``` sudo *kubeadm join <paste the full command which you have copied from the master node*> ```  > > *Congratulations!!! Your Kubernetes Cluster is set up Perfectly* > 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up