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.

Once installed we already have a running k3s agent, to check it we just write some:

Image for post
Image for post
Here we can see our single node

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.

Simple storage class configuration & validation

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.

Let's use some basic helm commands

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

Image for post
Image for post
We can see all posible options for mysql on helm repos

Once we choosed our chart stable/mysql we are going to customize it with some basic values like: persistence and default users.

This file is a basic example of wich customization we can make to our charts

Once created our values file we proceed to install it

Once writed this command you will se the output below
Image for post
Image for post
The output shows what helm did on the background(created a deployment, a service, a secret, persistent volume)

Check the installation with:

helm list

Image for post
Image for post
We can identify our deployment with the label we specified when running helm install

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

You have to open a second terminal to check your connection or end you port-forward command with &
Image for post
Image for post
This is a successful message of the port-forward
Image for post
Image for post
That’s it, with some simple steps we created a mysql deployment on kubernetes using helm

Written by

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store