Setup Kubernetes Development Environment using Vagrant and K3s

Easy way to setup your development environment

You need install some tools first and please refer to their official websites to setup into your PC or computer since it will have different steps if have different operating system.

Prerequisite

  1. VirtualBox
  2. Vagrant

If you want install VirtualBox please visit here: https://www.virtualbox.org/wiki/Downloads and select with the correct package that same with your operating system.

For Vagrant, you can check in here: https://www.vagrantup.com/downloads

Prepare the Vagrantfile

You can choose to use directly the Vagrantfile that I’ve created or create it from scratch, since I will provide you to create it.

  • Please make sure where you want to store the Vagrantfile
  • Open terminal/powershell/cmd and make sure the current directory is correct.
  • Run vagrant init
  • Open the Vagrantfile
  • Update the section of config.vm.box from base to generic/alpine312 , I decide to use alpine as my base box, you can choose another box that you are more familiar with.
  • Since I will try to connect into the development environment from host, I open an address so I can access my development environment.
  • Don’t forget to update the memory limit, you can customize it based on your requirements.

Here is the final Vagrantfile

Start setup K3s

  • Deploy the vagrant use vagrant up and wait until finished (the output maybe different)vagr.
  • Connect to the environment use vagrant ssh
  • Install K3s (please refer into the official website: https://k3s.io/ if it’s different step with the step in here) — it will take a while
  • Check the nodes (By default you need to go root for checking)
  • Try deploy nginx
  • Check the deployment, kubectl get deployment
  • Wait until it deployed, you can check again use the same command, wait until Ready 3/3. But you also can wait the pods status with kubectl get po -w (to exit use Ctrl+C)
  • Setup service for access the nginx (You can use below files)
  • Apply with kubectl apply -f example, kubectl apply -f nginx-service.yaml
  • Check the service
  • Check the browser (Please check the IP with that you’ve setup at Vagrantfile and the port with your setup at nodePort .

Summary

So, it’s easy enough, right? But it will need many internet connection (in case you have limited access). But, if you have any errors or another things you can ask me too.

Thank you for reading! Any comments? Please tell me.

12