Kubernetes Series(1): How to install Kubernetes in Ubuntu

kevinsheeranxyj

Kevin Sheeran

Posted on April 28, 2023

Kubernetes Series(1): How to install Kubernetes in Ubuntu

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:

  1. The developer creates a containerized application using Docker, which packages the application and its dependencies into a portable container.

  2. The developer defines the application's requirements, such as the number of replicas, resource requirements, and networking requirements, in a Kubernetes manifest file.

  3. 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.

  4. 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.

  5. Services provide a stable IP address and DNS name for the pods, and they can load balance traffic to the pods based on labels.

  6. 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.

  7. The Kubernetes master node monitors the state of the application's resources and automatically makes changes to ensure that the desired state is maintained.

  8. 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.

  9. 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.

  10. 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?

  1. Update your Ubuntu system using the following commands:
sudo apt-get update
sudo apt-get upgrade
Enter fullscreen mode Exit fullscreen mode
  1. 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
Enter fullscreen mode Exit fullscreen mode
  1. 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 -
Enter fullscreen mode Exit fullscreen mode
  1. 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"
Enter fullscreen mode Exit fullscreen mode
  1. Update your system again using the following command:
sudo apt-get update
Enter fullscreen mode Exit fullscreen mode
  1. Install Kubernetes and its dependencies using the following command:
sudo apt-get install kubeadm kubelet kubectl
Enter fullscreen mode Exit fullscreen mode

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).

  1. Initialize the Kubernetes cluster using kubeadm by running the following command:
sudo kubeadm init
Enter fullscreen mode Exit fullscreen mode

This will create the Kubernetes control plane on your master node.

  1. 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.

  2. 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
Enter fullscreen mode Exit fullscreen mode

This will create a directory for your kubectl configuration and copy the configuration file from your master node to your local machine.

  1. 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
Enter fullscreen mode Exit fullscreen mode

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.

💖 💪 🙅 🚩
kevinsheeranxyj
Kevin Sheeran

Posted on April 28, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

What was your win this week?
weeklyretro What was your win this week?

November 29, 2024

Where GitOps Meets ClickOps
devops Where GitOps Meets ClickOps

November 29, 2024

How to Use KitOps with MLflow
beginners How to Use KitOps with MLflow

November 29, 2024

Modern C++ for LeetCode 🧑‍💻🚀
leetcode Modern C++ for LeetCode 🧑‍💻🚀

November 29, 2024