MAC OSX
一、先安装虚拟化驱动
在MAC上支持 xhyve driver, VirtualBox 或 VMware Fusion
我用的是virtualbox,到官网下载https://www.virtualbox.org/wiki/Downloads DMG文件并安装。
二、安装kubectl https://kubernetes.io/docs/tasks/tools/install-kubectl/
#下载文件
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/darwin/amd64/kubectl
#增加可执行权限
chmod +x ./kubectl
#拷到bin目录
sudo mv ./kubectl /usr/local/bin/kubectl
三、安装minikube
#官方速度太慢用啊里云
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.25.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
四、启动Minikube
#这个过程需要联网两次下载,确保已经成功安装了第一步的虚拟化驱动
minikube start --registry-mirror=https://registry.docker-cn.com
打开控制面板
minikube dashboard
使用
#停止
wushanfudeMacBook-Air:~ wushanfu$ minikube stop
Stopping local Kubernetes cluster...
Machine stopped.
#启动(过程可能有点慢)
wushanfudeMacBook-Air:~ wushanfu$ minikube start
Starting local Kubernetes v1.9.0 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting 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.
#创建 hello-minikube 部署
wushanfudeMacBook-Air:~ wushanfu$ kubectl run hello-minikube --image=tomcat:8.0 --port=8080
deployment "hello-minikube" created
#发布服务 hello-minikube
wushanfudeMacBook-Air:~ wushanfu$ kubectl expose deployment hello-minikube --type=NodePort
service "hello-minikube" exposed
#查看 pods
wushanfudeMacBook-Air:~ wushanfu$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-minikube-5df766f774-nmcfh 0/1 ContainerCreating 0 25s
#注意 pod没有完全创建好的时候,状态是 ContainerCreating,当部署完成后,状态就变成 Running
wushanfudeMacBook-Air:~ wushanfu$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-minikube-5df766f774-nmcfh 1/1 Running 0 6m
#对外提供服务(http://192.168.99.100:30264 是自动生成的随机端口)
wushanfudeMacBook-Air:~ wushanfu$ minikube service hello-minikube --url
http://192.168.99.100:30264
#重用Docker守护进程
wushanfudeMacBook-Air:~ wushanfu$ eval $(minikube docker-env)
#这时就可以用docker与minikube VM内的docker守护进程交互
wushanfudeMacBook-Air:~ wushanfu$ docker ps
#进入minikube
wushanfudeMacBook-Air:~ wushanfu$ minikube ssh
_ _
_ _ ( ) ( )
___ ___ (_) ___ (_)| |/') _ _ | |_ __
/' _ ` _ `\| |/' _ `\| || , < ( ) ( )| '_`\ /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )( ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)
网友评论