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$ 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 the movies app sample. I cloned the repository and deployed the app with kubectl
.
$ git clone https://github.com/okteto/samples.git
$ cd samples/vote
$ kubectl apply -f manifests
deployment.extensions/vote created
service/vote 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).
$ okteto up
✓ Okteto Environment activated
✓ Files synchronized
✓ Your Okteto Environment is ready
Name: vote* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 899-835-619
With the application now running, I fired up my browser and went to http://localhost:8080 to see the app in all its high-res glory.
Finally, I went ahead and did some mock dev work to try my entire workflow. I opened vscode, modified the getOptions
function in app.py
with the following code, and saved my file:
def getOptions():
optionA = 'Otters'
optionB = 'Dogs'
return optionA, optionB
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! 😎
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.