How to Set Up a Kubernetes Cluster on Ubuntu 20.04/18.04/16.04 in 14 Steps

Author profile picture

@jhooqRahul Wagh

https://jhooq.com/

On this article on “14 Steps to Set up kubernetes on Ubuntu 18.04 and 16.04” we’re going to create Kubernetes cluster together with kubeadm on Ubuntu 18.04 (The similar steps can be utilized for the Ubuntu 16.04 as neatly)

kubeadm is command line software to have interaction with kubernetes cluster. Kubeadm is based on speedy deployment function of Docker and operating the formulation services and products of kubernetes grasp and etcd server as container.

We’re going to use two nodes

  1. Grasp node
  2. Employee node

Must haves

  1. Studying time is set 20 mins
  2. Vagrant 2.2.7 or newest – For installationi nstruction click on right here
  3. VM VirtualBox – For set up instruction click on right here

[embedded content]

Step 1 – Get started your vagrant field
As a minimal requirement for kubernetes set up we want –

  1. Grasp Node – 2 cpus, 2 GB Reminiscence
  2. Employee Node – 1 cpu, 1 GB Reminiscence

Use following Vagrantfile to spin up your vagrant field

Vagrant.configure("2") do |config| config.vm.outline "grasp" do |grasp| grasp.vm.box_download_insecure = true grasp.vm.field = "hashicorp/bionic64" grasp.vm.community "private_network", ip: "100.0.0.1" grasp.vm.hostname = "grasp" grasp.vm.supplier "virtualbox" do |v| v.identify = "grasp" v.reminiscence = 2048 v.cpus = 2 finish finish config.vm.outline "employee" do |employee| employee.vm.box_download_insecure = true employee.vm.field = "hashicorp/bionic64" employee.vm.community "private_network", ip: "100.0.0.2" employee.vm.hostname = "employee" employee.vm.supplier "virtualbox" do |v| v.identify = "employee" v.reminiscence = 1024 v.cpus = 1 finish finish finish

Step 2 – Replace host recordsdata on each grasp and employee node
grasp node –
SSH into the grasp node

$ vagrant ssh grasp

Upload host access for grasp in addition to employee node

[email protected]:~$ sudo vi /and so forth/hosts 100.0.0.1 grasp.jhooq.com grasp
100.0.0.2 employee.jhooq.com employee

Check the employee node through sending from grasp

[[email protected] ~]$ ping employee
PING employee.jhooq.com (100.0.0.2) 56(84) bytes of information.
64 bytes from employee.jhooq.com (100.0.0.2): icmp_seq=1 ttl=64 time=0.462 ms
64 bytes from employee.jhooq.com (100.0.0.2): icmp_seq=2 ttl=64 time=0.686 ms

Check the grasp node through sending from employee

[[email protected] ~]$ ping grasp
PING grasp.jhooq.com (100.0.0.1) 56(84) bytes of information.
64 bytes from grasp.jhooq.com (100.0.0.1): icmp_seq=1 ttl=64 time=0.238 ms
64 bytes from grasp.jhooq.com (100.0.0.1): icmp_seq=2 ttl=64 time=0.510 ms

Step 3 – Set up Docker on each grasp and employee node

You wish to have to set up Docker on each the node.

So run the next set up command on each the nodes

[[email protected] ~]$ sudo apt-get replace [[email protected] ~]$ sudo apt set up docker.io

Allow and get started docker

[email protected]:~$ sudo systemctl permit docker
Created symlink /and so forth/systemd/formulation/multi-user.goal.needs/docker.provider → /lib/systemd/formulation/docker.provider. [[email protected] ~]$ sudo systemctl get started docker

Take a look at the docker provider standing

[[email protected] ~]$ sudo systemctl standing docker ● docker.provider - Docker Application Container Engine Loaded: loaded (/lib/systemd/formulation/docker.provider; enabled; seller preset: enabled) Energetic: lively (operating) since Thu 2020-04-23 19:10:59 UTC; 4s in the past Doctors: https://medical doctors.docker.com

Step 4 – Disable the firewall and turnoff the “swapping”

We’d like to disable firewall in addition to swapping on grasp in addition to employee node. As a result of to set up kubernetes we want to disable the swapping on each the nodes

[email protected]:~$ sudo ufw disable
Firewall stopped and disabled on formulation startup [[email protected] ~]$ sudo swapoff -a

Step 5 – Set up “apt-transport-https” bundle

To download the kubernetes and its public we want to set up “apt-transport-https” bundle on each grasp in addition to employee node

[email protected]:~$ sudo apt-get replace && sudo apt-get set up -y apt-transport-https

Step 6 – Obtain the general public keys

We’d like to have the general public keys for gaining access to applications on Google Cloud.

So run the next command to get the general public keys on each grasp in addition to employee node

[email protected]:~$ curl -s https://applications.cloud.google.com/apt/document/apt-key.gpg | sudo apt-key upload -
OK

Step 7 – Upload kubernetes repo

As a subsequent step we want to upload the kubernetes repo to each grasp in addition to employee node

[email protected]:~$ sudo bash -c 'echo "deb http://apt.kubernetes.io/ kubernetes-xenial primary" > /and so forth/apt/assets.record.d/kubernetes.record'

Step 8 – Set up kubernetes

Now after including the kubernetes repo we want to set up the kubernetes on each mater in addition to employee node

[email protected]:~$ sudo apt-get replace && sudo apt-get set up -y kubelet kubeadm kubectl

Step 9 – Allow and Get started kubelet

Alright now we’ve got put in the kubernetes, now we want to permit the kubelet reinforce for each grasp as neatly employee node

