本文介绍使用 minikub 安装 Kubernetes。minikub是本地的Kubernetes,专注于使Kubernetes的学习和开发变得简单。
install minikube
brew install minikube
or
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.1.1/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
install k8s-cli
brew install kubernetes-cli
Create a profile
minikube profile poc
启动minikube
minikube start
minikube start -p poc
minikube start -p poc --registry-mirror=https://registry.docker-cn.com
minikube start --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
minikube start -p poc --driver=virtualbox --registry-mirror=https://registry.docker-cn.com --image-mirror-country=cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
➜ ~ minikube start
😄 [poc] minikube v1.14.0 on Darwin 10.15.7
✨ Using the virtualbox driver based on existing profile
👍 Starting control plane node poc in cluster poc
🔄 Restarting existing virtualbox VM for "poc" ...
🎉 minikube 1.14.1 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.14.1
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
🐳 Preparing Kubernetes v1.19.2 on Docker 19.03.12 ...
🔎 Verifying Kubernetes components...
🌟 Enabled addons: storage-provisioner, default-storageclass
❗ /usr/local/bin/kubectl is version 1.16.6-beta.0, which may have incompatibilites with Kubernetes 1.19.2.
💡 Want kubectl v1.19.2? Try 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "poc" by default
➜ ~
安装完毕后,查看版本
kubectl version
kubectl cluster-info
kubectl get nodes -o wide
登录minikube机器
minikube ssh
dashboard
minikube dashboard
会默认打开k8s dashboard:http://127.0.0.1:58803/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/
部署应用
启动一个镜像发布到的容器(Pod)8080端口
kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
or
kubectl run hello-minikube --image=gcmirrors/echoserver:1.7 --port=8080
kubectl get pods
kubectl get services
kubectl get deployments
kubectl get events
将容器(Pod)的8080端口,在节点(当前mac)中映射物理端口NodePort,
kubectl expose deployment hello-minikube --type=NodePort
发布后,通过命令查看已经发布的内容。
kubectl get services
访问
可以登录到virutalbox控制台(minikube虚拟机)上直接访问:
curl http://10.96.0.1:443/
也可以通过minikube的命令查看数据
curl $(minikube service hello-minikube --url)
删除服务
kubectl delete services hello-minikube
删除应用
kubectl delete deployment hello-minikube
停止minikube
minikube stop
FAQ
版本问题
minikube
默认使用的v1.12.x
版本的k8s
,但是我们安装的kubectl
版本为v1.13.1
minikube start --alsologtostderr --kubernetes-version v1.13.1
获取镜像问题
kubectl run hello-minikube --image=ghihfm4j.mirror.aliyuncs.com/gcmirrors/echoserver:1.7 --port=8080