Kubernetes Installation on Ubuntu

Introduction

Kubernetes, often abbreviated as K8s, is a powerful open-source platform for managing containerized applications. Whether you are a developer, system administrator, or tech enthusiast, mastering Kubernetes can revolutionize how you deploy and scale applications. This guide will walk you through the Kubernetes installation on Ubuntu, ensuring you have a functional Kubernetes cluster ready for use.

Prerequisites

Before diving into the installation process, ensure you have the following:

  • Ubuntu Version: A supported version of Ubuntu (20.04 or later is recommended).

  • Access Privileges: Root or sudo access to the system.

  • Hardware Requirements:

    • At least 2 CPUs.

    • 2 GB of RAM or more.

    • 10 GB of free disk space.

  • Network Configuration:

    • Stable internet connection.

    • Disable swap space (sudo swapoff -a).

Step-by-Step Guide to Kubernetes Installation on Ubuntu

1. Update Your System

Keeping your system up-to-date ensures smooth installation and compatibility.

sudo apt update && sudo apt upgrade -y

2. Install Docker

Kubernetes relies on a container runtime, and Docker is one of the most popular choices.

Install Docker CE

sudo apt install -y apt-transport-https ca-certificates curl software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg sudo add-apt-repository "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt update sudo apt install -y docker-ce

Verify Docker Installation

docker --version

3. Install Kubernetes Tools

Install the essential tools: kubeadm, kubelet, and kubectl.

Add Kubernetes Repository

sudo apt-get update sudo apt-get install -y apt-transport-https curl curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add - echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list sudo apt-get update

Install kubeadm, kubelet, and kubectl

sudo apt-get install -y kubelet kubeadm kubectl sudo apt-mark hold kubelet kubeadm kubectl

4. Initialize Kubernetes Cluster

Use kubeadm to set up the control plane node.

Pull Kubernetes Images

sudo kubeadm config images pull

Initialize the Cluster

sudo kubeadm init --pod-network-cidr=192.168.0.0/16

Set Up kubeconfig

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

5. Install a Pod Network Add-On

Kubernetes requires a network add-on for inter-pod communication. Here, we’ll use Calico.

Deploy Calico

kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml

6. Join Worker Nodes

To add worker nodes, use the token generated during initialization.

sudo kubeadm join <control-plane-host>:<port> --token <token> \ --discovery-token-ca-cert-hash sha256:<hash>

Examples of Kubernetes in Action

Deploying a Sample Application

Create a Deployment

kubectl create deployment nginx --image=nginx

Expose the Deployment

kubectl expose deployment nginx --port=80 --type=NodePort

Access the Application

Find the NodePort and access your application via http://<node-ip>:<node-port>.

Scaling the Application

Increase the number of replicas.

kubectl scale deployment nginx --replicas=3

Monitoring Pods

View the status of your pods.

kubectl get pods

FAQ

1. What is Kubernetes?

Kubernetes is an open-source platform for automating deployment, scaling, and operations of application containers across clusters of hosts.

2. Why use Kubernetes on Ubuntu?

Ubuntu provides a stable and user-friendly environment, making it ideal for running Kubernetes.

3. How do I reset a Kubernetes cluster?

Use the following command:

sudo kubeadm reset

4. Can I install Kubernetes without Docker?

Yes, Kubernetes supports other container runtimes like containerd and CRI-O.

kubernetes installation on ubuntu


External Resources

Conclusion

By following this guide, you have successfully completed the Kubernetes installation on Ubuntu. With your cluster up and running, you can now deploy, manage, and scale your applications efficiently. Dive deeper into Kubernetes and unlock its full potential to optimize your workflows! Thank you for reading the huuphan.com page!

Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

How to Install Python 3.13

Bash script list all IP addresses connected to Server with Country Information