loader

How to Install Kubernetes on Debian 9

Introduction:

 
Docker containers can be orchestrated and managed using Kubernetes on an on-prem server or across a hybrid cloud environment. It enables users to set up production-ready Kubernetes clusters with adherence to best practices using Kubeadm. 
 
The following tutorial will show you how to install a Kubernetes cluster on Debian 9. 
 
A container created with Docker can hold a preconfigured image and application. Kubernetes allows you to run multiple containers across multiple systems and balance loads between them. 
 

Prerequisites

 

• Multiple Debian 9 VMs (Cloud Servers) to house the Master and worker nodes.
• Docker or any other container runtime.
• User with sudo or root privileges on every server.

Steps to Install Kubernetes on debian 9

 
Step 1. Install Docker on all Debian 9 VMs

 

Kubernetes requires an existing Docker installation. If you already have Docker installed, skip ahead to Step 2.

If you do not have Kubernetes, install it by following these steps:
1. Update the installed packages
Our first step is to update the list of packages installed on Debian.

 

sudo apt update

 

2. Install security components so that https is enforced 

 
Now, we will install the files required to ensure that apt transfers files to and from other computers only over https connections.

sudo apt install apt-transport-https ca-certificates curl gnupg2 software-properties-common

 

 

3. Install GPG key to validate downloads
 
The GPG key ensures that we only obtain authentic files from the repository. To add the key, run the command below. This will return an OK.

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add –

4. Add Docker repository to APT sources 

 

 

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"

5. Update the list of packages

 

 

 

Add the just installed Docker packages to the packages database using the following command. 

 

sudo apt update

6. Install Docker on Debian

 

 

To install Docker now, run;

 

sudo apt install docker-ce

Type Y and press enter to continue with the installation when prompted to do so.

 

 

The above command will install the Docker on Debian after which it configures its engine to start on boot.

 

 

 

Use the command below to check the status and find out if the installation was successful, active, and running.

sudo systemctl status docker
OUTPUT
 

Step 2. Install Curl and https

 
First, we need to install curl and https on every machine. Use the following commands:
 

sudo apt install curl
sudo apt-get install -y apt-transport-https

Step 3. Add Kubernetes public key

 
Now get and add the key

sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -

Step 4. Add an apt repository

 
Next, we need to create a file for our new apt repository. Use the following command:

cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF

Step 5. Update the system and install Kubernetes modules

 
To update your system, enter:

sudo apt-get update

After the command finishes execution, install the Kubernetes modules using:

apt-get install -y kubelet kubeadm kubectl

Step 6. Set hostnames

Set the appropriate hostnames for your Master and worker nodes:

sudo hostnamectl set-hostname "master-node"
exec bash

And

sudo hostnamectl set-hostname "w-node1"
exec bash

Now open the /etc/hosts file and edit the hostnames for your worker nodes:

sudo cat <> /etc/hosts
10.168.10.207 master-node
10.168.10.208 node1 W-node1
10.168.10.209 node2 W-node2
EOF

Step 7. Configure Firewall

 
For seamless communication across multiple nodes, we need to define rules in firewall. Use the following commands on your Master node to do so:

sudo ufw allow 6443/tcp
sudo ufw allow 2379/tcp
sudo ufw allow 2380/tcp
sudo ufw allow 10250/tcp
sudo ufw allow 10251/tcp
sudo ufw allow 10252/tcp
sudo ufw allow 10255/tcp
sudo ufw reload

We also need to execute these commands on each of the worker nodes:

sudo ufw allow 10251/tcp
sudo ufw allow 10255/tcp
sudo ufw reload

Step 8. Turn swap off

 
For Kubelet to work, we also need to disable swap on all of our VMs. Use the following command to turn swap off:

sudo swapoff -a

Step 9. Enable Kubelet

 
Finally, we need to enable the kubelet service. Use this command:

sudo systemctl enable kubelet

Now you’re all set up.

Deploying a Kubernetes Cluster on Debian 9

 

Step 1. kubeadm initialisation

 To launch a new Kubernetes cluster instance, you need to initialise kubeadm. Use the following command: 

sudo kubeadm init

 

This command may take several minutes to execute.

Also, you will automatically receive a command. To save the text, copy it and save it somewhere safe. The worker nodes will be added to the cluster using this method.  No worries if you misplaced or forgot to duplicate the command. Type the following command to get it back: 

 

 

sudo kubeadm token create --print-join-command

 

Step 2. Create required directories and start managing Kubernetes cluster

 You must first establish a directory and acquire ownership of it before you can begin managing your cluster. As a regular user, run the following commands: 

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

 

Step 3. Set up Pod network for the Cluster

 Each pod in a cluster is connected to the pod network. It doesn’t work right now. Here are two commands you can use to confirm this:

sudo kubectl get nodes

 

sudo kubectl get pods --all-namespaces

 

 

CoreDNS service is inaccessible at this time as well as the master–node state is NotReady. You can resolve this problem by running these commands:

 

 

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml

 

Step 4. Add nodes to your cluster

 In addition to the worker nodes, you need to create a cluster of workers. The above kubeadm join auto-generated token was used again in Step 1. 

sudo kubeadm token create --print-join-command

 

 

 

Run your own version of the following command on all of the worker node VMs, meaning you have to replace with your own machine’s IP address.

 

 

 

 

kubeadm join 102.130.117.206:6443 --token v9qxex.i6jant8m2r0zxhhk     --discovery-token-ca-cert-hash sha256:b0cda6d2e64a8a65ad5f439e06c3cb489c3d7f6f4e0c094ebb2556037153dc4b

 

 

This command should be run on the The master node Newly added nodes should appear.

 

 

 

sudo kubectl get nodes

 

To set the role for your worker node, use the following command:

 

 

 

sudo kubectl label node w-node1 node-role.kubernetes.io/worker=worker

 

 

 

You’re completely ready now!!

 

 

 

 

That’s it.

 

 

 

 

Our goal in writing this article is to give you an how to install kubernetes on debian 9 and we hope this article has given you a better understanding.

 

 

 

 

 

 

Get the most out of learning with VPSie.com