Kubernetes setup guide
Run the following commands on your all cluster nodes
- Setup docker
sudo apt-get update sudo apt-get install docker.io sudo systemctl start docker sudo systemctl enable docker
- Turn off swap memory
sudo swapoff -a
- Setup kubernetes
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 install kubeadm kubelet kubectl sudo apt-mark hold kubeadm kubelet kubectl
- Initialize your control plane (master node)
sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=<MASTER_NODE_IP> mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Make kubernetes config directory and put the config files there
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
- Setup the flannel network
sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
- Join to the cluster from other nodes
sudo kubeadm join <MASTER_NODE_IP>:6443 --token <TOKEN> \ --discovery-token-ca-cert-hash <DISCOVERY_TOKEN>
- Make sure all nodes are connected & ready by running the command in control plane
kubectl get nodes
- Run a simple app on kubernetes
# Create the deployment pods sudo kubectl apply -f https://raw.githubusercontent.com/sohelamin/k8s-example/master/k8s/deployment.yml # Create the service to expose outside the cluster sudo kubectl apply -f https://raw.githubusercontent.com/sohelamin/k8s-example/master/k8s/service.yml
- Now you have a NodePort eg. 3xxxx and you can get it by the command
kubectl get svc
- Visit on browser http://<NODE_IP>:<NODE_PORT>
https://phoenixnap.com/kb/install-kubernetes-on-ubuntu https://learnk8s.io/nodejs-kubernetes-guide