How to Install Kubernetes Using K3s On Ubuntu 22.04

Are you looking for an easy guide for installing Kubernetes using K3s on Ubuntu 22.04?

A step-by-step guide on this page will explain how to install Kubernetes using k3s on Ubuntu 22.04.

Kubernetes is an open-source platform designed to automate the deployment, scaling, and management of containerized applications. It helps you abstract away the underlying infrastructure and provides a consistent way to deploy and manage your applications across various environments.

k3s, on the other hand, is a lightweight Kubernetes distribution built for resource-constrained environments. It is optimized for edge computing, IoT devices, CI/CD pipelines, and development environments. Despite its small footprint, k3s offers full Kubernetes functionality, making it an excellent choice for small-scale deployments.

Prerequisites for Install Kubernetes Using K3s

  • Pre-Install Ubuntu 22.04 System
  • SSH access to your Ubuntu 22.04
  • Sudo user with admin access
  • Internet Connectivity

Consider our VPS plans with Ubuntu 22 pre-installed and full root access.

Without any further delay, lets deep dive into Kubernetes installation using k3s.

1. Update System Packages

First, let’s ensure that all system packages are up to date. Open a terminal and run the following apt commands:$ sudo apt update $ sudo apt upgrade -y

2. Install k3s dependencies

Run beneath command to install curl and wget command for smooth k3s installation.$ sudo apt install curl wget -y

3. Install Kubernetes Using K3s on Ubuntu 22.04

Next, download and run k3s script which will setup the Kubernetes on your Ubuntu 22.04, run beneath curl command.

$ curl -sfL https://get.k3s.io | sh -
ngcb22

Above command may take couple of minutes depending on your internet speed. Once the command is executed successfully, we will get the output something like above.

Verify the K3s service, if everything went smoothly, you should see output indicating that the k3s service is active and running.

ngcb22

4. Access Kubernetes Cluster

To access and interact with Kubernetes cluster, we must first configure kubectl command that points to k3s API. Run the following set of commands one after the another.

$ mkdir ~/.kube 
$ sudo cp /etc/rancher/k3s/k3s.yaml ~/.kube/config && sudo chown $USER ~/.kube/config 
$ sudo chmod 600 ~/.kube/config && export KUBECONFIG=~/.kube/config
ngcb22

Now run following kubectl commands to start interacting with Kubernetes.$ kubectl get nodes $ kubectl cluster-info

ngcb22

Great, output above shows that out Kubernetes cluster is up and running.

5. Validate K3s Kubernetes Installation on Ubuntu 22.04

In order to validate k3s Kubernetes installation, try to deploy to a nginx based application and expose it via NodePort as shown below:

$ kubectl create deployment  nginx-app --image nginx --replicas 2
$ kubectl get deployment nginx-app 
$ kubectl get pods
ngcb22

Next, expose the nginx-app deployment using NodePort, execute following command.

$ kubectl expose deployment nginx-app --type NodePort --port 80 
$ kubectl get svc nginx-app
ngcb22

Now access nginx-app using its nodeport, run

$ curl http://<Your-Ubuntu-22-04-IP-Address><NodePort>
ngcb22

Output above confirms that we are able to access our nginx based application.

You have now learned how to install Kubernetes Using K3s on Ubuntu 22 Linux platform.

source: https://www.linuxtechi.com/install-kubernetes-using-k3s-on-ubuntu/

Tags: ,