Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. Docker is the leading platform for containerization. In this guide, we will show you how to install and configure Kubernetes along with Docker on Ubuntu 18.04 LTS. Whether you're using a Windows VPS UK or another hosting provider, Kubernetes helps manage containers efficiently.
Prerequisites
Before you begin, ensure you have the following:
- An Ubuntu 18.04 LTS server, which could be hosted on a UK Windows VPS, Windows Virtual Private Servers, or another Windows VPS Hosting UK solution.
- At least 2 GB of RAM and 2 CPUs for the master node.
- Root or sudo privileges on your server.
Step 1: Install Docker
Docker is a prerequisite for Kubernetes as it runs containerized applications. Install Docker by following these steps:
sudo apt update
sudo apt install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce -y
Once installed, start Docker and enable it to start at boot:
sudo systemctl start docker
sudo systemctl enable docker
Step 2: Install Kubernetes (kubeadm, kubelet, and kubectl)
To install Kubernetes components, follow these steps:
sudo apt update
sudo apt install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
sudo apt update
sudo apt install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
Step 3: Disable Swap
Kubernetes requires swap to be disabled on your system. You can disable swap by running:
sudo swapoff -a
To make this change permanent, edit the /etc/fstab
file and comment out any swap entries:
sudo nano /etc/fstab
Step 4: Initialize Kubernetes Control Plane
On the master node, initialize the Kubernetes control plane using kubeadm
:
sudo kubeadm init --pod-network-cidr=192.168.0.0/16
Once the initialization is complete, follow the instructions displayed on the screen to set up your environment. Run these commands as a regular user (not root):
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
Step 5: Install a Pod Network Add-on
To enable communication between the nodes in your cluster, you need to install a pod network add-on. In this example, we will use Calico:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Step 6: Join Worker Nodes to the Cluster
If you have additional nodes to add to your Kubernetes cluster, run the join command provided at the end of the kubeadm init
process on each worker node. The command looks like this:
sudo kubeadm join your-master-ip:6443 --token --discovery-token-ca-cert-hash sha256:
This command connects the worker nodes to the Kubernetes master.
Step 7: Verify the Kubernetes Cluster
Once your worker nodes are connected, verify the cluster status by running:
kubectl get nodes
You should see a list of nodes showing the status as "Ready".
Step 8: Deploy an Application on Kubernetes
To ensure Kubernetes is working properly, deploy a test application. For example, deploy an Nginx container:
kubectl create deployment nginx --image=nginx
To expose the deployment as a service, run:
kubectl expose deployment nginx --port=80 --type=NodePort
Check the status of the service:
kubectl get svc
Step 9: Secure Your Kubernetes Cluster with SSL (Optional)
If you want to secure your Kubernetes cluster with SSL, you can configure Let's Encrypt with your Nginx ingress. First, install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Conclusion
By following these steps, you have successfully installed Kubernetes and Docker on Ubuntu 18.04 LTS. Whether you’re using Kubernetes on a Windows VPS UK, Windows VPS Italy, or another Windows Virtual Private Server Hosting, Kubernetes provides an efficient platform for managing containerized applications.