Minikube简介
Minikube是一种轻量级的Kubernetes实现,可在本地计算机上创建VM并部署仅包含一个节点的简单集群,Minikube可用于Linux、MacOS和Windows系统。Minikube CLI提供了用于引导集群工作的多种操作,包括启动、停止、查看状态和删除。
安装
https://minikube.sigs.k8s.io/docs/start/
- rpm安装
# curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-latest.x86_64.rpm
# rpm -Uvh minikube-latest.x86_64.rpm
- 如果你使用的是root用户的话会无法启动并提示如下信息,那是因为Minikube不允许使用root权限启动,需要创建一个非root账号再启动;
* minikube v1.24.0 on Centos 7.9.2009
* Using the docker driver based on existing profile
* The "docker" driver should not be used with root privileges.
* If you are running minikube within a VM, consider using --driver=none:
* https://minikube.sigs.k8s.io/docs/reference/drivers/none/
* Tip: To remove this root owned cluster, run: sudo minikube delete
X Exiting due to DRV_AS_ROOT: The "docker" driver should not be used with root privileges.
- 这里创建了一个属于docker用户组的test用户,并切换到该用户;
# 创建用户
useradd -u 1024 -g docker test
# 设置用户密码
passwd test
# 切换用户
su test
- 再次使用minikube start命令启动Minikube,启动成功后会显示如下信息:
* To pull new external images, you may need to configure a proxy: https://minikube.sigs.k8s.io/docs/reference/networking/proxy/
* Preparing Kubernetes v1.22.3 on Docker 20.10.8 ...
* Verifying Kubernetes components...
- Using image kubernetesui/metrics-scraper:v1.0.7
- Using image gcr.io/k8s-minikube/storage-provisioner:v5
- Using image kubernetesui/dashboard:v2.3.1
* Enabled addons: default-storageclass, storage-provisioner, dashboard
* 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
创建集群
通过Minikube我们可以创建一个单节点的K8S集群,集群管理Master和负责运行应用的Node都部署在此节点上。
- 查看minikube的版本号:
minikube version
minikube version: v1.24.0
commit: 76b94fb3c4e8ac5062daf70d60cf03ddcc0a741b
- 查看kubectl的版本号,第一次使用会直接安装kubectl:
minikube kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:41:28Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.3", GitCommit:"c92036820499fedefec0f847e2054d824aea6cd1", GitTreeState:"clean", BuildDate:"2021-10-27T18:35:25Z", GoVersion:"go1.16.9", Compiler:"gc", Platform:"linux/amd64"}
- 如果你想直接使用kubectl命令的话,可以将其复制到/bin目录下去:
# 查找kubectl命令的位置
find / -name kubectl
# 找到之后复制到/bin目录下
cp /var/lib/docker/volumes/minikube/_data/lib/minikube/binaries/v1.22.3/kubectl /bin/
# 直接使用kubectl命令
kubectl version
Client Version: version.Info{Major:"1", Minor:"22",……
Server Version: version.Info{Major:"1", Minor:"22",……
- 查看集群详细信息:
kubectl cluster-info
Kubernetes control plane is running at https://192.168.49.2:8443
CoreDNS is running at https://192.168.49.2:8443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.
- 查看集群中所有的Node,可以发现minikube创建了一个单节点的简单集群:
kubectl get nodes
NAME STATUS ROLES AGE VERSION
minikube Ready control-plane,master 43h v1.22.3
部署应用
一旦运行了K8S集群,就可以在其上部署容器化应用程序。通过创建Deployment对象,可以指挥K8S如何创建和更新应用程序的实例。
指定好应用镜像并创建一个Deployment,启动服务
kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
查看所有部署kubectl get delopyment