这是我参与8月更文挑战的第1天,活动详情查看:8月更文挑战node
最近须要给开发相关同时培训K8s,集群方式部署负责且占用资源多,简单快捷高效的单机版K8s环境,可谓开发人员不错的选择,minikube就是为解决这个问题而衍生出来的工具,它基于go语言开发, 是一个易于在本地运行 Kubernetes 的工具,可在你的笔记本电脑上的虚拟机内轻松建立单机版 Kubernetes 集群。便于尝试 Kubernetes 或使用 Kubernetes 平常开发。能够在单机环境下快速搭建可用的k8s集群,很是适合测试和本地开发。若是没有服务器或在本地笔记本安装,则能够在线使用labs.play-with-k8s.com/来体验K8s。linux
为了运行和管理 Kubernetes 的组件,Minikube 中使用了 Spread's 的 localkube,localkube 是一个独立的 Go 语言的二进制包,包含了全部 Kubernetes 的主要组件,而且以不一样的 goroutine 来运行。git
为了支持 MacOS 和 Windows,Minikube 在内部使用 libmachine 建立或销毁虚拟机,能够将它理解为一个虚拟机的驱动程序。至于在 Linux 上,因为集群能够直接本地运行,因此避免设置虚拟机。github
能够今后连接下载:www.virtualbox.org/wiki/Downlo…docker
brew install kubectl
复制代码
官方出品的minikube,默认链接的是google官方站点,因为众所周知的缘由能够利用阿里云修改过的minikube,目前已经替换了其中国外的镜像源shell
curl -Lo minikube http://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v0.30.0/minikube-darwin-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
复制代码
minikube start --vm-driver=virtualbox --registry-mirror=https://registry.docker-cn.com
复制代码
注:若是首次失败了(好比:步骤一中的安全设置没勾选,致使没法启用),能够先尝试minikute delete 删除原来的machine。bootstrap
CentOS 7.8
复制代码
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum clean all && yum makecache fast
yum -y install docker-ce
systemctl start docker
复制代码
curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.18.0/bin/linux/amd64/kubectl &&\
chmod +x ./kubectl &&\
mv ./kubectl /usr/bin/kubectl
复制代码
$ curl -Lo minikube https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/releases/v1.18.1/minikube-linux-amd64 && $ chmod +x minikube && sudo mv minikube /usr/local/bin/
# 使用docker驱动不能使用root用户,新建minikube用户用于启动
$ useradd minikube
$ usermod -a -G docker minikube
$ su minikube
# 切换到minikube用户进行安装
$ minikube start --driver=docker
😄 Centos 7.9.2009 (amd64) 上的 minikube v1.18.1
🎉 minikube 1.20.0 is available! Download it: https://github.com/kubernetes/minikube/releases/tag/v1.20.0
💡 To disable this notice, run: 'minikube config set WantUpdateNotification false'
✨ 根据用户配置使用 docker 驱动程序
👍 Starting control plane node minikube in cluster minikube
🚜 Pulling base image ...
🔥 Creating docker container (CPUs=2, Memory=2200MB) ...
> kubelet.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubectl.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubeadm.sha256: 64 B / 64 B [--------------------------] 100.00% ? p/s 0s
> kubectl: 38.37 MiB / 38.37 MiB [---------------] 100.00% 2.68 MiB p/s 14s
> kubeadm: 37.40 MiB / 37.40 MiB [---------------] 100.00% 2.18 MiB p/s 17s
> kubelet: 108.73 MiB / 108.73 MiB [-------------] 100.00% 4.11 MiB p/s 26s
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
🔎 Verifying Kubernetes components...
▪ Using image registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner:v4 (global image repository)
🌟 Enabled addons: storage-provisioner, default-storageclass
💡 kubectl not found. If you need it, try: 'minikube kubectl -- get pods -A'
🏄 Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
### 查看信息
$ kubectl cluster-info
### 进入到minikube
$ minikube ssh
$ docker ps
复制代码
使用下列命令能够打开控制面板,自动跳转浏览器查看centos
minikube dashboard
复制代码
使用下面命令能够查看虚拟机ipapi
minikube ip
复制代码
查看状态使用下面命令浏览器
minikube status
复制代码
其余命令可使用minikube —help查看帮助,以下
➜ bin 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
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.
复制代码
随后使用k8s的命令便可在本机进行测试,如
kubectl get pods
复制代码