Cheap and local Kubernetes playground with K3s & Helm
If you are addressing to work with microservices you’ve better start getting familiar with kubernetes, this uber powerful container orchestation technology that everyone is excited about.
To use a kubernetes cluster you either have to install minikube(a virtual machine running a single kubernetes node) or expend a couple of dollars on some cloud managed kubernetes like GKE or AKS.
Either option can be a little expensive for some labs & playgrounds, while minikube keeps things local it is a little of a pain (virtual machines dude..), but this is not something I’ve figured out, it is something that people smarter than me already figured out so they created k3s.
Rancherlabs describe k3s as:
Lightweight Kubernetes, easy to install. A binary of less than 40 MB. Only 512 MB of RAM required to run.
And they don’t lie with such a big premise.
Installing
Really...? well let's do it, we are going to follow the recommmended steps for installing k3s in our local.
Validating the cluster
Once installed we already have a running k3s agent, to check it we just write some:
Creating a storage class for your cluster
To make our local cluster even more functional we need to add a storage, so we will be using rancher's local-path-provisioner a local path storage for your k3s cluster.
Installing helm
Helm is a package manager for kubernetes, basically is a powerful tooling for abstracting deployments into charts this makes easy to manage complex deployments; wich usually consist of multiple kubernetes objects(secrets, ingress, services, pods etc..) into versionable units of work.
Link Helm with tiller
Play a little with helm
Let's use some basic helm commands
Look for helm charts
For our test we are going to deploy a MySQL database, let's search for a mysql chart. To search we will use the command helm list followed by what we are searching(in this case mysql).
helm search mysql
Make some test deployment on Helm
Once we choosed our chart stable/mysql we are going to customize it with some basic values like: persistence and default users.
Once created our values file we proceed to install it
Check the installation with:
helm list
Check the connection
To check the MySQL connection we are going to use port-forwarding to enable a connection from our machine to the service
Summary
We saw how can we use some simple configurations to run a local kubernetes cluster using k3s and how to use a basic helm commands to deploy a database, this is only the beginning of the things you can do with k3s, helm and your laptop/desktop.