My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more
Lightweight Kubernetes development with k3s and Okteto

Lightweight Kubernetes development with k3s and Okteto

Ramiro Berrelleza's photo
Ramiro Berrelleza
·Mar 5, 2019

A couple of days ago, Rancher labs released k3s, a lightweight, fully compliant production-grade Kubernetes. The entire thing runs out of a 40MB binary, runs on x64 and ARM, and even from a docker-compose. Saying that this is a great engineering feat is an understatement.

I tried it out as soon as I saw the announcement. I expected their initial release to show promise, but to be rough around the edges. Was I in it for a surprise!

I decided to go with the docker-compose way so I didn’t have to deal with downloads, configs, and all that. I went ahead, got the compose manifest, and launched it.

$ mkdir ~/k3s
$ curl https://raw.githubusercontent.com/rancher/k3s/master/docker-compose.yml > ~/k3s/docker-compose.yml
$ cd ~/k3s
$ docker-compose up -d
Starting k3s_node_1   ... done
Starting k3s_server_1 ... done

After about 30 seconds, I had my k3s instance up and running.

$ export KUBECONFIG=~/k3s/kubeconfig.yaml
$ kubectl --kubeconfig kubeconfig.yaml get node                                                              (k3s/default)
NAME           STATUS   ROLES    AGE     VERSION
df305e6358a6   Ready    <none>   5m16s   v1.13.3-k3s.6

k3s’ docker-compose drops the kubeconfig file in the same folder you started it at. Great pattern!

We built okteto to quickly create development environments in your kubernetes cluster. k3s is a fully compliant Kubernetes distro. Will they work together? Only one way to figure it out (full disclosure: I’m one of Okteto's founders).

For this experiment, I went with the movies app sample. I cloned the repository and deployed the app with kubectl.

$ git clone https://github.com/okteto/samples.git
$ cd samples/react-kubectl
$ kubectl apply -f manifests
deployment.extensions/movies created
service/movies created
$ kubectl get pods
NAME                     READY   STATUS    RESTARTS   AGE
movies-7cd9f9ddb-sflwf   1/1     Running   0          55s

Once the application is ready, I used okteto to launch my development environment in my k3s instance (install okteto from here).

$ cd movies
$ okteto up
 ✓  Environment activated!
    Ports:
       9000 -> 9000
       9001 -> 9001
    Cluster:     default
    Deployment:  default/movies

After a couple of seconds, my development environment was up and running. I opened a second terminal and used the okteto run start command to start the application directly in the development environment:

$ export KUBECONFIG=~/k3s/kubeconfig.yaml
$ okteto run start
yarn run v1.6.0
$ CHOKIDAR_USEPOLLING=1 parcel src/index.html --port 9000 --hmr-port 9001
Server running at http://localhost:9000
✨  Built in 8.21s.

With the application now running (using parcel), I fired up my browser and went to localhost:9000 to see the app in all its high-res glory.

movieapp.png

Finally, I went ahead and did some mock dev work to try my entire workflow. I opened vscode, updated the title of the page (src/App.jsx line 22) to Ramiro's Mega Movie Site, saved it and went back to the browser. The changes were automatically reloaded (thanks to parcel's hot reloader) without having to build a container, pick a tag, redeploy it or even refresh my browser! 😎

look-ma-no-hands.gif

Conclusion

k3s is an amazing product. It has some issues (I couldn't get outbound network connections to work). But If this is the first release, I can't wait and see what they come up with in the near future.

Kudos to the team at Rancher for taking the fully compliant approach. With this, their users can leverage the entire ecosystem from day one!

Interested in improving your Kubernetes and Docker development workflows? Contact Okteto and stop waiting for your code to build and redeploy.