mfanjie / tips

0 stars 0 forks source link

Setup kubernetes on vagrant in China mainland #1

Open mfanjie opened 8 years ago

mfanjie commented 8 years ago

As the existence of Chinese GFW, certain required internet accesses are blocked in China. Simply following getting started guide http://kubernetes.io/v1.1/docs/getting-started-guides/vagrant.html will not let you have Kubernetes installed. We need to do a series of hack to make things happen. OS: Mac OS 10.11.2 KUBERNETE_PROVIDER=vagrant

mfanjie commented 8 years ago

Here is another good blog for k8s cluster setup, with deeper understanding on build and cluster setup https://github.com/zhouhaibing089/Blog/issues

mfanjie commented 8 years ago

Build: Kubernetes build will be using docker-machine to create a new docker machine named kube-dev, all Kuberenetes builds are inside this machine. As the build requires access to gcr.io to pull images(debian-iptables, pause, kube-registry-proxy), we need to set proxy for this machine. Option 1:Set engine-env when creating the machine using docker-machine create -d virtualbox --engine-env HTTP_PROXY=http://myproxy

diff --git a/build/common.sh b/build/common.sh index 0582911..a70b139 100755 --- a/build/common.sh +++ b/build/common.sh @@ -165,7 +165,10 @@ function kube::build::prepare_docker_machine() { kube::log::status "docker-machine was found." docker-machine inspect kube-dev >/dev/null || { kube::log::status "Creating a machine to build Kubernetes"

Option 2: set global environment variable in Docker file of kube-dev diff --git a/build/build-image/Dockerfile b/build/build-image/Dockerfile index a3e0f8c..17661b3 100644 --- a/build/build-image/Dockerfile +++ b/build/build-image/Dockerfile @@ -26,6 +26,8 @@ ENV GOARCH amd64 ENV TMPDIR /tmp.k8s

Get the code coverage tool and godep

+ENV http_proxy http://myproxy +ENV https_proxy http://myproxy RUN mkdir $TMPDIR && \ go get golang.org/x/tools/cmd/cover github.com/tools/godep

mfanjie commented 8 years ago

Cluster Bootstrapping When kubernetes provider is set to vagrant, kubernetes will use vagrant to setup the cluster. The master cluster requires connect to gcr.io to pull etcd images, and nodes requires connect to gcr.io to pull etcd as well as other addons. We need to set proxy to the vagrant VM to ensure the connection. Setting up vagrant proxy is most convenient way to do that.

  1. install the plugin vagrant plugin install vagrant-proxyconf
  2. configure the plugin diff --git a/Vagrantfile b/Vagrantfile index 3b3599e..d4b1f50 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -107,6 +107,12 @@ end $vm_master_mem = (ENV['KUBERNETES_MASTER_MEMORY'] || ENV['KUBERNETES_MEMORY'] || 1280).to_i $vm_node_mem = (ENV['KUBERNETES_NODE_MEMORY'] || ENV['KUBERNETES_MEMORY'] || 1024).to_i

+Vagrant.configure("2") do |config|

refererence http://tmatilai.github.io/vagrant-proxyconf/

After proxy is properly configured, you can boot your cluster by run cluster/kube-up.sh

mfanjie commented 8 years ago

To accelerate the build, just remove those unnecessary platform. diff --git a/hack/lib/golang.sh b/hack/lib/golang.sh index 43a1f68..39aeaba 100755 --- a/hack/lib/golang.sh +++ b/hack/lib/golang.sh @@ -50,7 +50,6 @@ readonly KUBE_SERVER_BINARIES=("${KUBE_SERVER_TARGETS[@]##*/}") The server platform we are building on. readonly KUBE_SERVER_PLATFORMS=( linux/amd64