INSTALLING KUBERNETES FROM SCRATCH ON UBUNTU

In this post we will install the Kubernetes aka K8s from scratch on Ubuntu 18.04 LTS.

Our setup consists of 3 machines (1 Master and 2 Worker Nodes) with each minimum 2 GB of RAM.

Below are commands :-

## Add Docker and Kubernetes to your repository.
Run the following on all three nodes to get the gpg keys for Docker and Kubernetes and add it to your repository:
sudo apt-get update
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
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

## Install Docker, kubelet, kubeadm, and kubectl.
Run the following command on all three nodes to install kubelet, kubeadm, and kubectl:
sudo apt-get install -y docker-ce kubelet kubeadm kubectl

## Initialize the Kubernetes cluster.
In the master node, run the following command to initialize the cluster using kubeadm:
sudo kubeadm init --pod-network-cidr=10.244.0.0/16

## Set up local kubeconfig.
In the master node, run the following commands to set up local kubeconfig:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

## Apply the flannel CNI plugin as a network overlay.
In the master node, run the following command to apply flannel:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

## Join the worker nodes to the cluster, and verify they have joined successfully.
In both of the worker nodes, run the output of the kubeadm init command to join the worker nodes to the cluster. Should look similar to:
sudo kubeadm join 'KUBERNETES_MASTER_IP':6443 --token 'UNIQUE_TOKEN' --discovery-token-ca-cert-hash sha256:'UNIQUE_HASH'

## Run a deployment that includes at least one pod, and verify it was successful.
In the master node, run the following commands to run a deployment of ngnix and verify:
kubectl create deployment mynginx --image=nginx
kubectl get deployments
kubectl get pods
 
Top