Setting Up a Unified Development Environment for Kube-OVN Using Vagrant and VirtualBox
This article explains how to use Vagrant and VirtualBox to create a reproducible development and testing environment for the Kube-OVN Kubernetes CNI project, including Vagrantfile configuration, provisioning scripts for Docker, Kubernetes tools, Go, and steps to compile, test, and run Kube-OVN with Kind clusters.
Introduction
Kube-OVN is a Kubernetes networking project built on OVS/OVN that brings mature OpenStack networking features to Kubernetes, greatly improving security, operability, manageability, and performance.
This series shares the kube-ovn-controller, Pod IP management, CNI plugin, security groups, and a unified Vagrant-based development and testing environment.
Author: Kube-OVN community contributor Mr. Li
Author's Note
Compiling and testing various Go projects can be painful because each project may require a different set of dependencies and environments. Inspired by the Cilium project's use of Vagrant to provide a unified development environment, the author adopted Vagrant for Kube-OVN.
What is Vagrant?
Vagrant is a tool for building reproducible virtual development environments using providers such as VirtualBox.
Kube-OVN Vagrant Development VM
Install VirtualBox and Vagrant
Installation steps are omitted.
Write the Vagrantfile
a. Create the working directory:
mkdir /d/vagrant/myproject/kube-ovn
cd /d/vagrant/myproject/kube-ovnb. Create the Vagrantfile :
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/impish64"
config.vm.box_version = "20211211.0.0"
config.vm.provider "virtualbox" do |vb|
vb.memory = "4096"
vb.cpus = 4
end
config.vm.provision "shell", path: "./provision-vagrant-with-sudo.sh"
config.vm.provision "shell", privileged: false, path: "./provision-vagrant.sh"
endThe base box is ubuntu/impish64:20211211.0.0 , using VirtualBox with 4 CPU cores and 4 GB RAM. Two provisioning scripts run on startup: one with root privileges and one as the vagrant user.
Write provision-vagrant-with-sudo.sh
This script installs the basic build environment, Docker, kubectl, Kind, and the g tool.
#!/bin/bash
set -e
VERSION="1.17.5"
echo "Install packages..."
sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list
apt-get update
apt-get install -y \
apt-transport-https \
gnupg-agent \
gcc \
make \
pip
pip install j2cli
# install docker-ce
echo "Install docker..."
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt-cache madison docker-ce
apt-get install -y docker-ce docker-ce-cli containerd.io
gpasswd -a vagrant docker
newgrp docker
# enable and start docker
systemctl enable docker
systemctl enable containerd
systemctl restart docker
# install kubectl
echo "Install kubectl..."
wget -q -t 3 --retry-connrefused https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
chmod +x kubectl
mv kubectl /usr/local/bin/
# install kind
echo "Install kind..."
wget -q -t 3 --retry-connrefused https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64 -O kind
chmod +x kind
mv kind /usr/local/bin/
# install g
echo "Install g..."
wget -q -t 3 --retry-connrefused https://github.com/voidint/g/releases/download/v1.2.1/g1.2.1.linux-amd64.tar.gz
tar -xzf g1.2.1.linux-amd64.tar.gz -C /usr/local/bin/
chmod +x /usr/local/bin/g
rm -f g1.2.1.linux-amd64.tar.gz
HOME="/home/vagrant"
{
echo '# ===== set g environment variables ====='
echo 'export GOROOT=${HOME}/.g/go'
echo 'export GOPATH=${HOME}/go'
echo 'export GOPROXY=https://goproxy.cn'
echo 'export PATH=${HOME}/.g/go/bin:${GOPATH}/bin:$PATH'
echo 'export G_MIRROR=https://golang.google.cn/dl/'
} >> "$HOME/.bashrc"
# set sudo to not reset env
echo "Defaults !env_reset" >> /etc/sudoers.d/vagrantWrite provision-vagrant.sh
This script runs as the vagrant user, switches Go versions, clones the Kube-OVN source, and performs compilation and testing.
#!/bin/bash
set -e
GOVERSION="1.17.5"
HOME="/home/vagrant"
export GOROOT=${HOME}/.g/go
export GOPATH=${HOME}/go
export GOPROXY=https://goproxy.cn
export PATH=${HOME}/.g/go/bin:${GOPATH}/bin:$PATH
export G_MIRROR=https://golang.google.cn/dl/
# install go by g
echo "Install go..."
goversion=$(go version | { read _ _ v _; echo ${v#go}; })
if [ "x${goversion}" != "x${GOVERSION}" ]; then
g install ${GOVERSION} || true
g use ${GOVERSION}
sudo ln -sf ${HOME}/.g/go/bin/go /usr/local/bin/go
sudo ln -sf ${HOME}/.g/go/bin/gofmt /usr/local/bin/gofmt
fi
# kube-ovn preparation
echo "Prepare kube-ovn..."
mkdir -p ${GOPATH}/{src,pkg,bin}
go install github.com/securego/gosec/cmd/gosec@latest
go install github.com/onsi/ginkgo/ginkgo@latest
sudo ln -sf ${GOPATH}/bin/gosec /usr/local/bin/gosec
sudo ln -sf ${GOPATH}/bin/ginkgo /usr/local/bin/ginkgo
# (optional) clone and build kube-ovn – uncomment as needed
# mkdir -p ${GOPATH}/src/github.com/kubeovn
# cd ${GOPATH}/src/github.com/kubeovn
# git clone https://github.com/kubeovn/kube-ovn.git
# cd kube-ovn
# sudo make release
# sudo make ut
# sudo make kind-init
# sudo make kind-install
# sudo make e2eCreate and Use the Vagrant VM
cd /d/vagrant/myproject/kube-ovn
# Bring up the VM
vagrant up
# SSH into the VM
vagrant sshCompile and Test Kube-OVN Inside the VM
# Create workspace
mkdir -p /home/vagrant/go/src/github.com/kubeovn
cd /home/vagrant/go/src/github.com/kubeovn
# Clone the project
git clone https://github.com/kubeovn/kube-ovn.git
cd kube-ovn
# Checkout a specific version (v1.9.0 for Go 1.17)
git checkout v1.9.0
# Build release binary
sudo make release
# Run unit tests
sudo make ut
# Run Kind cluster tests
sudo make kind-init
sudo make kind-install
sudo make e2eKind Cluster Test Overview
After executing sudo make kind-install , a Kind cluster with Kube-OVN components is automatically deployed inside the Vagrant VM, allowing end‑to‑end testing of the networking stack.
Images in the original article illustrate the deployed resources and cluster status.
Conclusion
By customizing a Vagrantfile and provisioning scripts, developers can quickly spin up a consistent development and testing environment for Kube-OVN, and use Kind to create Kubernetes clusters for further validation.
Cloud Native Technology Community
The Cloud Native Technology Community, part of the CNBPA Cloud Native Technology Practice Alliance, focuses on evangelizing cutting‑edge cloud‑native technologies and practical implementations. It shares in‑depth content, case studies, and event/meetup information on containers, Kubernetes, DevOps, Service Mesh, and other cloud‑native tech, along with updates from the CNBPA alliance.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.