Kubernetes Series(1): How to install Kubernetes in Ubuntu
Kevin Sheeran
Posted on April 28, 2023
Hi all, I recently learned some Docker key features and once in a while I come up with Kubernetes which really makes me wondering what is it and how does it work and what's the difference between Docker, so today I will guide you through clear the whole doubts.
What is Kubernetes?
Assuming you have learned Docker, if you don't know about Docker, it doesn't matter, I'll give you a example. Docker is like a container which put all of your stuff inside it, and in DevOps world, the stuff means your package applications and their dependencies, and you can run the container whatever you want in an isolated environment which make it easier to develop, test, and deploy applications across different environments. While Kubernetes is a platform for orchestrating and managing the containerized applications. It provides a higher-level abstraction that makes it easier to manage and scale containerized application in production.
How does it work?
As I mentioned above, Kubernetes is a powerful tool that automates the deployment, scaling, and management of containerized applications. So here is how it works:
The developer creates a containerized application using Docker, which packages the application and its dependencies into a portable container.
The developer defines the application's requirements, such as the number of replicas, resource requirements, and networking requirements, in a Kubernetes manifest file.
The Kubernetes master node receives the manifest file and uses it to create and manage the application's resources, such as pods, services, and replicasets.
Pods are the smallest deployable units in Kubernetes, and they contain one or more containers that share the same network namespace and can communicate with each other directly.
Services provide a stable IP address and DNS name for the pods, and they can load balance traffic to the pods based on labels.
Replicasets ensure that a specified number of replicas of a pod are running at all times, and they automatically scale up or down based on the application's resource requirements.
The Kubernetes master node monitors the state of the application's resources and automatically makes changes to ensure that the desired state is maintained.
If a pod fails or is terminated, the Kubernetes master node automatically replaces it with a new pod to maintain the desired number of replicas.
If the application's resource requirements change, such as increased traffic or resource-intensive tasks, Kubernetes can automatically scale up the number of replicas to meet the demand.
Kubernetes also provides advanced features such as rolling updates, which allow updates to be rolled out gradually to minimize downtime, and canary deployments, which allow new versions of the application to be tested on a small subset of users before being rolled out to everyone.
How to install it in Ubuntu?
- Update your Ubuntu system using the following commands:
sudo apt-get update
sudo apt-get upgrade
- Install Docker on your Ubuntu system by running the following commands:
sudo apt-get install docker.io
sudo systemctl start docker
sudo systemctl enable docker
- Add the Kubernetes apt repository key by running the following command:
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
- Add the Kubernetes apt repository to your system by running the following command:
sudo apt-add-repository "deb http://apt.kubernetes.io/ kubernetes-xenial main"
- Update your system again using the following command:
sudo apt-get update
- Install Kubernetes and its dependencies using the following command:
sudo apt-get install kubeadm kubelet kubectl
This will install Kubernetes, kubelet (the agent that runs on each node in the cluster), kubeadm (the tool used to bootstrap the cluster), and kubectl (the command-line tool used to interact with the cluster).
- Initialize the Kubernetes cluster using
kubeadm
by running the following command:
sudo kubeadm init
This will create the Kubernetes control plane on your master node.
Once the initialization is complete, kubeadm will output a kubeadm join command. Copy this command to your clipboard, as you will need to run it on your worker nodes to join them to the cluster.
Configure your kubectl command-line tool to connect to the Kubernetes API server by running the following command:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
This will create a directory for your kubectl configuration and copy the configuration file from your master node to your local machine.
- Deploy a pod network to the cluster using the following command:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
This will deploy the Flannel pod network to the cluster, which will allow pods to communicate with each other across different nodes.
That's it! You now have a Kubernetes cluster running on your Ubuntu system. You can add worker nodes to the cluster by running the kubeadm join command on each worker node, and you can deploy applications to the cluster using kubectl.
Posted on April 28, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.