How to build and run Kubernetes locally .
Tags: opensource, kubernetes, devops
Published: 2021-06-07 17:00:07

## __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
```
## __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
```

`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 
```
## install etcd
```$ hack/install-etcd.sh```

## start docker demon
```$
systemctl enable docker
systemctl start  docker
```
## Build k8s
```$
This step takes 15 minitues
cd ${GOPATH_K8S}
git checkout v1.12.3 (checkout the stable release version)
time make quick-release
```
## 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
```
## Fork the k8s repo on github
```
navigate to 
click fork button
```
## setup gihub user name
```$
export GITHUB_USER=[Insert your github user name]
echo 'export GITHUB_USER=${GITHUB_USER}' >> ~/.bash_profile
```
## 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
```
## These instructions make the folllowing assumptions:
```
-Your upstream remote going to
http://
-Your origin remote
http://
```
## 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
```

## 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](http://golang.org/doc/code.html#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
```
## 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
```

If you have any doubt please ASK .
Thank you for reading 🔥