DEV Community

Rahul Kumar
Rahul Kumar

Posted on

How to build and run Kubernetes locally .

Install GOLang (latest version):

sudo wget https://golang.org/dl/go1.16.5.linux-amd64.tar.gz
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.5.linux-amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode

Setup the environment via Bash :

echo 'export PATH=${PATH}:/usr/local/go/bin' >> ~/.profile
echo 'export GOPATH_K8S=${HOME}/go/src/k8s.io/kubernetes' >> ~/.profile
echo 'export PATH=${GOPATH_K8S}/third_party/etcd:${PATH}' >> ~/.profile
source ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

MAKE SURE YOU HAVE SET THE PATH FOR BOTH GO AND ETCD IN THE SECURE_PATH IN THE /etc/sudoers FILE

MAKE SURE TO EDIT IT AS VISUDO

clone kubernetes

mkdir -p {GOPATH_K8S}
git clone https://github.com/kubernetes/kubernetes ${GOPATH_K8S}
git remote rename origin upstream 
Enter fullscreen mode Exit fullscreen mode

install etcd

$ hack/install-etcd.sh

start docker demon

systemctl enable docker
systemctl start  docker
Enter fullscreen mode Exit fullscreen mode

Build k8s

This step takes 15 minitues
cd ${GOPATH_K8S}
git checkout v1.12.3 (checkout the stable release version)
time make quick-release
Enter fullscreen mode Exit fullscreen mode

Run a Local k8s cluster

$ {GOPATH_K8S}/hack/local-up-cluster.sh

verify the cluster is running in another window

export KUBERNETES_PROVIDER=local
export KUBECONFIG=/var/run/kubernetes/admin.kubeconfig
${GOPATH_K8S}/cluster/kubectl.sh get nodes
Enter fullscreen mode Exit fullscreen mode

Fork the k8s repo on github

navigate to 
click fork button
Enter fullscreen mode Exit fullscreen mode

setup gihub user name

export GITHUB_USER=[Insert your github user name]
echo 'export GITHUB_USER=${GITHUB_USER}' >> ~/.bash_profile
Enter fullscreen mode Exit fullscreen mode

Change the k8s source code

Navigate to the directory your clone

cd ${GOPATH_K8S}
git remote add origin https://github.com/${GITHUB_USER}/kubernetes
git fetch origin
Enter fullscreen mode Exit fullscreen mode

These instructions make the folllowing assumptions:

-Your upstream remote going to
http://
-Your origin remote
http://
Enter fullscreen mode Exit fullscreen mode

you can double check by runnig

$ git remote -v

Create a new branch before making a change

branch should have some meaning means what you have added to the code

git checkout upstream/master
git checkout -b my-brnach-of-k8s
Enter fullscreen mode Exit fullscreen mode

If you would like to make change we recommend finding some untested code and adding a few unit tests. If you don't know how to write unit tests in go read this

GOLang_Testing

Example new test

File: pkg/util/normalizer/normalizer_test.go

Run Kubernetes Locally

$ make test WHAT-k8s.io/kubernetes/pkg/util/normalizer

Contribute a pull request

Commit your changes and push to your fork

gofmt -v [insert path to changed file]
gofmt -v pkg/util/normalizer/normalier_test.go
git add .
git config --global user.name ""
git config --global user.email ""
git commit -m "commit msg"
git push -u origin/my-branch-of-k8s
Enter fullscreen mode Exit fullscreen mode

create a pull request via GiHub UI

Navigate to https://github.com/kubernetes/kubernetes page
click on the new pull request
click on compare across forks link
select your fork and branch from the two dropdowns on the right
click on create pull request
Note that an existing maintainer must comment with the /ok-to-test comment the automated test for new contributer
Enter fullscreen mode Exit fullscreen mode

If you have any doubt please ASK .
Thank you for reading πŸ”₯

Top comments (0)