Setup Kubernetes Development Environment using Vagrant and K3s
Tags: virtualbox, vagrant, k3, devops
Published: 2021-07-11 09:42:45

---
title: Setup Kubernetes Development Environment using Vagrant and K3s
published: true
date: 2021-07-11 05:55:03 UTC
tags: virtualbox,vagrant,k3,devops
canonical_url: https://berviantoleo.medium.com/setup-kubernetes-development-environment-using-vagrant-and-k3s-9d3273589c44
---

#### 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](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](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

![](https://cdn-images-1.medium.com/max/677/1*GVDubB4v0AybNX0mimUn1Q.png)<figcaption>Vagrant init</figcaption>

- 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.

![](https://cdn-images-1.medium.com/max/666/1*olr4Rkwzig4jJXUO-L7npw.png)<figcaption>Vagrantfile basic</figcaption>

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

![](https://cdn-images-1.medium.com/max/635/1*TWeU_fHbVPbUM6__9WQZ1w.png)<figcaption>IP Address setup</figcaption>

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

![](https://cdn-images-1.medium.com/max/768/1*Y5YnAuVQaHNv6uQ6w-OUWQ.png)<figcaption>VM Memory</figcaption>

Here is the final Vagrantfile

{% gist https://gist.github.com/berviantoleo/7086ee0b1648eed8b935c4b3957d4ad4 %}

### Start setup K3s

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

![](https://cdn-images-1.medium.com/max/1024/1*RJzvRmaXwkpJd66KX3EXGQ.png)<figcaption>Vagrant up</figcaption>

- Connect to the environment use vagrant ssh

![](https://cdn-images-1.medium.com/max/526/1*TdDhk4kXpSMWC7fDBCxmzQ.png)<figcaption>Vagrant ssh</figcaption>

- Install K3s (please refer into the official website: [https://k3s.io/](https://k3s.io/) if it’s different step with the step in here) — it will take a while

![](https://cdn-images-1.medium.com/max/1024/1*LLeRujmiXz9AcQW_llwHtw.png)<figcaption>Installing K3s</figcaption>

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

![](https://cdn-images-1.medium.com/max/787/1*JWPRZ4H_uWHlgQf917wUHg.png)<figcaption>Check node</figcaption>

- Try deploy nginx

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

- Check the deployment, kubectl get deployment

![](https://cdn-images-1.medium.com/max/580/1*VKQjH1BwS0UXQ-p3nwkiOA.png)<figcaption>Check deployment</figcaption>

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

![](https://cdn-images-1.medium.com/max/571/1*S3D47SAPRKb61RJAV1Pakw.png)<figcaption>Deployment ready</figcaption>

![](https://cdn-images-1.medium.com/max/803/1*zqv5e59gBX_95xIYFsplqQ.png)<figcaption>Wait pods</figcaption>

- Setup service for access the nginx (You can use below files)

{% gist https://gist.github.com/berviantoleo/a03c2dcb3150764124a8c050124db136 %}

- Apply with kubectl apply -f <filename> example, kubectl apply -f nginx-service.yaml

![](https://cdn-images-1.medium.com/max/584/1*L05t8-fLWZKOGJE_ki7bKQ.png)<figcaption>Created</figcaption>

- Check the service

![](https://cdn-images-1.medium.com/max/758/1*kCHy0WhQdamOi9KKE2segg.png)<figcaption>Service lists</figcaption>

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

![](https://cdn-images-1.medium.com/max/1024/1*J15amAUxhDaiFxZLWIoeSQ.png)<figcaption>Nginx deployed!</figcaption>

### 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.

![](https://cdn-images-1.medium.com/max/1024/0*zjYZwCWjC575bP9B)<figcaption>Photo by <a href="https://unsplash.com/@kellysikkema?utm_source=medium&amp;utm_medium=referral">Kelly Sikkema</a> on <a href="https://unsplash.com?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption>