在 Mac 上通过 Minikube 安装本地 K8s 集群

准备工作

安装 xhyve 驱动程序。

1
2
3
$ brew install docker-machine-driver-xhyve
$ sudo chown root:wheel $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve
$ sudo chmod u+s $(brew --prefix)/opt/docker-machine-driver-xhyve/bin/docker-machine-driver-xhyve

安装 kubectl

1
2
3
4
5
6
7
8
$ curl -LO https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/darwin/amd64/kubectl

$ chmod +x ./kubectl
$ sudo mv ./kubectl /usr/local/bin/kubectl

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"9", GitVersion:"v1.9.1", GitCommit:"3a1c9449a956b6026f075fa3134ff92f7d55f812", GitTreeState:"clean", BuildDate:"2018-01-04T11:52:23Z", GoVersion:"go1.9.2", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.0", GitCommit:"0b9efaeb34a2fc51ff8e4d34ad9bc6375459c4a4", GitTreeState:"clean", BuildDate:"2017-11-29T22:43:34Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"linux/amd64"}

安装 Minikube

1
2
3
4
$ curl -Lo minikube https://storage.googleapis.com/minikube/releases/v0.24.1/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/

$ minikube version
minikube version: v0.24.1

启动集群

1
$ minikube start --vm-driver=xhyve --registry-mirror=https://registry.docker-cn.com

查看节点

1
2
3
$ kubectl get node
NAME STATUS ROLES AGE VERSION
minikube Ready <none> 13d v1.8.0

进入集群

1
$ minikube ssh

或者使用 Minikube Docker 守护进程:

1
$ eval $(minikube docker-env)

如果不使用 Minikube,可以通过运行 eval $(minikube docker-env -u) 来撤消此更改。

确保以下镜像已经预先下载(查源码),可以使用这个脚本

1
2
3
4
5
6
7
8
9
10
gcr.io/google_containers/pause-amd64:3.0
gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.5

gcr.io/google-containers/kube-addon-manager:v6.4-beta.2
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.5
gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.5
gcr.io/google_containers/kubernetes-dashboard-amd64:v1.8.0
gcr.io/k8s-minikube/storage-provisioner:v1.8.1
quay.io/kubernetes-ingress-controller/nginx-ingress-controller:0.9.0-beta.17
gcr.io/google_containers/defaultbackend:1.4

确认所有服务就绪

1
2
3
4
5
6
7
8
$ kubectl get pod --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system default-http-backend-qd455 1/1 Running 1 47m
kube-system kube-addon-manager-minikube 1/1 Running 3 13d
kube-system kube-dns-86f6f55dd5-wkbxj 3/3 Running 9 47m
kube-system kubernetes-dashboard-qn4tw 1/1 Running 3 47m
kube-system nginx-ingress-controller-jvbtg 1/1 Running 2 47m
kube-system storage-provisioner 1/1 Running 1 47m

访问 Dashboard

1
2
$ minikube dashboard
Opening kubernetes dashboard in default browser...

切换集群

1
$ kubectl config use-context minikube

查看集群信息

1
2
$ $ kubectl cluster-info
Kubernetes master is running at https://192.168.64.3:8443