Use the following Vagrantfile to start your vagrant box
Vagrant.configure ( "2 ) do | config | config.vm .define "master do | master | master.vm.box_download_insecure = true master.vm.box = "hashicorp / bionic64 master.vm.network "private_network , ip : "188.8.131.52 master.vm.hostname = " master master.vm.provider "virtualbox do | v | v.name = " maître v.memory = 2048 v.cpus = 2 end end config.vm.define "worker do | worker | worker.vm .box_download_insecure = true worker.vm.box = "hashicorp / bionic64 worker .vm.network "private_network , ip : " 184.108.40.206 worker.vm.hostname = "worker worker.vm.provider "virtualbox do | v | v.name = "worker v.memory = 1024 v.cpus = 1 end end end
Step 2 - Update host files on master node and worker node
master node - SSH in master node
$ vagrant ssh master
Add a host entry for the master node and the worker node
vagrant @ master: ~ $ sudo vi / etc / hosts 100.0 . 0 .1 master.jhooq.com master 100.0 . 0 .2 worker.jhooq.com worker
Test the worker node in l 'sending from master
[vagrant @ master ~] $ pingPING worker worker.jhooq.com ( 100.0 . 0 . 2 ) 56 ( 84 ) bytes of data. 64 bytes de worker.jhooq.com ( 100.0 . 0 . 2 ) : icmp_seq = 1 ttl = 64 time = 0.462 ms 64 bytes from worker .jhooq.com ( 100.0 . 0 . 2 ): icmp_seq = 2 ttl = 64 time = 0.686 ms
Test the master node by sending worker
[vagrant @ worker ~] $ ping master PING master.jhooq.com ( 100.0 . 0 . 1 ) 56 ( 84 ) bytes of data. 64 bytes de master.jhooq.com ( 100.0 . 0 . 1 ) : icmp_seq = 1 ttl = 64 time = 0.238 ms 64 bytes from master.jhooq.com ( 100.0 . 0 . 1 ): icmp_seq = 2 ttl = 64 time = 0,510 ms
Step 3 - Install Docker on the master and worker nodes
You must install Docker on both nodes.
So run the following install command on both nodes
[vagrant @ master ~] $ sudo apt-get update [vagrant @ master ~] $ sudo apt install docker.io
Activate and start the docker
vagrant @ master: ~ $ sudo systemctl activate docker Create symbolic link / etc / systemd / system / multi-user. target.wants / docker.service → /lib/systemd/system/docker.service. [vagrant @ master ~] $ sudo systemctl start docker
Check the status of the docker service
[vagrant @ master ~] $ sudo systemctl docker status ● docker.service - Docker Application Container Engine Loaded: loaded ( / lib / systemd / system / docker.service; enabled; provider preset: enabled) Active: active (running) from game. 2020 - 04 - 23 19 : 10 : 59 UTC; There are 4 Docs: https: // docs.docker.com
Step 4 - Disable the firewall and disable the "swapping
We need to disable the firewall and swap on the master node and on the worker node. Because to install Kubernetes, we need to disable swapping on both nodes
vagrant @ worker: ~ $ sudo ufw disable Firewall stopped and disabled on system startup [vagrant @ worker ~] $ sudo swapoff -a
Step 5 - Install the "apt-transport-https" package
To download the kubernetes and its audience, we need to install the "apt package -transport-https "on both master node and worker node
vagrant @ master: ~ $ sudo apt-get update && sudo apt-get install -y apt-transport -https
Step 6 - Download the public keys
We need the public keys to access the packages on Google Cloud.
So run the following command to get the public keys on both the master node and the worker node
vagrant @ worker: ~ $ curl -s https: // packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - OK
Step 7 - Add the kubernetes repository
As next step we need to add the kubernetes repository to both master node and worker node
vagrant @ worker: ~ $ sudo bash -c 'echo "deb http: //apt.kubernetes.io/ " kubernetes-xenial main "> /etc/apt/sources.list.d/kubernetes.list '
Step 8 - Install kubernetes
Now after adding the kubernetes repository we also need to install the kubernetes on both maters as a worker node
vagrant @ master: ~ $ sudo apt-get update && sudo apt-get install -y kubelet kubeadm kubectl
Step 9 - Activate and start kubelet
Alright now we've installed the kubernetes, now we need to enable kubelet support for the master and worker nodes
[vagrant @ master ~] $ sudo systemctl enable kubelet [vagrant @ master ~] $ sudo systemctl start kubelet
Step 10 - Initialize the kubernetes cluster
Okay, we've reached the point where we've done all the prerequisites for initializing the kubernetes cluster.
Let's start the initialization of kubernetes command only on the master
[vagrant @ master ~] $ sudo kubeadm init --apiserver-advertise-address = 100.0 . 0 . 1 --pod-network-cidr = 10.244 . 0 . 0 / 16
Note the kubeadm join command that we will be using from worker node to jo in the master node using the token.
sudo kubeadm join 100.0 . 0 . 1 : 6443 --token g2bsw7 .5 xr3bqc21eqyc6r7 --discovery-token-ca-cert-hash sha256: 39 b2b0608b9300b3342a8d0a0e9204c8fc74d45f94f /a8code
Step 11 - Move the configuration file from kube to the current user (only run on the master)
To interact with the kubernetes cluster and use the kubectl command, we need to have the configura filetion kube with us.
Use the following command to get the kube config file and put it under the working directory.
[vagrant @ master ~] $ mkdir -p $ HOME / .kube [ vagrant @ master ~] $ sudo cp -i /etc/kubernetes/admin.conf $ HOME / .kube / config [vagrant @ master ~] $ sudo chown $ (id -u): $ (id -g) $ HOME / .kube / config
Step 12 - Apply CNI from kube-flannel.yml (only run on the master)
Once the cluster master is ready to handle tasks and services are running, with the aim of making the containers accessible to each other through the network, we need to configure the network for container communication
Obtain CNI (container network interface) flannel
[vagrant @ master ~] $ wget https: // raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Note - But since we are working on VMs, we need to check our Ethernet int faces first.
Find the Ethernet ie eth1 which has an IP address of 220.127.116.11 (this is the IP address we used in the vagrant file)
[vagrant @ master ~] $ ip like
1 : lo: < LOOPBACK, UP, LOWER_UP > 2: eth0: mtu 1500 qdisc fq_codel status UP default group qlen 1000 link / ether 08: 00: 27: bb: 14: 75 brd ff: ff : ff: ff: ff: ff inet 10.0.2.15 3: eth1: mtu 1500 qdisc fq_codel state UP default group qlen 1000 link / ether 08: 00: 27: fb: 48: 77 brd ff: ff: ff: ff: ff: ff inet 18.104.22.168 4: docker0:
We must now add the additional arguments for eth1 in kube- flannel.yml
[vagrant @ master ~] $ vi kube-flannel.yml
Search for - "flanneld
In the args section, add: - –iface = eth1
- --iface = eth1 args: - - ip-masq - --kube-subnet-mgr - --iface = eth1
Apply flannel configuration
vagrant @ master : ~ $ kubectl apply -f kube-flannel.yml
podsecuritypolicy.policy / psp.flannel.unprivileged created clusterrole.rbac.authorization.k8s.io/flannel created clusterrolebinding.rbac.authorization.k8s.io/flannel created serviceaccount / flannel created configmap / kube-flannel-cfg created daemonset.apps / kube-flannel- ds-amd64 created daemonset.apps / kube-flannel-ds-arm64 created daemonset.apps / kube-flannel-ds-arm created daemonset.apps / kube-flannel-ds-ppc64le created daemonset.apps / kube-flannel-ds- s390x created
Step 13 - Join worker nodes to master (only run on worker)
In step 10, we generated the token and kubeadm join command.
News now need to use this join command from our worker node
vagrant @ worker : ~ $ sudo kubeadm join 100.0 . 0 . 1 : 6443 --token g2bsw7 . 5 xr3bqc21eqyc6r7 --discovery-token-ca-cert-hash sha256: 39 b2b0608b9300b3342a8d0a0e9204c8fc74d45b008843f "style
block; -x: auto style = "display: block; -x:; background: black; color: #eaeaea; padding: 30px "> W0423 19 : 27 : 00.344480 18268 join.go: 346 ] [contupstream role] WARNING: JoinControlPane.controlPlane parameters will be ignored when the control plane flag is not set. [Preflight] Performing pre-flight checks [WARNING IsDockerSystemdCheck]: "cgroupfs detected as the Docker cgroup group driver The recommended driver is "systemd . Please follow the guide on https: // kubernetes.io/docs/setup/cri/ [preflight] Reading the configuration from the cluster ... [preflight] FYI: You can view this configuration file with 'kubectl -n kube-system get cm kubeadm-config -oyaml ' [kubelet- start] Download configuration for the kubelet from the " kubelet-config-1.18 ConfigMap in namespace kube-system [kubelet-start] Write kubelet configuration to file "/ var / lib / kubelet / config.yaml [kubelet-start] Writing kubelet environment file with flags in the file " / var / lib / kubelet / kubeadm-flags.env " [kubelet-start] Starting du kubelet [kubelet-start] Waiting for that the kubelet performs the TLS bootstrap ... This node has joined the cluster: * A signing request from certificate has been sent to apiserver and a response has been received. * The Kubelet has been notified of the new secure connection details. Run 'kubectl get nodes ' on the control plane to see this node join the cluster.
Step 14 - Check the state of the nodes (only executed on the master)
To check node status use
[vagrant @ master ~] $ kubectl get nodes
NAME STATUS ROLES AGE VERSION master Ready master 26 m v1 . 18 . 2 worker Ready 63 s v1 . 18 . 2
So this was our beginners tutorial which involves about - 14 steps to install kubernetes on Ubuntu 18.04 and 16.04.
With this we can conclude what we have accomplished -
- Congratulations, we have successfully installed kubernetes on Ubuntu 18.04
- After installing kubernetes, we successfully joined the worker nodes with master.