DEV Community

Bervianto Leo Pratama
Bervianto Leo Pratama

Posted on • Originally published at berviantoleo.Medium on

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

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.

Vagrantfile basic

  • Since I will try to connect into the development environment from host, I open an address so I can access my development environment.

IP Address setup

  • Don’t forget to update the memory limit, you can customize it based on your requirements.

VM Memory

Here is the final Vagrantfile

Start setup K3s

  • Deploy the vagrant use vagrant up and wait until finished (the output maybe different)vagr.

Vagrant up

  • Connect to the environment use vagrant ssh

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

Installing K3s

  • Check the nodes (By default you need to go root for checking)

Check node

  • Try deploy nginx

Run kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml

  • Check the deployment, kubectl get deployment

Check 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)

Deployment ready

Wait pods

  • Setup service for access the nginx (You can use below files)
  • Apply with kubectl apply -f example, kubectl apply -f nginx-service.yaml

Created

  • Check the service

Service lists

  • Check the browser (Please check the IP with that you’ve setup at Vagrantfile and the port with your setup at nodePort .

Nginx deployed!

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.

Photo by Kelly Sikkema on Unsplash

Top comments (0)