Minikube 使用

背景介绍
Minikube是什么?

Minikube是一个能够在虚拟机中运行单节点Kubernetes集群的工具,它使得开发者可以在本地环境中进行开发和调试Kubernetes。推荐阿里封装的minikube

Kubernetes又是什么?

Kubernetes是一个用来自动部署、伸缩、和管理容器化应用的开源系统。
容器又是什么?

容器指的是运用虚拟化技术将不同应用和其所需的运行环境进行隔离的进程,其中Docker是最著名的开源容器软件。

容器又是什么?

容器指的是运用虚拟化技术将不同应用和其所需的运行环境进行隔离的进程,其中Docker是最著名的开源容器软件。

  • 我有几个项目使用的不同Node.js版本,开发调试需要进行切换很不方便。——容器的虚拟运行环境可以解决
  • 每次部署都要重新安装依赖,而且不同环境依赖安装后可能出现问题。——打包成镜像,无需再安装依赖,秒级启动。
  • 我想创建几个同样的进程做负载均衡/高可用。——用Kubernetes创建容器副本。
  • 我希望我的进程在生产环境中挂掉或者被误杀之后自动重新启动。——用Kubernetes的自愈功能操作容器。
  • 根据不同机器的资源使用情况来分配进程。——用Kubernetes来调度容器。

Hyper-V(Windows8以上的系统默认已安装)

首先minikube start会默认使用VirtualBox,但是我们用的是Hyper-V,所以需要加参数指定:

minikube start --vm-driver=hyperv

还记得我们之前创建的虚拟网络交换机吗?这时候就需要用到它了。

minikube start --vm-driver=hyperv --hyperv-virtual-switch=k8svswitch

默认不显示错误信息,为了方便排查启动中的问题,我们还是开启日志输出。

minikube start --vm-driver=hyperv --hyperv-virtual-switch=k8svswitch --v=3 --alsologtostderr

默认需要2048Mb内存,如果不够我们需要--memory 1024指定一下更小的空间,当然我的机器10Gb的内存不可能不够,这个参数省略了~

管理员模式打开命令行,执行上面那条minikube start ...开头的命令。

执行完成之后输入kubectl cluster-info dump,看到集群的大量详细信息表示安装成功~

如果按照以上步骤仍不成功,可以参考国外网友的一篇文章

《Run k8s minikube on Windows 10 with Hyper-V》https://gibmirfred.de/2017/02/run-k8s-minikube-on-windows-10-with-hyper-v/

1.1 MINIKUBE BASIC
Name Command
minikube lifecycle minikube delete, minikube start, minikube status, Link: minikube
Get minikube version minikube version, Link: all minikube releases
mac install minikube brew cask install minikube, brew cask reinstall minikube
Start minikube with different machine flavor minikube start --memory 5120 --cpus=4
Start minikube with a specific k8s version minikube start --kubernetes-version v1.11.0
Start minikube with more customizations minikube start –kubernetes-version v1.11.0 –feature-gates=AdvancedAuditing=true
SSH to minikube vm minikube ssh, ssh -i ~/.minikube/machines/minikube/id_rsa docker@192.168.99.100
Your local docker to use minikube dockerd eval $(minikube docker-env), Then no need for docker push
Minikube check latest version minikube update-check
Reference Minikube CheatSheet, Kubernetes kind CheatSheet
Reference Kubectl CheatSheet, Kubernetes Yaml
1.2 CHECK STATUS
Name Command
Get minikube version minikube version, Link: all minikube releases
Get cluster info kubectl cluster-info
Get service info minikube service
Get dashboard minikube dashboard
Get ip minikube ip
Get minikube log minikube logs
List addons minikube addons list
1.3 MINIKUBE FOLDERS
Name Command
Mount host OS’s folder to minikube VM minikube mount /host-mount-path:/vm-mount-path
Folder of k8s.io/minikube-hostpath provisioner /tmp/hostpath-provisioner, /tmp/hostpath_pv
Mount host OS’s folder to minikube VM minikube mount /host-mount-path:/vm-mount-path
Critical minikube folder /var/lib/localkube, /var/lib/docker, /data
Check minikube config in your host OS desktop ~/.minikube/machines/minikube/config.json
Minikube conf in local env ~/.minikube, ~/.kube
1.4 MINIKUBE ADVANCED
Name Command
Install addon after creating minikube env minikube addons enable heapster, kubectl top node
1.5 MINIKUBE CLI ONLINE HELP

minikube version
minikube version: v0.31.0

minikube --help
Minikube is a CLI tool that provisions and manages single-node Kubernetes clusters optimized for development workflows.

Usage:
minikube [command]

Available Commands:
addons Modify minikube's kubernetes addons
cache Add or delete an image from the local cache.
completion Outputs minikube shell completion for the given shell (bash or zsh)
config Modify minikube config
dashboard Access the kubernetes dashboard running within the minikube cluster
delete Deletes a local kubernetes cluster
docker-env Sets up docker env variables; similar to '$(docker-machine env)'
help Help about any command
ip Retrieves the IP address of the running cluster
logs Gets the logs of the running instance, used for debugging minikube, not user code
mount Mounts the specified directory into minikube
profile Profile sets the current minikube profile
service Gets the kubernetes URL(s) for the specified service in your local cluster
ssh Log into or run a command on a machine with SSH; similar to 'docker-machine ssh'
ssh-key Retrieve the ssh identity key path of the specified cluster
start Starts a local kubernetes cluster
status Gets the status of a local kubernetes cluster
stop Stops a running local kubernetes cluster
tunnel tunnel makes services of type LoadBalancer accessible on localhost
update-check Print current and latest version number
update-context Verify the IP address of the running cluster in kubeconfig.
version Print the version of minikube

Flags:
--alsologtostderr log to standard error as well as files
-b, --bootstrapper string The name of the cluster bootstrapper that will set up the kubernetes cluster. (default "kubeadm")
-h, --help help for minikube
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files
-p, --profile string The name of the minikube VM being used.
This can be modified to allow for multiple minikube instances to be run independently (default "minikube")
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging

Use "minikube [command] --help" for more information about a command.