This tutorial shows you how to install k3s to run Kubernetes cluster locally on our Linux machine, we will also be deploying a Docker container in our kubernetes container.
What is Kubernetes?
For now all we need to know is that we like to deploy our application in containers, to provide a isolated enviroment for them, which is great because now you have a one container that has all the dependencies needed to run that application we can take that docker conatiner and use it on any OS without any issues.
But what happens when you have, let’s say 10000 containers, for example this is tinder, now imagine you have to manage that yourself, does not sounds, so for this we have kubernetes, Kubernetes is a container orchestration tool, that means it helps you in container management.
How to use kubernetes?
There are cloud providers like AWS or Google Cloud that provides managed kubernetes services that you can use but if you are starting and it might not be the best choice.
For that, we will start with a local kubernetes cluster. You have lots of tools out there to help you like minikube, k3s, kind, etc. For this tutorial we will use k3s. If you want to read about them and there use cases this blog from thechief might be a good read.
Setting up K3s
I’m using Linux (ubnutu) for this tutorial.
Run the following command in your terminal, to install the k3s.
Additional utilities will be installed, including kubectl
, crictl
, ctr
, k3s-killall.sh
, and k3s-uninstall.sh
.
|
|
Note that this command will install latest version of kubernetes.
To check whether the installation is completed or not, run:
|
|
Now you’ve k3s working but we still need to configure few parts.
|
|
To verify that k3s has been installed successfully, and configured run:
|
|
Optional, run if you get a permission denied
|
|
How to use Kubernetes?
Now, create a new directory, and create a new file deployment.yaml
and service.yaml
and run the following commands.
These commands will generate dry run for you and saves it in the files.
|
|
Now to verify if everything is working, run these command, you will see one deployment (named nginx) and two services (kubernetes and nginx).
|
|
Now, In services, you will see there is a PORT for nginx like 80:<PORT>/TCP
.
Visit localhost:<PORT>
, you’ll find the nginx page. And finally we have deployed nginx successfully🎉 🎉 🎉.
Things we have learned today is:
- Docker Container Images
- Kubernetes Deployments
- Kubernetes Services
- Kubectl Dry Run