DEV Community

Cover image for K3s: smallest K8s on your local
DevOps Pass AI for DevOps Pass AI

Posted on

K3s: smallest K8s on your local

Have you ever needed to play with Kubernetes on your local?
For K8s apps development or to test your changes in Helm chart or just for fun?

Recommended way for local Kubernetes is Minikube, but peronally I dont like it and let me explain why K3s + autok3s + K3d is your choise.

Why not Minikube

Your local with Minikube

Minikube, in the same way as many other local Kubernetes providers is annoying me in one way - it makes your laptop/PC dirty. Creates some sophisticated networking configurations, creates SystemD units, doing some unknown changes on local filesystem, install/update some tools you dont wanted to and so on.

My solution - use K3s with K3d provider, which will setup Kubernetes in your Docker and change nothing on your local. You can create multi node cluster and remove it next minute. And NOTHING will be changed on your local!

How to

If you prepere video

If not lets move step by step.

First of all you have to add Docker and K3s applications in DevOps Pass:

Docker and K3s applications

You can install Docker from DOP and move on with K3s.

K3s app actions

K3s app providing following actions:

  • Install autoK3s - start autok3s tool in your Docker
  • Setup k3d cluster - Setup local Kubernetes in Docker
  • Open autoK3s in Browser - open autok3s in your browser

autok3s is a tool, developed by Rancher, which allowing you to install K3s anywhere, currently supported AWS, Docker, GCP, etc. - https://github.com/cnrancher/autok3s

k3d is one of providers k3s can use, it setups Kubernetes cluster in your local Docker and you even can specify amount of nodes you want to run.

So install autok3s first, then click "Setup k3d cluster", wait until it appear "Running" in clusters list:

k3s clusters list

And done! You have Kubernetes cluster installed locally.

You can swithc to Kubernetes app and check if context exists and installed namespaces list:

Kubernetes contexts

Kubernetes namespaces

MacOS, as usual...

MacOS

As usual for MacOS there is one exception... Alike Windows or Linux you can not access Docker containers from local network, you have to install additional Brew package - https://github.com/chipmk/docker-mac-net-connect

It will allow you to connect your containers and K3s services/ingress'es from host machine:

# Install via Homebrew
$ brew install chipmk/tap/docker-mac-net-connect

# Run the service and register it to launch at boot
$ sudo brew services start chipmk/tap/docker-mac-net-connect
Enter fullscreen mode Exit fullscreen mode

Thats it, now you can forget about it.
If you're curious what is it: its Brew service written in Go, which refreshing MacOS routing table, to allow you access Docker networks from host machine. More details you can find in repo readme.

Install Jenkins via Helm

Go to Helm app in DOP, click "Addd Helm repo" action in right top and add Bitnami Helm repo - https://charts.bitnami.com/bitnami

Add Bitnami Helm repo

Then on "Helm Repo charts" tab find Jenkins chart:

Find Jenkins chart

Now "Actions -> Install Chaart", it will require some values, value should be in JSON format, i.e. if its string "..." if number 8083 if boolean true:

service.ports.https=8443
service.ports.http=8083
jenkinsUser="user"
jenkinsPassword="12345678"
agent.enabled=true
Enter fullscreen mode Exit fullscreen mode

Click "Install" and wait for Jenkins pod to be ready (you can open "default" namespace in K9s in Kubernetes app or just wait for a few mins):

K9s Jenkins pod

Now copy this to your console to get Jenkins URL:

export SERVICE_IP=$(kubectl get svc --namespace default jenkins --template "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}")
echo "Jenkins URL: http://$SERVICE_IP:8083/"
Enter fullscreen mode Exit fullscreen mode

Login to Jenkins and voila!

Removing K3s cluster

At the moment you dont need K8s cluster on your local, you can drop it. Navigate to K3s application, find cluster in the list at the bottom and find "Destroy" action.

Destroy k3s cluster

Thats it! Not even a hint of K8s on your local, you can forget about it till you'll need it again.

Summary

I hope that workshop was interresting for you we've created K8s cluster on your local, installed some Helm charts and dropped it.

No more broken semi-configured networking rules or services, no more waste on your local.

If you likes this article, give us πŸ‘ and start on GitHub 🀩 - https://github.com/devopspass/devopspass/

Top comments (0)