Difference between revisions of "Kubernetes Installation"

From PKC
Jump to navigation Jump to search
(Changed redirect target from Process/K8s Installation to K8s Installation)
Tag: Redirect target changed
 
(47 intermediate revisions by the same user not shown)
Line 1: Line 1:
What is [[Kubernetes]]?
#REDIRECT [[K8s Installation]]
 
=Installation Outline=
After watching many videos on installing Kubernetes, the following outline is extracted from Edureka's tutorial.
 
The suggested initial configuration is to start with one master node and one worker node.
The master node must have at least 2 CPU cores, 2 Gb of memory.
The worker node (slave) should have at least 1 CPU core and 2 Gb of memory.
If one needs to add more machine, one can do it after the above two machines are working.
 
Ideally, set up the domain names of these two nodes with their public IPv4 addresses.
 
==Procedure for both Master and Slave==
The usual initial action is to update, but make sure that you switch to the super user mode and keep being in that role throughout most of the installation.
sudo su
apt update
 
===Swap Space must be turned off===
Then, turn off swap space
swapoff -a
The <code>/etc/fstab</code> file must be edited to remove the line entry that specifies a /swapoff directory.
nano /etc/fstab
 
===Update Hostname, Hosts, and Setup Static IP===
Then, update the hostname file at the <code>/etc/hostname</code> location:
nano /etc/hostname
Change the master node and worker node to <code>kmaster</code> and <code>w1</code> respectively.
 
====Install Net-Tools====
Before inspecting the IP addresses of these machines, you will need to first install Net-Tools.
apt install net-tools
Afterwards, run the instruction:
ifconfig
 
This will show some information, such as follows:
<syntaxhighlight>
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.31.20.148  netmask 255.255.240.0  broadcast 172.31.31.255
        inet6 fe80::5d:ddff:fea4:9331  prefixlen 64  scopeid 0x20<link>
        ether 02:5d:dd:a4:93:31  txqueuelen 1000  (Ethernet)
        RX packets 14905  bytes 20660726 (20.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2247  bytes 270976 (270.9 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
 
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 198  bytes 17010 (17.0 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 198  bytes 17010 (17.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
</syntaxhighlight>
 
====Set a static IP address====
Notice the inet value: <code>172.31.20.148</code>. This is the static and private IP address, that can be used even after one reboots the machine.
One may set up the static IP address here:
nano /etc/network/interfaces
 
Then, put in the following textual content:
<syntaxhighlight>
auto enp0s8
iface enp0s8 inet static
address <IP-Address-of-masters and slaves>
</syntaxhighlight>
Note that this step needs to be executed for each master and slave/worker node.
 
 
====Set a host names====
After setting up the network interfaces, one needs to set up a static look up table for the <code>/etc/hosts</code> file:
nano /etc/hosts
 
Then, put in the following textual content:
Note that this step needs to be executed for each master and slave/worker node.
<syntaxhighlight>
127.0.0.1 localhost
172.31.28.100 w1
172.31.20.148 kmaster
 
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
</syntaxhighlight>
 
Note that one may put in multiple entries at once, in this case, two entries, <code>w1</code> and <code>kmaster</code>, are registered in the <code>/etc/hosts</code> file.
 
At this time, one may issue the command <code>reboot</code>, to restart the machine.
reboot
After rebooting, the machines should show the host name in command line. More importantly, use <code>ifconfig</code> to check if the locally-defined IP address has been kept stable.
===Install Open SSH Server and Docker===
If ssh server is not available, it can be set up by:
sudo apt-get install openssh-server
 
Afterwards, one may install docker
sudo apt-get update
sudo apt-get install -y docker.io
 
Then, one must make sure <code>curl</code> and other things are available:
sudo apt-get update && apt-get install -y apt-transport-https curl
 
Then, use <code>curl</code> to install the following
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
 
===Install kubeadm, kubelet and kubectl===
Then, one needs to add a file to the Debian package list:
<syntaxhighlight lang="bash">
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
> deb http://apt.kubernetes.io/ kubernetes-xenial main
>EOF
</syntaxhighlight>
 
Then, run the following two commands:
apt-get update
apt-get install -y kubelet kubeadm kubectl
 
===Update the Kubernetes configuration===
The following file must be edited with an extra data entry:
nano /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
In this file, add the following entry to the last line.
Environment="cgroup-driver=systemd/cgroup-driver=cgroupfs"
 
==Only do this for the Master Node==
It is time to use the <code>kubeadm init</code> command.
sudo kubeadm init
Or one may specify more parameter using this instruction:
sudo kubeadm init --pod-network-cidr=<depends on calico or flannel pod network> --apiserver-advertise-address=<ip-address-of-master>
An example based on Calico Pod Network (<code>192.168.0.0/16</code>) is shown here:
  sudo kubeadm init --pod-network-cidr=192.168.0.0/16 --apiserver-advertise-address=172.31.20.148
An example based on Flannel Pod Network (<code>10.244.0.0/16</code>) is shown here:
  sudo kubeadm init --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=172.31.20.148
 
After the Kubernetes master node has been successfully initialized, one must run the following three instructions before proceeding:
  mkdir -p $HOME/.kube
  sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  sudo chown $(id -u):$(id -g) $HOME/.kube/config
 
===Create a Pod network based on Calico===
First download the <code>calico.yaml</code> file
curl https://docs.projectcalico.org/manifests/calico.yaml -O
 
Use the <code>kubectl apply</code> command.
kubectl apply -f calico.yaml
 
==Only at the Slave==
 
=Kubernetes on Ubuntu by Edureka=
 
{{#ev:youtube|UWg3ORRRF60}}
 
=Two K8s Installation tutorials by the same guy=
 
{{#ev:youtube|briu_Ev89sw}}
 
{{#ev:youtube|15pdT15NUrk}}
 
=Kubernetes Cluster on AWS EKS (Nana)=
 
{{#ev:youtube|p6xDCz00TxU}}
 
=A 14-minute tutorial=
 
{{#ev:youtube|h4IawuI-EWk}}
 
=Another tutorial=
 
{{#ev:youtube|TDLKQWsrSyk}}
 
 
=A rather short tutorial (seems to have caused errors after testing)=
 
{{#ev:youtube|vpEDUmt_WKA}}
 
 
 
 
=Some online installation tutorials=
# https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/
# https://computingforgeeks.com/deploy-kubernetes-cluster-on-ubuntu-with-kubeadm/
# https://blog.knoldus.com/how-to-install-kubernetes-on-ubuntu-20-04-kubeadm-and-minikube/
 
<noinclude>
[[Category:Kubernetes]]
</noinclude>

Latest revision as of 07:06, 30 July 2021

Redirect to: