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
 
(2 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 [[Installing Kubernetes#Kubernetes on Ubuntu by Edureka|Edureka's video 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==
To automate this repeated process on many machines, consider using [[Ansible]] or [[Terraform]].
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
 
====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>
 
===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>worker1</code> respectively.
The string that shows up in this file <code>/etc/hostname</code>, will eventually show up in the command line interface.
It will show up in a terminal app with prompts looking like: <code>root@kmaster:</code> or <code>root@worker1:</code>.
 
====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>
In the above mentioned example, <code><IP-Address-of-masters and slaves></code> is <code>172.31.20.148</code>. Note that this step needs to be executed for each master and slave/worker node.
 
====Statically defined 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 worker1
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 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 -
 
===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
 
Another way to do this is to compress all the above into one instruction
<syntaxhighlight lang="bash">
echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" \
| sudo tee -a /etc/apt/sources.list.d/kubernetes.list \
&& sudo apt-get update
</syntaxhighlight>
 
===Update the kubeadm.conf file===
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
 
===Pod network based on [https://docs.projectcalico.org Calico] (or [https://github.com/flannel-io/flannel#flannel Flannel])===
First download the <code>calico.yaml</code> file: ('''The following instruction is different from the [[Installing Kubernetes#Kubernetes on Ubuntu by Edureka|original video]].''')
curl https://docs.projectcalico.org/manifests/calico.yaml -O
 
Use the <code>kubectl apply</code> command.
kubectl apply -f calico.yaml
 
An alternative Kubernetes networking substrate is [https://github.com/flannel-io/flannel#flannel Flannel].
The URL to get the YAML file is here:
curl https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml -O
Then you may just perform <code>kubectl apply</code> command to install the network substrate:
kubectl apply -f kube-flannel.yaml
 
{{:Kubernetes Dashboard Installation}}
 
==Only at the Slave==
At the end, run this command to get the worker node, or slave to join the cluster.
sudo kubeadm join 172.31.20.148:6443 --token h5c0bs.nt4vtekd1eb7qupd --discovery-token-ca-cert-hash sha256:088a39a92611a81f18f16bd6ab6b1b438a7015b68392fa8559487c9240c1d1b6
 
=Check Installation Results=
Check the final result:
kubectl get nodes
To see all the pods, use the following instruction:
kubectl get pods -o wide --all-namespaces
 
=Kubernetes on Ubuntu by Edureka=
{{:Kubernetes on Ubuntu by Edureka}}
 
=Some online installation tutorials=
# [[Video:Installing Kubernetes]]
# https://blog.alexellis.io/kubernetes-in-10-minutes/
# 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: