Are you looking for an easy guide for installing Kubernetes 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
- Pre-Install Ubuntu 22.04 System
- SSH access to your Ubuntu 22.04
- Sudo user with admin access
- Internet Connectivity
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 -
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.
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
Now run following kubectl commands to start interacting with Kubernetes.
$ kubectl get nodes $ kubectl cluster-info
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
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
Now access nginx-app using its nodeport, run
$ curl http://<Your-Ubuntu-22-04-IP-Address><NodePort>
Output above confirms that we are able to access our nginx based application.
That’s all from this guide, I believe you have found it useful and informative. Feel free to post your queries and feedback in below comments section.
Also Read : How to Install Kubernetes Dashboard Using Helm