Kubernetes开发环境

配置开发环境

apt-get install -y gcc make socat git

# install docker
curl -fsSL https://get.docker.com/ | sh

# install etcd
curl -L https://github.com/coreos/etcd/releases/download/v3.0.10/etcd-v3.0.10-linux-amd64.tar.gz -o etcd-v3.0.10-linux-amd64.tar.gz && tar xzvf etcd-v3.0.10-linux-amd64.tar.gz && /bin/cp -f etcd-v3.0.10-linux-amd64/{etcd,etcdctl} /usr/bin && rm -rf etcd-v3.0.10-linux-amd64*

# install golang
curl -sL https://storage.googleapis.com/golang/go1.8.1.linux-amd64.tar.gz | tar -C /usr/local -zxf -
export GOPATH=/gopath
export PATH=$PATH:$GOPATH/bin:/usr/local/bin:/usr/local/go/bin/

# Get essential tools for building kubernetes
go get -u github.com/jteeuwen/go-bindata/go-bindata

# Get kubernetes code
mkdir -p $GOPATH/src/k8s.io
git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes
cd $GOPATH/src/k8s.io/kubernetes

# Start a local cluster
export KUBERNETES_PROVIDER=local
# export EXPERIMENTAL_CRI=true
# export ALLOW_SECURITY_CONTEXT=yes
# set dockerd --selinux-enabled
# export NET_PLUGIN=kubenet
hack/local-up-cluster.sh

打开另外一个终端,配置kubectl:

export KUBECONFIG=/var/run/kubernetes/admin.kubeconfig
cluster/kubectl.sh

编译release版

make quick-release

容器集成开发环境

hyper run -it feisky/kubernetes-dev bash
# /hack/start-hyperd.sh
# /hack/start-docker.sh
# /hack/start-frakti.sh
# /hack/start-kubernetes-frakti.sh
# /hack/setup-kubectl.sh
# cluster/kubectl.sh

单元测试

# unit test a special package
go test -v k8s.io/kubernetes/pkg/kubelet/kuberuntime

e2e测试

make WHAT='test/e2e/e2e.test'
make ginkgo

export KUBERNETES_PROVIDER=local
go run hack/e2e.go -v -test --test_args='--ginkgo.focus=Port\sforwarding'
go run hack/e2e.go -v -test --test_args='--ginkgo.focus=Feature:SecurityContext'

Node e2e测试

export KUBERNETES_PROVIDER=local
make test-e2e-node FOCUS="InitContainer" TEST_ARGS="--runtime-integration-type=cri"

Bot命令

  • Jenkins verification: @k8s-bot verify test this
  • GCE E2E: @k8s-bot cvm gce e2e test this
  • Test all: @k8s-bot test this please, issue #IGNORE
  • CRI test: @k8s-bot cri test this.
  • Verity test: @k8s-bot verify test this
  • LGTM (only applied if you are one of assignees):: /lgtm
  • LGTM cancel: /lgtm cancel

更多命令见kubernetes test-infra

有用的git命令

拉取pull request到本地:

git fetch upstream pull/324/head:branch
git fetch upstream pull/365/merge:branch

或者配置.git/config并运行git fetch拉取所有的pull requests:

    fetch = +refs/pull/*:refs/remotes/origin/pull/*

用docker-machine创建虚拟机的方法

docker-machine create --driver google --google-project xxxx --google-machine-type n1-standard-2 --google-disk-size 30 kubernetes

Minikube启动本地cluster

$ minikube get-k8s-versions
The following Kubernetes versions are available:
    - v1.5.1
    - v1.4.3
    ...

# http proxy is required in China
$ minikube start --docker-env HTTP_PROXY=http://proxy-ip:port --docker-env HTTPS_PROXY=http://proxy-ip:port --vm-driver=xhyve --kubernetes-version="v1.6.2"
powered by Gitbook 该教程制作时间: 2017-05-16 17:06:56