Lightweight Kubernetes development with k3s and Okteto
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.
k3s’ docker-compose drops the kubeconfig file in the same folder you started it at. Great pattern!
$ 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
Once your cluster is ready, install Rancher's local path provisioner, so we can use the local storage of your k3s node.
$ kubectl apply -f [https://gist.githubusercontent.com/rberrelleza/58705b20fa69836035cf11bd65d9fc65/raw/bf479a97e2a2da7ba69d909db5facc23cc98942c/local-path-storage.yaml](https://gist.githubusercontent.com/rberrelleza/58705b20fa69836035cf11bd65d9fc65/raw/bf479a97e2a2da7ba69d909db5facc23cc98942c/local-path-storage.yaml) $ kubectl get storageclass NAME PROVISIONER AGE local-path (default) rancher.io/local-path 50s
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 our Python Sample App. I cloned the repository and deployed the app with
$ git clone https://github.com/okteto/python-getting-started.git $ cd python-getting-started
$ kubectl apply -f manifests deployment.apps/hello-world created service/hello-world created
Once the application is ready, I used okteto to launch my development environment in my k3s instance (install okteto from here).
$ okteto up ✓ Development environment activated ✓ Files synchronized Name: hello-world SSH: 51553 -> 2222 Forward: 8080 -> 8080 Reverse: 3500 <- 3500 Starting hello-world server... * Serving Flask app "app" (lazy loading) * Environment: development * Debug mode: on * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
With the application now running, I fired up my browser and went to http://localhost:8080 to see the app up and running.
Finally, I went ahead and did some mock dev work to try my entire workflow. I opened the
app.py file in VS Code and modified the response message on line 7 to be Hello world from the cluster!. Save your changes.
@app.route('/') def hello_world(): return 'Hello world from the cluster!' }
I went back to the browser. The changes were automatically reloaded (thanks to python hot reloader) without having to build a container, pick a tag, redeploy it or even refresh my browser! 😎
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!