什么是MiniKube
Minikube 是一个可以在本地轻松运行 Kubernetes 的工具。Minikube 会在您的笔记本电脑中的虚拟机上运行一个单节点的 Kubernetes 集群,以便用户对 Kubernetes 进行试用或者在之上进行 Kubernetes 的日常开发(---来自于官网的描述)
安装MiniKube
一、准备
- BIOS 中启用 VT-x 或者 AMD-v 虚拟化(Linux系统可以执行命令:egrep --color 'vmx|svm' /proc/cpuinfo;结果不为空则表示已经开启)
二、安装
-
安装VirtualBox
image.png
- 安装kubectl(我使用的是Ubuntu,其它安装方式请参考官网)
kubectl是Kubernetes命令行工具,通过它可以部署和管理应用,查看各种资源、创建、删除和更新
sudo apt-get update && sudo apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubectl
- 安装Minikube
- 下载安装包
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \
&& chmod +x minikube
- copy到/usr/local/bin路径下
sudo cp minikube /usr/local/bin
三、启动
- 指定 VM driver类型
minkube start --vm-driver=virtualbox
VM Driver支持多种类型,详见官网
启动日志
$ minikube start --vm-driver=virtualbox
Starting local Kubernetes v1.13.2 cluster...
Starting VM...
Getting VM IP address...
Moving files into cluster...
Setting up certs...
Connecting to cluster...
Setting up kubeconfig...
Stopping extra container runtimes...
Starting cluster components...
Verifying kubelet health ...
Verifying apiserver health ...
Kubectl is now configured to use the cluster.
Loading cached images from config file.
Everything looks great. Please enjoy minikube!
- 体验MiniKube
- 部署应用
$ kubectl run hello-minikube --image=k8s.gcr.io/echoserver:1.10 --port=8080
deployment.apps/hello-minikube created
执行上述命令时,会出现下面命令废弃的提示信息:
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
- 访问应用
$ kubectl expose deployment hello-minikube --type=NodePort
service/hello-minikube exposed
#第一次执行时,创建Pod中
$ kubectl get pod
NAME READY STATUS RESTARTS AGE
hello-minikube-6fd785d459-4n5s8 0/1 ContainerCreating 0 27s
#第二次执行时,Pod创建完毕
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-minikube-6fd785d459-4n5s8 1/1 Running 0 13m
#获取服务地址
$ minikube service hello-minikube --url
http://192.168.99.105:30555
$ curl http://192.168.99.105:30555
Hostname: hello-minikube-6fd785d459-4n5s8
Pod Information:
-no pod information available-
Server values:
server_version=nginx: 1.13.3 - lua: 10008
Request Information:
client_address=172.17.0.1
method=GET
real path=/
query=
request_version=1.1
request_scheme=http
request_uri=http://192.168.99.105:8080/
Request Headers:
accept=*/*
host=192.168.99.105:30555
user-agent=curl/7.58.0
Request Body:
-no body in request-
- 启动 dashboard
$ minikube dashboard
Enabling dashboard ...
Verifying dashboard health ...
Launching proxy ...
Verifying proxy health ...
Opening http://127.0.0.1:46595/api/v1/namespaces/kube-system/services/http:kubernetes-dashboard:/proxy/ in your default browser...
[17270:17270:0131/140138.494733:ERROR:sandbox_linux.cc(364)] InitializeSandbox() called with multiple threads in process gpu-process.
浏览器中显示Dashboard

网友评论