安装 Minikube 要求 Minikube 需要在 BIOS 中启用 VT-x/AMD-v 虚拟化。要检查在 OS X/macOS 上是否已启用,请运行: 如果有输出,就说明已经启用了! 先决条件 kubectl docker(适用于 Mac) minikube virtualbox 验证 启动 这可能需要一段时间,预期的输出是: 正在启动本地 Kubernetes 集群... Kubectl 现在配置为使用该集群。 太好了!你现在有了一个本地运行的 Kubernetes 集群。Minikube 已为你启动了一个虚拟机,并且一个 Kubernetes 集群正在该虚拟机中运行。
Minikube 需要在 BIOS 中启用 VT-x/AMD-v 虚拟化。要检查在 OS X/macOS 上是否已启用,请运行:
sysctl -a | grep machdep.cpu.features | grep VMX
如果有输出,就说明已经启用了!
brew update && brew install kubectl && brew cask install docker virtualbox && brew install minikube
docker --version # Docker version 17.09.0-ce, build afdb6d4 docker-compose --version # docker-compose version 1.16.1, build 6d1ac21 docker-machine --version # docker-machine version 0.12.2, build 9371605 minikube version # minikube version: v0.22.3 kubectl version --client # Client Version: version.Info{Major:"1", Minor:"8", GitVersion:"v1.8.1", GitCommit:"f38e43b221d08850172a9a4ea785a86a3ffa3b3a", GitTreeState:"clean", BuildDate:"2017-10-12T00:45:05Z", GoVersion:"go1.9.1", Compiler:"gc", Platform:"darwin/amd64"}
minikube start
正在启动本地 Kubernetes 集群...
Kubectl 现在配置为使用该集群。
太好了!你现在有了一个本地运行的 Kubernetes 集群。Minikube 已为你启动了一个虚拟机,并且一个 Kubernetes 集群正在该虚拟机中运行。
应输出类似的内容:
NAME STATUS ROLES AGE VERSION minikube Ready <none> 40s v1.7.5
eval $(minikube docker-env)
如果希望默认使用 minikube 的守护进程(或不想每次打开新终端时都设置),请将此行添加到
.bash_profileor.zshrc或其他文件中。
eval $(docker-machine env -u)
docker ps,它应该输出类似的内容:CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES e97128790bf9 gcr.io/google-containers/kube-addon-manager "/opt/kube-addons.sh" 22 seconds ago Up 22 seconds k8s_kube-addon-manager_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0 69707e54d1d0 gcr.io/google_containers/pause-amd64:3.0 "/pause" 33 seconds ago Up 33 seconds k8s_POD_kube-addon-manager-minikube_kube-system_c654b2f084cf26941c334a2c3d6db53d_0
docker run -d -p 5000:5000 --restart=always --name registry registry:2
首先,将所有文件(Dockerfile、my-app.yml、index.html)从这个示例中本地保存到一个新的(空)目录中。
如果你希望严格按照本指南操作,可以先在本地构建下面的 Dockerfile。将 Dockerfile 本地保存,最好在一个空目录中并运行:
docker build . --tag my-app
现在你应该有一个名为 'my-app' 的本地镜像,可以通过
docker images(或你自己的镜像)来检查。然后你可以将其发布到你的本地 Docker 注册表:
docker tag my-app localhost:5000/my-app:0.1.0
运行
docker images应该输出以下内容:
REPOSITORY TAG IMAGE ID CREATED SIZE my-app latest cc949ad8c8d3 44 seconds ago 89.3MB localhost:5000/my-app 0.1.0 cc949ad8c8d3 44 seconds ago 89.3MB httpd 2.4-alpine fe26194c0b94 7 days ago 89.3MB
my-app.yml 保存到你的系统上并运行以下命令:kubectl create -f my-app.yml
你现在应该能看到你的 Pod 和服务:
kubectl get all
my-app 暴露在集群之外,你可以通过运行以下命令获取访问地址:minikube service my-app --url
这应该输出类似
http://192.168.99.100:30304的内容(端口可能会有所不同)。使用你喜欢的浏览器访问该地址,你应该会看到“Hello world!”。你刚刚从本地 Kubernetes 集群外部访问了你的应用!
minikube dashboard
kubectl delete deploy my-app
kubectl delete service my-app
你现在可以部署其他镜像了!
minikube stop;minikube delete;rm -rf ~/.minikube ~/.kube;`` brew uninstall kubectl; brew cask uninstall docker virtualbox minikube;```
The Dashboard UI is not deployed by default. To deploy it, run the following command:
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
You can access Dashboard using the kubectl command-line tool by running the following command:
kubectl proxy
Kubectl will make Dashboard available at http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/.
To get the token in a single oneliner:
kubectl -n kube-system describe secret $(kubectl -n kube-system get secret | awk '/^deployment-controller-token-/{print $1}') | awk '$1=="token:"{print $2}'
kubectl run <pod-name-to-be-created> --image=<image-name> --env="PORT=8080" --port=8080 --expose --namespace=<namespace>
The following command will launch a deployment called http which will start a container based on the Docker Image katacoda/docker-http-server:latest.
kubectl run http --image=katacoda/docker-http-server:latest --replicas=1
Use the following command to expose the container port 80 on the host 8000 binding to the external-ip of the host.
kubectl expose deployment http --external-ip="172.17.0.57" --port=8000 --target-port=80
You will then be able to ping the host and see the result from the HTTP service.
curl http://172.17.0.57:8000
Use the command command to create a second http service exposed on port 8001.
kubectl run httpexposed --image=katacoda/docker-http-server:latest --replicas=1 --port=80 --hostport=8001
You should be able to access it using curl http://172.17.0.57
Under the covers, this exposes the Pod via Docker Port Mapping. As a result, you will not see the service listed using kubectl get svc
To find the details you can use docker ps | grep httpexposed
声明:
本文件灏天文库团队进行了翻译。尽管我们力求准确,但请注意,翻译可能包含错误或不准确之处。原文档以其原始语言为准。我们不对因使用此翻译而产生的任何误解或误译负责。