k8s开发环境
在搭建开发环境之前, 请Try Kubernetes,Get Started and CONCEPTS
可以自己使用minikube 来搭建个环境, 自己玩一玩。
K8s需要一些依赖。 参看官方文档
https://github.com/kubernetes/community/blob/master/contributors/devel/running-locally.md
1. 需要安装 linux
2. 安装docker
wget -O- https://get.docker.com/ |bash
sudo usermod -aG docker $USER
3. 安装etcd
hack/install-etcd.sh # Installs in ./third_party/etcd
echo "export PATH=\"\$PATH:$(pwd)/third_party/etcd\"" >> ~/.profile # Add to PATH
4. 安装go
sudo add-apt-repository ppa:gophers/archive sudo apt update sudo apt-get install golang-1.9-go cat >> ~/.profile <<<' GOROOT=`go env |grep "GOROOT" |cut -d "=" -f2` GOROOT=${GOROOT#\"} GOROOT=${GOROOT%\"} GOPATH=`go env |grep GOPATH |cut -d "=" -f 2` GOPATH=${GOPATH%\"} GOPATH=${GOPATH#\"}' echo "export PATH=\$PATH:/usr/lib/go-1.9/bin" >> ~/.profile source ~/.profile
5. 安装 openssl
6. 安装 CFSSL
go get -u github.com/cloudflare/cfssl/cmd/...
echo "export PATH=\$PATH:\$GOPATH/bin" >> ~/.profile
source ~/.profile
7. 下载源码
git clone --depth=1 https://github.com/kubernetes/kubernetes.git
8. 编译安装k8s
cd kubernetes
hack/local-up-cluster.sh
9. 可以开发了。
请参看 devel 重点 coding-conventions
go调试, 请参考 golang debug, 推荐使用Delve
=============================
参考文档:
开发者主要看看: Community 和 Documentation
附录:
编译过程:
$ hack/local-up-cluster.sh WARNING : The kubelet is configured to not fail if swap is enabled; production deployments should disable swap. WARNING : This script MAY be run as root for docker socket / iptables functionality; if failures occur, retry as root. make: Entering directory '/home/ubuntu/kubernetes' make[1]: Entering directory '/home/ubuntu/kubernetes' +++ [0108 11:10:43] Building the toolchain targets: k8s.io/kubernetes/hack/cmd/teststale k8s.io/kubernetes/vendor/github.com/jteeuwen/go-bindata/go-bindata +++ [0108 11:10:44] Generating bindata: test/e2e/generated/gobindata_util.go ~/kubernetes ~/kubernetes/test/e2e/generated ~/kubernetes/test/e2e/generated +++ [0108 11:10:45] Building go targets for linux/amd64: ./vendor/k8s.io/code-generator/cmd/deepcopy-gen +++ [0108 11:10:55] Building the toolchain targets: k8s.io/kubernetes/hack/cmd/teststale k8s.io/kubernetes/vendor/github.com/jteeuwen/go-bindata/go-bindata +++ [0108 11:10:55] Generating bindata: test/e2e/generated/gobindata_util.go ~/kubernetes ~/kubernetes/test/e2e/generated ~/kubernetes/test/e2e/generated +++ [0108 11:10:56] Building go targets for linux/amd64: ./vendor/k8s.io/code-generator/cmd/defaulter-gen +++ [0108 11:11:03] Building the toolchain targets: k8s.io/kubernetes/hack/cmd/teststale k8s.io/kubernetes/vendor/github.com/jteeuwen/go-bindata/go-bindata +++ [0108 11:11:03] Generating bindata: test/e2e/generated/gobindata_util.go ~/kubernetes ~/kubernetes/test/e2e/generated ~/kubernetes/test/e2e/generated +++ [0108 11:11:04] Building go targets for linux/amd64: ./vendor/k8s.io/code-generator/cmd/conversion-gen +++ [0108 11:11:13] Building the toolchain targets: k8s.io/kubernetes/hack/cmd/teststale k8s.io/kubernetes/vendor/github.com/jteeuwen/go-bindata/go-bindata +++ [0108 11:11:13] Generating bindata: test/e2e/generated/gobindata_util.go ~/kubernetes ~/kubernetes/test/e2e/generated ~/kubernetes/test/e2e/generated +++ [0108 11:11:14] Building go targets for linux/amd64: ./vendor/k8s.io/code-generator/cmd/openapi-gen make[1]: Leaving directory '/home/ubuntu/kubernetes' +++ [0108 11:11:23] Building the toolchain targets: k8s.io/kubernetes/hack/cmd/teststale k8s.io/kubernetes/vendor/github.com/jteeuwen/go-bindata/go-bindata +++ [0108 11:11:23] Generating bindata: test/e2e/generated/gobindata_util.go ~/kubernetes ~/kubernetes/test/e2e/generated ~/kubernetes/test/e2e/generated +++ [0108 11:11:24] Building go targets for linux/amd64: cmd/kubectl cmd/hyperkube +++ [0108 11:11:24] +++ Warning: stdlib pkg with cgo flag not found. +++ [0108 11:11:24] +++ Warning: stdlib pkg cannot be rebuilt since /usr/lib/go-1.9/pkg is not writable by ubuntu +++ [0108 11:11:24] +++ Warning: Make /usr/lib/go-1.9/pkg writable for ubuntu for a one-time stdlib install, Or +++ [0108 11:11:24] +++ Warning: Rebuild stdlib using the command 'CGO_ENABLED=0 go install -a -installsuffix cgo std' +++ [0108 11:11:24] +++ Falling back to go build, which is slower ** make: Leaving directory '/home/ubuntu/kubernetes' WARNING: No swap limit support Kubelet cgroup driver defaulted to use: cgroupfs API SERVER insecure port is free, proceeding... API SERVER secure port is free, proceeding... Detected host and ready to start services. Doing some housekeeping first... Using GO_OUT /home/ubuntu/kubernetes/_output/local/bin/linux/amd64 Starting services now! Starting etcd etcd --advertise-client-urls http://127.0.0.1:2379 --data-dir /tmp/tmp.lG7Vdi3iOj --listen-client-urls http://127.0.0.1:2379 --debug > "/dev/null" 2>/dev/null Waiting for etcd to come up. +++ [0108 11:14:07] On try 1, etcd: : http://127.0.0.1:2379 {"action":"set","node":{"key":"/_test","value":"","modifiedIndex":4,"createdIndex":4}} Generating a 2048 bit RSA private key ...............+++ .....................................................................................................................+++ writing new private key to '/var/run/kubernetes/server-ca.key' ----- Generating a 2048 bit RSA private key ..................+++ ................................................+++ writing new private key to '/var/run/kubernetes/client-ca.key' ----- Generating a 2048 bit RSA private key ....................................................................+++ .....................................+++ writing new private key to '/var/run/kubernetes/request-header-ca.key' ----- 2018/01/08 11:14:09 [INFO] generate received request 2018/01/08 11:14:09 [INFO] received CSR 2018/01/08 11:14:09 [INFO] generating key: rsa-2048 2018/01/08 11:14:10 [INFO] encoded CSR 2018/01/08 11:14:10 [INFO] signed certificate with serial number 715123456948917083412158572796494175744197307872 2018/01/08 11:14:10 [INFO] generate received request 2018/01/08 11:14:10 [INFO] received CSR 2018/01/08 11:14:10 [INFO] generating key: rsa-2048 2018/01/08 11:14:10 [INFO] encoded CSR 2018/01/08 11:14:10 [INFO] signed certificate with serial number 129637119914906282839116246736967141392059620053 2018/01/08 11:14:10 [INFO] generate received request 2018/01/08 11:14:10 [INFO] received CSR 2018/01/08 11:14:10 [INFO] generating key: rsa-2048 2018/01/08 11:14:11 [INFO] encoded CSR 2018/01/08 11:14:11 [INFO] signed certificate with serial number 165024087692961687999165752394062992892543742472 2018/01/08 11:14:11 [INFO] generate received request 2018/01/08 11:14:11 [INFO] received CSR 2018/01/08 11:14:11 [INFO] generating key: rsa-2048 2018/01/08 11:14:11 [INFO] encoded CSR 2018/01/08 11:14:11 [INFO] signed certificate with serial number 494758003908811925730802793525711755484053117292 2018/01/08 11:14:12 [INFO] generate received request 2018/01/08 11:14:12 [INFO] received CSR 2018/01/08 11:14:12 [INFO] generating key: rsa-2048 2018/01/08 11:14:12 [INFO] encoded CSR 2018/01/08 11:14:12 [INFO] signed certificate with serial number 413859821971649967403269044690888435909488107601 2018/01/08 11:14:12 [INFO] generate received request 2018/01/08 11:14:12 [INFO] received CSR 2018/01/08 11:14:12 [INFO] generating key: rsa-2048 2018/01/08 11:14:12 [INFO] encoded CSR 2018/01/08 11:14:12 [INFO] signed certificate with serial number 436494598670785810730542474619179243660984927821 2018/01/08 11:14:13 [INFO] generate received request 2018/01/08 11:14:13 [INFO] received CSR 2018/01/08 11:14:13 [INFO] generating key: rsa-2048 2018/01/08 11:14:13 [INFO] encoded CSR 2018/01/08 11:14:13 [INFO] signed certificate with serial number 527478716993845979463342446982400322373891769061 2018/01/08 11:14:13 [INFO] generate received request 2018/01/08 11:14:13 [INFO] received CSR 2018/01/08 11:14:13 [INFO] generating key: rsa-2048 2018/01/08 11:14:14 [INFO] encoded CSR 2018/01/08 11:14:14 [INFO] signed certificate with serial number 403955253617662981707875676047491510407377487753 2018/01/08 11:14:14 [INFO] generate received request 2018/01/08 11:14:14 [INFO] received CSR 2018/01/08 11:14:14 [INFO] generating key: rsa-2048 2018/01/08 11:14:14 [INFO] encoded CSR 2018/01/08 11:14:14 [INFO] signed certificate with serial number 162848926558084611619120993030850770010628652872 Waiting for apiserver to come up +++ [0108 11:14:24] On try 7, apiserver: : ok Cluster "local-up-cluster" set. use 'kubectl --kubeconfig=/var/run/kubernetes/admin-kube-aggregator.kubeconfig' to use the aggregated API server service "kube-dns" created serviceaccount "kube-dns" created configmap "kube-dns" created deployment "kube-dns" created Kube-dns addon successfully deployed. kubelet ( 6858 ) is running. Create default storage class for storageclass "standard" created Local Kubernetes cluster is running. Press Ctrl-C to shut it down. Logs: /tmp/kube-apiserver.log /tmp/kube-controller-manager.log /tmp/kube-proxy.log /tmp/kube-scheduler.log /tmp/kubelet.log To start using your cluster, you can open up another terminal/tab and run: export KUBECONFIG=/var/run/kubernetes/admin.kubeconfig cluster/kubectl.sh Alternatively, you can write to the default kubeconfig: export KUBERNETES_PROVIDER=local cluster/kubectl.sh config set-cluster local --server=https://localhost:6443 --certificate-authority=/var/run/kubernetes/server-ca.crt cluster/kubectl.sh config set-credentials myself --client-key=/var/run/kubernetes/client-admin.key --client-certificate=/var/run/kubernetes/client-admin.crt cluster/kubectl.sh config set-context local --cluster=local --user=myself cluster/kubectl.sh config use-context local cluster/kubectl.sh