A Kubernetes development environment (KuDE) isolated to install, develop and tests Kubernetes from the Github source code, using a Vagrant Box. This Vagrant Box or Environment is for developers contributing the Kubernetes project.
Using a Kubernetes development environment using a Vagrant Box allows to:
- Automate the provisioning process, ensuring to have the same environment every time it is re-created
- Destroy the environment when it's not in use, to release resources. The environment will be exactly the same the next time it's created
- Use the same operative system (Ubuntu) and configuration by all the developers
- Use the IDE of our preference on your own computer
- Use the environment only to build and test your changes. You can turn it up or down whenever you want.
The first step to contribute to Kubernetes is to fork the Kubernetes projects on your Github account. Go to each of te following projects and click on the Fork button in the top-right corner.
- Kubernetes code: https://github.com/kubernetes/kubernetes
- Kubernetes Website and Documentation: https://github.com/kubernetes/website
- Kubernetes Testing Infrastructure: https://github.com/kubernetes/test-infra
To save time provisioning the environment, it's recommended to clone the forked Kubernetes projects mentioned above into the directory ./shared_folder/k8s.io
. Like this:
mkdir -p shared_folder/k8s.io
cd shared_folder/k8s.io
git clone https://github.com/<github_username>/kubernetes
git clone https://github.com/<github_username>/website
git clone https://github.com/<github_username>/test-infra
The requirements on any operative system are:
- Virtual Box and the Extension Pack version 6 or higher
- Vagrant version 2.2 or higher
Specifically on macOS X, you can install everything using brew
executing this:
brew install virtualbox virtualbox-extension-pack
brew install vagrant
On Ubuntu, you need nothing if you don't want an isolated environment.
Having forked the Kubernetes projects and installed all the requirements for an isolated environment you can have the Kubernetes Development Environment following these instructions:
- Create a directory to be use as workspace. Example:
./kude
- Export the environment variable
GITHUB_USER
with your Github username or organization name. - To save time provisioning the environment, it's recommended to clone the forked Kubernetes projects mentioned above into the directory
./kude/shared_folder/k8s.io
. - Download the
Vagrantfile
either from here or usingcurl
. You can also clone the repo but theVagrantfile
is all you need. - Execute
vagrant up
to provision the environment - Use your favorite IDE to open the Kubernetes projects, and to follow the Git workflow explained below.
- Execute
vagrant ssh
to login to the Vagrant box - If you don't need the environment and want to release resources, execute
vagrant destroy
Or, executing on a terminal the following commands:
mkdir -p ./kude/shared_folder/k8s.io
export GITHUB_USER=johandry
cd ./kude
curl -fsL https://raw.githubusercontent.com/johandry/kube-dev-env/main/Vagrantfile
cd ./shared_folder/k8s.io
git clone https://github.com/${GITHUB_USER}/kubernetes
git clone https://github.com/${GITHUB_USER}/website
git clone https://github.com/${GITHUB_USER}/test-infra
vagrant up
vagrant ssh
-
Clone this repository or download just the Vagranfile, then modify the Vagrantfile. The main sections in the file are:
- Parameters: They are self-descriptive variables located at the top of the file.
- Setup/Provisioning Script: It is located after the parameters in the variable
PROVISION_NODE
. These are all the shell instructions to execute to setup or provisioning the vagrant box instance or node when it boot or when you executevagrant up
.- Try to make it idempotent.
- Exit with non-zero when a validation fail
- All these instructions are executed as
root
.
- Network Settings: It is the last section inside teh block
Vagrant.configure
...end
. This block contain Vagrant instructions to setup the node. You can find information on the Vagrant Documentation.
-
Export the following environment variables:
- GITHUB_USER: Your Github username or organization where you forked the Kubernetes projects. The Github URL should be like:
github.com/{GITHUB_USERNAME}
FULLNAME
: (Optional) Your full name like it is assigned to your Github user. It's used to configuregit
and it's used for your commits. If not provided, the script will get it using thegit config
command.EMAIL
: (Optional) Your email address like it is assigned to your Github user. It's used to configuregit
and it's used for your commits. If not provided, the script will get it using thegit config
command.
- GITHUB_USER: Your Github username or organization where you forked the Kubernetes projects. The Github URL should be like:
-
Execute the following instructions, it includes the download of the
Vagrantfile
, and theexport
of the above variables:mkdir -p kude/shared_folder cd kude curl -fsL https://raw.githubusercontent.com/johandry/kube-dev-env/main/Vagrantfile export GITHUB_USER=johandry vagrant up cd shared_folder
To test the environment, login into the Vagrant box and verify you have all the important requirements, or execute test.sh
, like this:
vagrant ssh
./test.sh
If something fail in your build, you may want to cleanup everything and start over.
vagrant destroy
You must sign the Contributor License Agreement in order to contribute.
- Go to https://github.com/kubernetes/kubernetes/issues to find issues to work on.
- Take ownership of the issue. Make a comment on the issue you found using the tag
#dibs
orI would like to work on this
. - Sync your fork's master.
- Create a feature branch and begin work.
- Sync as you work and iterate.
- Pull request back to
github.com/kubernetes/kubernetes
- Go to step 5 until it's finished and accepted.
- Merge.
Some important comments:
- Don't by shy, ask if you have questions
- If you are not ready to fix the issue, tag it as
#investigating
. You will not be assigned but will let others know you might call it as#dibs
You can find more information about this process in the CONTRIBUTING document of each Kubernetes project or SIG.
You can work from your computer, on whatever operative system you are, on the directory kude/shared_folder/k8s.io/
. This directory is shared in your Vagrant box or development environment on the directory ~/shared_folder/k8s.io
To build Kubernetes login to the Vagrant box and execute make
, like this:
vagrant ssh
sudo make all
When you use vagrant ssh
you login as the user vagrant
, so it's required to use sudo
when executing make
.
You can also use the parameter WHAT
to build just one package or executable, like this:
make WHAT=cmd/kubelet
Other useful Makefile rules are:
clean
: remove built binariesrelease
: generate a releaserelease-skip-tests
: generate a release without running testshelp
: print all the rules
Example:
sudo make clean
sudo make release-skip-tests WHAT=cmd/kubelet
It's required to run the tests before committing any code change, depending of the change is the test you'd like to execute.
The tests are also executed using make
using the following rules (don't forget to use sudo
):
verify
: Verification tests. Required before pushing a PRtest
: Unit tests. You can use the parameterWHAT
to test a package. Example:WHAT=./pkg/api/pod
test-integration
: Integration tests. You can use the parameterWHAT
to test an existing integration tests. Example:WHAT=./test/integration/kubelet
You can also use the parameter GOFLAGS="-v"
to tests in verbose mode. For example:
sudo make test-integration WHAT=./test/integration/pods GOFLAGS="-v"
The alternatives to this project would be:
- KinD which uses Docker instead of Virtual Box. KinD may consume less resources than KuDE and may provision the environment quicker (Containers vs VMs).
- VM on a Cloud can be setup using the same provisioning script but requires access to internet and will cost you. However, the performance may be better as you are not consuming your computer resources.
Thanks to Mike Brown for the mentoring and instructions to setup a VM to contribute to Kubernetes projects. The process explained here are from his repo and the Kubernetes project repos.