這是我參與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
複製代碼