Thứ Tư, 24 tháng 7, 2019

Install Kubernetes using kubeadm with two nodes master & worker


Well come back for a long time my friends!

Today I want to take a note about some basic knowledge about Kubernetes. I hope that it will be useful for you (Absolutely it's useful for me 😃😃😃)


This will take a lot of time to tell about Kubernetes Architecture. So I will add a link about this. I think that it will help you to find out more: http://bit.ly/2YhqwLy

Now we can go directly about the main task of this article. As the title, I only note something that I see that it's the most important and be helpful for me when I use Kubernetes. If you see anything else, you can add comments and we can discuss more.

Install Kubernetes

In this article, I will install Kubernetes using two nodes (Master and worker) on two Virtual machine:
  • Master node: k8s-master-node: 192.168.1.200
  • Worker node: k8s-worker-node: 192.3168.1.201

Environment

  • Target: Ubuntu
  • Tool: kubeadm. There are many ways to install but I like kubeadm because it's simple and easy to install and use.

Step by step to install

  • Create hostname: On terminal of master and worker, we set up the hostname:
    • On master: sudo hostnamectl set-hostname k8s-master-node 
    • On worker: sudo hostnamectl set-hostname k8s-worker-node 
  • Update hosts file: Add following lines to /etc/hosts (Remember to change the IP of master and worker as your IPs)
192.168.1.200      k8s-master-node
192.3168.1.201    k8s-worker-node

After install docker, if you do not want to you sudo each time you run docker or docker-compose command, you can follow these link to resolve: https://docs.docker.com/install/linux/linux-postinstall/


  • Configure Kubernetes Package Repository on Master & Worker Nodes

sudo apt-get install apt-transport-https curl -y
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"

  • Disable Swap and Install Kubeadm on all the nodes

sudo swapoff -a
sudo apt-get install kubeadm -y 

  • Initialize and Start Kubernetes Cluster on Master Node using Kubeadm
sudo kubeadm init --pod-network-cidr=172.168.10.0/24
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config 

  • Create token and join worker to master
    • Create token in master node: kubeadm token create --print-join-command 
    • Copy output command and run in worker node

See the nodes

  • kubectl get nodes

Install Kubernetes using kubeadm with two nodes master & worker

Well come back for a long time my friends! Today I want to take a note about some basic knowledge about Kubernetes. I hope that it will...