K3s: smallest K8s on your local
Published: 2024-04-16 08:32:01

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cld1tloq6juu4csbxff.jpg)

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 

{% embed https://youtu.be/8U8c2R3WeTA %}

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/52tkppdp4i1w02cninor.png)

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

![K3s app actions](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5tf3qqfm9hado92ev9qx.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0an98kas7irzrbgtgm2t.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy0mwuin4fhw9fgwq5u6.png)

![Kubernetes namespaces](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0iy3kz808vrddhdiv6by.png)

## MacOS, as usual...

![MacOS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x9umab886ai095tyicvw.jpg)

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
``` 

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ogr3jd54wb8538c4hbaw.png)

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


![Find Jenkins chart](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sc8kzjsa3m2c11zji27j.png)

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
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y99z1qghc27xblpozi59.png)

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/"
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4j9zp4wws1ml33abw4v.png)

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/