[[email protected] ~]$ sudo systemctl permit kubelet [[email protected] ~]$ sudo systemctl get started kubelet

Step 10 – Initialize the kubernetes cluster

Ok now we’ve got succeed in to level the place we’ve got completed the entire prerequisite for initializing the kubernetes cluster.

Let’s run the kubernetes initialization command on best on grasp

[[email protected] ~]$ sudo kubeadm init --apiserver-advertise-address=100.0.0.1 --pod-network-cidr=10.244.0.0/16

Be aware down kubeadm sign up for command which we’re going to use from employee node to sign up for the grasp node the use of token.

sudo kubeadm sign up for 100.0.0.1:6443 --token g2bsw7.5xr3bqc21eqyc6r7 --discovery-token-ca-cert-hash sha256:39b2b0608b9300b3342a8d0a0e9204c8fc74d45b008043a810f94e4f1fb8861f

Step 11 – Transfer kube config document to present consumer (best run on grasp)

To have interaction with the kubernetes cluster and to use kubectl command, we want to have the kube config document with us.

Use the next command to get the kube config document and put it below running listing.

[[email protected] ~]$ mkdir -p $HOME/.kube
[[email protected] ~]$ sudo cp -i /and so forth/kubernetes/admin.conf $HOME/.kube/config
[[email protected] ~]$ sudo chown $(identification -u):$(identification -g) $HOME/.kube/config

Step 12 – Practice CNI from kube-flannel.yml(best run on grasp)

After the grasp of the cluster is able to deal with jobs and the services and products are operating, for the aim of creating bins out there to every different via networking, we want to arrange the community for container verbal exchange

Get the CNI(container community interface) configuration from flannel
[[email protected] ~]$ wget https://uncooked.githubusercontent.com/coreos/flannel/grasp/Documentation/kube-flannel.yml

Be aware – However since we’re running on the VMs so we want to test our Ethernet interfaces first.

Glance out for the Ethernet i.e. eth1 which has a ip handle 100.0.0.1(that is the ip handle which we used in vagrant document)

[[email protected] ~]$ ip a s
1: lo: <LOOPBACK,UP,LOWER_UP>
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP crew default qlen 1000 hyperlink/ether 08:00:27:bb:14:75 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP crew default qlen 1000 hyperlink/ether 08:00:27:facebook:48:77 brd ff:ff:ff:ff:ff:ff inet 100.0.0.1
4: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP>

Now we want to upload the additional args for eth1 in kube-flannel.yml

[[email protected] ~]$ vi kube-flannel.yml

Searche for – “flanneld”

Within the args phase upload : – –iface=eth1

- --iface=eth1 args: - --ip-masq - --kube-subnet-mgr - --iface=eth1

Practice the flannel configuration

[email protected]:~$ kubectl practice -f kube-flannel.yml
podsecuritypolicy.coverage/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-p.c64le created
daemonset.apps/kube-flannel-ds-s390x created

Step 13 – Sign up for employee nodes to grasp(best run on employee)

Within the Step 10 we generated the token and kubeadm sign up for command.

Now we want to use that sign up for command from our employee node

[email protected]:~$ sudo kubeadm sign up for 100.0.0.1:6443 --token g2bsw7.5xr3bqc21eqyc6r7 --discovery-token-ca-cert-hash sha256:39b2b0608b9300b3342a8d0a0e9204c8fc74d45b008043a810f94e4f1fb8861f
W0423 19:27:00.344480 18268 sign up for.pass:346] [preflight] WARNING: JoinControlPane.controlPlane settings might be overlooked when control-plane flag isn't set.
[preflight] Operating pre-flight exams [WARNING IsDockerSystemdCheck]: detected "cgroupfs" as the Docker cgroup motive force. The really helpful motive force is "systemd". Please practice the information at https://kubernetes.io/medical doctors/setup/cri/
[preflight] Studying configuration from the cluster...
[preflight] FYI: You'll take a look at this config document with 'kubectl -n kube-system get cm kubeadm-config -oyaml'
[kubelet-start] Downloading configuration for the kubelet from the "kubelet-config-1.18" ConfigMap in the kube-system namespace
[kubelet-start] Writing kubelet configuration to document "/var/lib/kubelet/config.yaml"
[kubelet-start] Writing kubelet surroundings document with flags to document "/var/lib/kubelet/kubeadm-flags.env"
[kubelet-start] Beginning the kubelet
[kubelet-start] Ready for the kubelet to carry out the TLS Bootstrap... This node has joined the cluster:
* Certificates signing request used to be despatched to apiserver and a reaction used to be won.
* The Kubelet used to be knowledgeable of the new safe connection main points. Run 'kubectl get nodes' on the control-plane to see this node sign up for the cluster.

Step 14 – Take a look at the nodes standing(best run on grasp)

To test the standing of the nodes use

[[email protected] ~]$ kubectl get nodes

NAME STATUS ROLES AGE VERSION
grasp In a position grasp 26m v1.18.2
employee In a position <none> 63s v1.18.2

Abstract

So this used to be our amateur instructional which comes to round – 14 Steps to Set up kubernetes on Ubuntu 18.04 and 16.04.

With that we will be able to conclude what we’ve got accomplished –

  1. Congratulations we’ve got effectively put in kubernetes on Ubuntu 18.04
  2. After putting in kubernetes we’re effectively sign up for the employee nodes with grasp.

Tags

The Noonification banner

Subscribe to get your day by day round-up of best tech tales!

(Visited 1 times, 1 visits today)

Leave a Reply