Kubernetes 环境搭建 - MacOS

96
Anoyi
2018.05.05 12:16 字数 173

准备工作

1、Mac 环境需求

Minikube 要求在 BIOS 中启用 VT-x / AMD-v 虚拟化, 要检查这是否在OSX / macOS上运行,请执行以下操作:

sysctl -a | grep machdep.cpu.features | grep VMX

如果有输出,那你很棒棒!

2、【推荐】使用清华的 brew 镜像源

cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

brew update

相关软件安装

  • kubectl
  • docker (for Mac)
  • minikube
  • virtualbox
brew update && brew install kubectl && brew cask install docker minikube virtualbox

校验软件版本信息

docker --version                # Docker version 18.03.1-ce, build 9ee9f40
docker-compose --version        # docker-compose version 1.21.1, build 5a3f1a3
docker-machine --version        # docker-machine version 0.14.0, build 89b8332
minikube version                # minikube version: v0.26.1
kubectl version --client        # Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.1", GitCommit:"d4ab47518836c750f9949b9e0d387f20fb92260b", GitTreeState:"clean", BuildDate:"2018-04-13T22:28:25Z", GoVersion:"go1.9.5", Compiler:"gc", Platform:"darwin/amd64"}      

开始

1、启动 kubernetes 集群

minikube start --bootstrapper=localkube

一会后,会有如下输出

Starting local Kubernetes v1.10.0 cluster...
Starting VM...
Downloading Minikube ISO
 150.53 MB / 150.53 MB [============================================] 100.00% 0s
Getting VM IP address...
WARNING: The localkube bootstrapper is now deprecated and support for it
will be removed in a future release. Please consider switching to the kubeadm bootstrapper, which
is intended to replace the localkube bootstrapper. To disable this message, run
[minikube config set ShowBootstrapperDeprecationNotification false]
Moving files into cluster...
Downloading localkube binary
 173.54 MB / 173.54 MB [============================================] 100.00% 0s
 0 B / 65 B [----------------------------------------------------------]   0.00%
 65 B / 65 B [======================================================] 100.00% 0sSetting up certs...
Connecting to cluster...
Setting up kubeconfig...
Starting cluster components...
Kubectl is now configured to use the cluster.
Loading cached images from config file.

恭喜!Minikube 为你启动了一个虚拟机,并在该虚拟机中运行了 Kubernetes 集群。

2、查看集群节点信息

➜  ~ kubectl get nodes
NAME       STATUS    ROLES     AGE       VERSION
minikube   Ready     <none>    15m       v1.10.0

常见问题及解决办法

1、kubectl 安装失败

➜ brew install kubectl
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (caskroom/cask, homebrew/core).
==> Updated Formulae
pandoc-citeproc                                                   php                                                               php@7.0

Error: Failed to link all completions, docs and manpages:
  Permission denied @ rb_file_s_symlink - (../../../Homebrew/completions/zsh/_brew, /usr/local/share/zsh/site-functions/_brew)
Warning: kubernetes-cli 1.10.1 is already installed, it's just not linked
You can use `brew link kubernetes-cli` to link this version.

解决办法

sudo chown -R $(whoami) /usr/local/share/
brew link kubernetes-cli
Kubernetes
Web note ad 1