Cloud Native 13 min read

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.

Cloud Native Technology Community
Cloud Native Technology Community
Cloud Native Technology Community
Setting Up a Unified Development Environment for Kube-OVN Using Vagrant and VirtualBox

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<br/>cd /d/vagrant/myproject/kube-ovn

b. Create the Vagrantfile:

# -*- mode: ruby -*-<br/># vi: set ft=ruby :<br/>Vagrant.configure("2") do |config|<br/>  config.vm.box = "ubuntu/impish64"<br/>  config.vm.box_version = "20211211.0.0"<br/><br/>  config.vm.provider "virtualbox" do |vb|<br/>    vb.memory = "4096"<br/>    vb.cpus = 4<br/>  end<br/><br/>  config.vm.provision "shell", path: "./provision-vagrant-with-sudo.sh"<br/>  config.vm.provision "shell", privileged: false, path: "./provision-vagrant.sh"<br/>end

The 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<br/>set -e<br/>VERSION="1.17.5"<br/><br/>echo "Install packages..."<br/>sed -i "s/archive.ubuntu.com/mirrors.aliyun.com/g" /etc/apt/sources.list<br/>apt-get update<br/>apt-get install -y \
  apt-transport-https \
  gnupg-agent \
  gcc \
  make \
  pip<br/>pip install j2cli<br/><br/># install docker-ce<br/>echo "Install docker..."<br/>curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -<br/>add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"<br/>apt-cache madison docker-ce<br/>apt-get install -y docker-ce docker-ce-cli containerd.io<br/>gpasswd -a vagrant docker<br/>newgrp docker<br/><br/># enable and start docker<br/>systemctl enable docker<br/>systemctl enable containerd<br/>systemctl restart docker<br/><br/># install kubectl<br/>echo "Install kubectl..."<br/>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<br/>chmod +x kubectl<br/>mv kubectl /usr/local/bin/<br/><br/># install kind<br/>echo "Install kind..."<br/>wget -q -t 3 --retry-connrefused https://kind.sigs.k8s.io/dl/v0.11.1/kind-linux-amd64 -O kind<br/>chmod +x kind<br/>mv kind /usr/local/bin/<br/><br/># install g<br/>echo "Install g..."<br/>wget -q -t 3 --retry-connrefused https://github.com/voidint/g/releases/download/v1.2.1/g1.2.1.linux-amd64.tar.gz<br/>tar -xzf g1.2.1.linux-amd64.tar.gz -C /usr/local/bin/<br/>chmod +x /usr/local/bin/g<br/>rm -f g1.2.1.linux-amd64.tar.gz<br/>HOME="/home/vagrant"<br/>{<br/>  echo '# ===== set g environment variables ====='<br/>  echo 'export GOROOT=${HOME}/.g/go'<br/>  echo 'export GOPATH=${HOME}/go'<br/>  echo 'export GOPROXY=https://goproxy.cn'<br/>  echo 'export PATH=${HOME}/.g/go/bin:${GOPATH}/bin:$PATH'<br/>  echo 'export G_MIRROR=https://golang.google.cn/dl/'<br/>} >> "$HOME/.bashrc"<br/><br/># set sudo to not reset env<br/>echo "Defaults !env_reset" >> /etc/sudoers.d/vagrant

Write 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<br/>set -e<br/>GOVERSION="1.17.5"<br/>HOME="/home/vagrant"<br/>export GOROOT=${HOME}/.g/go<br/>export GOPATH=${HOME}/go<br/>export GOPROXY=https://goproxy.cn<br/>export PATH=${HOME}/.g/go/bin:${GOPATH}/bin:$PATH<br/>export G_MIRROR=https://golang.google.cn/dl/<br/><br/># install go by g<br/>echo "Install go..."<br/>goversion=$(go version | { read _ _ v _; echo ${v#go}; })<br/>if [ "x${goversion}" != "x${GOVERSION}" ]; then<br/>  g install ${GOVERSION} || true<br/>  g use ${GOVERSION}<br/>  sudo ln -sf ${HOME}/.g/go/bin/go /usr/local/bin/go<br/>  sudo ln -sf ${HOME}/.g/go/bin/gofmt /usr/local/bin/gofmt<br/>fi<br/><br/># kube-ovn preparation<br/>echo "Prepare kube-ovn..."<br/>mkdir -p ${GOPATH}/{src,pkg,bin}<br/>go install github.com/securego/gosec/cmd/gosec@latest<br/>go install github.com/onsi/ginkgo/ginkgo@latest<br/>sudo ln -sf ${GOPATH}/bin/gosec /usr/local/bin/gosec<br/>sudo ln -sf ${GOPATH}/bin/ginkgo /usr/local/bin/ginkgo<br/><br/># (optional) clone and build kube-ovn – uncomment as needed<br/># mkdir -p ${GOPATH}/src/github.com/kubeovn<br/># cd ${GOPATH}/src/github.com/kubeovn<br/># git clone https://github.com/kubeovn/kube-ovn.git<br/># cd kube-ovn<br/># sudo make release<br/># sudo make ut<br/># sudo make kind-init<br/># sudo make kind-install<br/># sudo make e2e

Create and Use the Vagrant VM

cd /d/vagrant/myproject/kube-ovn<br/># Bring up the VM<br/>vagrant up<br/># SSH into the VM<br/>vagrant ssh

Compile and Test Kube-OVN Inside the VM

# Create workspace<br/>mkdir -p /home/vagrant/go/src/github.com/kubeovn<br/>cd /home/vagrant/go/src/github.com/kubeovn<br/># Clone the project<br/>git clone https://github.com/kubeovn/kube-ovn.git<br/>cd kube-ovn<br/># Checkout a specific version (v1.9.0 for Go 1.17)<br/>git checkout v1.9.0<br/># Build release binary<br/>sudo make release<br/># Run unit tests<br/>sudo make ut<br/># Run Kind cluster tests<br/>sudo make kind-init<br/>sudo make kind-install<br/>sudo make e2e

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

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

KubernetesDevOpsCNIkindVagrantKube-OVN
Cloud Native Technology Community
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.