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
- VirtualBox
- 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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
# All Vagrant configuration is done below. The "2" in Vagrant.configure | |
# configures the configuration version (we support older styles for | |
# backwards compatibility). Please don't change it unless you know what | |
# you're doing. | |
Vagrant.configure("2") do |config| | |
# The most common configuration options are documented and commented below. | |
# For a complete reference, please see the online documentation at | |
# https://docs.vagrantup.com. | |
# Every Vagrant development environment requires a box. You can search for | |
# boxes at https://vagrantcloud.com/search. | |
config.vm.box = "generic/alpine312" | |
# Disable automatic box update checking. If you disable this, then | |
# boxes will only be checked for updates when the user runs | |
# `vagrant box outdated`. This is not recommended. | |
# config.vm.box_check_update = false | |
# Create a forwarded port mapping which allows access to a specific port | |
# within the machine from a port on the host machine. In the example below, | |
# accessing "localhost:8080" will access port 80 on the guest machine. | |
# NOTE: This will enable public access to the opened port | |
# config.vm.network "forwarded_port", guest: 80, host: 8080 | |
# Create a forwarded port mapping which allows access to a specific port | |
# within the machine from a port on the host machine and only allow access | |
# via 127.0.0.1 to disable public access | |
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" | |
# Create a private network, which allows host-only access to the machine | |
# using a specific IP. | |
config.vm.network "private_network", ip: "192.168.33.90" | |
# Create a public network, which generally matched to bridged network. | |
# Bridged networks make the machine appear as another physical device on | |
# your network. | |
# config.vm.network "public_network" | |
# Share an additional folder to the guest VM. The first argument is | |
# the path on the host to the actual folder. The second argument is | |
# the path on the guest to mount the folder. And the optional third | |
# argument is a set of non-required options. | |
# config.vm.synced_folder "../data", "/vagrant_data" | |
# Provider-specific configuration so you can fine-tune various | |
# backing providers for Vagrant. These expose provider-specific options. | |
# Example for VirtualBox: | |
# | |
config.vm.provider "virtualbox" do |vb| | |
# # Display the VirtualBox GUI when booting the machine | |
# vb.gui = true | |
# | |
# # Customize the amount of memory on the VM: | |
vb.memory = "2048" | |
end | |
# | |
# View the documentation for the provider you are using for more | |
# information on available options. | |
# Enable provisioning with a shell script. Additional provisioners such as | |
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the | |
# documentation for more information about their specific syntax and use. | |
# config.vm.provision "shell", inline: <<-SHELL | |
# apt-get update | |
# apt-get install -y apache2 | |
# SHELL | |
end |
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
Run kubectl apply -f https://k8s.io/examples/controllers/nginx-deployment.yaml
- 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)
apiVersion: v1 | |
kind: Service | |
metadata: | |
name: nginx-service | |
spec: | |
type: NodePort | |
selector: | |
app: nginx | |
ports: | |
# By default and for convenience, the `targetPort` is set to the same value as the `port` field. | |
- port: 80 | |
targetPort: 80 | |
# Optional field | |
# By default and for convenience, the Kubernetes control plane will allocate a port from a range (default: 30000-32767) | |
nodePort: 30007 |
- 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.
Top comments (0)