Setting up Kubernetes on Ubuntu streamlines your infrastructure, turning it into a robust container orchestration system. With Kubernetes (K8s), you can automate the deployment, scaling, and operation of application containers,
simplifying management for developers and system administrators.
In this article, you will learn how to install and use Kubernetes on Ubuntu. You will see how to create different types of clusters for different purposes. This article will show you how to make your Kubernetes cluster work smoothly.
Refresh Your System: First, refresh your system to make sure all packages are current.
sudo apt-get update
sudo apt-get upgrade -y
Get Docker: Kubernetes needs Docker to run application containers. Get Docker on every machine by executing the command below:
sudo apt-get install docker.io -y
After getting Docker, put your user in the Docker group to use Docker commands without sudo.
sudo usermod -aG docker $USER
Turn Off Swap: Kubernetes needs you to turn off swap on every machine.
sudo swapoff -a
To keep this change, remove any swap lines in /etc/fstab.
Get the Kubernetes package repository on every machine by running the command:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add –
echo “deb http://apt.kubernetes.io/ kubernetes-xenial main” | sudo tee /etc/apt/sources.list.d/kubernetes.list
Now, get kubeadm, kubelet, and kubectl also on every machine via the commands:
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
Fix their versions to stop automatic updates.
sudo apt-mark hold kubelet kubeadm kubectl
To set up the cluster, run kubeadm on the master node.
sudo kubeadm init –pod-network-cidr=192.168.0.0/16 Then, the instructions on the screen will be able to show you how to use your cluster. Usually, you need to run these commands as a normal user.
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf HOME/.kube/configsudochown(id -u):$(id -g) $HOME/.kube/config
To make your pods talk to each other, you need a pod network add-on on your cluster. Many people use Calico for this. You can install it with:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
You need to use the kubeadm join command to connect worker nodes to your cluster. This command is given to you when the master is done setting up. Run this command on every worker node:
sudo kubeadm join
Your cluster is working now, so you can deploy apps. You can begin by deploying a simple app using a deployment YAML file:
– name: nginx
– containerPort: 80
To deploy this, run this command: kubectl apply -f
Change the size of your applications by changing the replica count in your deployment. Use kubectl, the command-line tool for Kubernetes, to control your cluster resources. Learn how to deploy more advanced applications, install Kubernetes Dashboard for a graphical interface, and think about using Helm for managing packages.