minikube 安装

minikube 是一个用于在本地计算机上运行单个节点的 k8s 集群的工具。它允许开发人员可以在自己的计算机上进行本地的 k8s 开发和测试。通过minikube,您可以模拟一个完整的 k8s 集群环境,包括节点、Pod、服务和存储等组件。它是一个轻量级、易于安装和使用的工具,适用于在本地进行 k8s 相关的开发、测试和学习。

徒手搭建过 k8s 的同学都晓得其中的煎熬,复杂的认证,配置环节相当折磨人,出错率相当高,而 minikube 就是为解决这个问题而衍生出来的工具,minikube 可以在单机环境下快速搭建可用的 k8s 集群,非常适合测试和本地开发,现有的大部分在线 k8s 实验环境也是基于 minikube 的。

可以在 minikube 上体验 kubernetes 的相关功能。

minikube 基于 go 语言开发,可以在单机环境下快速搭建可用的 k8s 集群,快速启动,消耗机器资源较少,可在你的笔记本电脑上的虚拟机内轻松创建单机版 k8s 集群,非常适合测试和本地开发。

minikube 架构

下图是 minikube的架构,可以看出,master 节点与其它节点合为一体,而整体则通过宿主机上的 kubectl 进行管理,这样可以更加节省资源。

k8s入门到实战(二)—— windows安装minikube-LMLPHP

其支持大部分 k8s 的功能,列表如下:

DNS
NodePorts
ConfigMaps and Secrets
Dashboards
Container Runtime: Docker, and rkt
Enabling CNI (Container Network Interface)
Ingress
…

minikube 支持 Windows、macOS、Linux 三种 OS系统,会根据平台不同,下载对应的虚拟机镜像,并在镜像内安装 K8S。

我们这里直接使用 Windows 安装体验。

minikube 安装

下载步骤:

  1. 安装 docker
  • 下载地址:https://docs.docker.com/desktop/install/windows-install/

  • 知道下载后的 Docker for Windows Installer 安装文件,完成安装。

  • 安装好之后会重启

k8s入门到实战(二)—— windows安装minikube-LMLPHP

安装好后如图所示

  1. 安装 minikube

minikube 下载地址 https://minikube.sigs.k8s.io/docs/start/

1、点击这里下载安装程序minikube-installer.exe,安装即可

k8s入门到实战(二)—— windows安装minikube-LMLPHP

2、配置环境变量

3、命令行测试,需要保证 docker 启动

minikube 常用命令

minikube version
C:\Users\DELL>minikube version
W0323 17:19:55.916748    1800 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
minikube version: v1.32.0
commit: 8220a6eb95f0a4d75f7f2d7b14cef975f050512d
minikube start
C:\Users\DELL>minikube start
W0323 17:24:17.006260   23440 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
* Microsoft Windows 11 Home China 10.0.22631.3296 Build 22631.3296 上的 minikube v1.32.0
* 根据现有的配置文件使用 docker 驱动程序
* 正在集群 minikube 中启动控制平面节点 minikube
* 正在拉取基础镜像 ...
    > index.docker.io/kicbase/sta...:  453.90 MiB / 453.90 MiB  100.00% 2.61 Mi
! minikube was unable to download gcr.io/k8s-minikube/kicbase:v0.0.42, but successfully downloaded docker.io/kicbase/stable:v0.0.42 as a fallback image
* Creating docker container (CPUs=2, Memory=4000MB) ...
* 正在 Docker 24.0.7 中准备 Kubernetes v1.28.3…
  - 正在生成证书和密钥...
  - 正在启动控制平面...
  - 配置 RBAC 规则 ...
* 配置 bridge CNI (Container Networking Interface) ...
* 正在验证 Kubernetes 组件...
  - 正在使用镜像 gcr.io/k8s-minikube/storage-provisioner:v5
* 启用插件: storage-provisioner, default-storageclass
* 完成!kubectl 现在已配置,默认使用"minikube"集群和"default"命名空间
minikube status
C:\Users\DELL>minikube status
W0323 17:30:34.612462    4616 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured
minikube ip
C:\Users\DELL>minikube ip
W0323 17:31:38.368205    2484 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
192.168.49.2
minikube ssh
C:\Users\DELL>minikube ssh
W0323 17:34:12.883919   24608 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
# 查看集群下所有的 docker 容器
docker@minikube:~$ docker ps
CONTAINER ID   IMAGE                       COMMAND                  CREATED         STATUS         PORTS     NAMES
1407610b3a2f   6e38f40d628d                "/storage-provisioner"   6 minutes ago   Up 6 minutes             k8s_storage-provisioner_storage-provisioner_kube-system_d4ee5dfb-c7e0-441c-baa2-12474b5ad5c4_1
f6403b614117   ead0a4a53df8                "/coredns -conf /etc…"   7 minutes ago   Up 7 minutes             k8s_coredns_coredns-5dd5756b68-w9wgv_kube-system_0a9ad253-2304-447e-8ab3-2f06da88a721_0
606d3bac1dbb   registry.k8s.io/pause:3.9   "/pause"                 7 minutes ago   Up 7 minutes             k8s_POD_coredns-5dd5756b68-w9wgv_kube-system_0a9ad253-2304-447e-8ab3-2f06da88a721_0
4cdfd56f9d60   bfc896cf80fb                "/usr/local/bin/kube…"   7 minutes ago   Up 7 minutes             k8s_kube-proxy_kube-proxy-cdq9d_kube-system_2f2aca3c-4d8c-45c1-8efc-b7d0d4938025_0
821e8c045d0c   registry.k8s.io/pause:3.9   "/pause"                 7 minutes ago   Up 7 minutes             k8s_POD_kube-proxy-cdq9d_kube-system_2f2aca3c-4d8c-45c1-8efc-b7d0d4938025_0
c7f05331626d   registry.k8s.io/pause:3.9   "/pause"                 7 minutes ago   Up 7 minutes             k8s_POD_storage-provisioner_kube-system_d4ee5dfb-c7e0-441c-baa2-12474b5ad5c4_0
ae5966109c8a   6d1b4fd1b182                "kube-scheduler --au…"   7 minutes ago   Up 7 minutes             k8s_kube-scheduler_kube-scheduler-minikube_kube-system_75ac196d3709dde303d8a81c035c2c28_0
49f497991344   10baa1ca1706                "kube-controller-man…"   7 minutes ago   Up 7 minutes             k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_7da72fc2e2cfb27aacf6cffd1c72da00_0
51420b3b4a70   73deb9a3f702                "etcd --advertise-cl…"   7 minutes ago   Up 7 minutes             k8s_etcd_etcd-minikube_kube-system_9aac5b5c8815def09a2ef9e37b89da55_0
982fdca2d503   537434729123                "kube-apiserver --ad…"   7 minutes ago   Up 7 minutes             k8s_kube-apiserver_kube-apiserver-minikube_kube-system_55b4bbe24dac3803a7379f9ae169d6ba_0
7f2976f13746   registry.k8s.io/pause:3.9   "/pause"                 7 minutes ago   Up 7 minutes             k8s_POD_kube-scheduler-minikube_kube-system_75ac196d3709dde303d8a81c035c2c28_0
b2b10a4815fa   registry.k8s.io/pause:3.9   "/pause"                 7 minutes ago   Up 7 minutes             k8s_POD_kube-controller-manager-minikube_kube-system_7da72fc2e2cfb27aacf6cffd1c72da00_0
eff72a86aa15   registry.k8s.io/pause:3.9   "/pause"                 7 minutes ago   Up 7 minutes             k8s_POD_kube-apiserver-minikube_kube-system_55b4bbe24dac3803a7379f9ae169d6ba_0
7236c52d6a38   registry.k8s.io/pause:3.9   "/pause"                 7 minutes ago   Up 7 minutes             k8s_POD_etcd-minikube_kube-system_9aac5b5c8815def09a2ef9e37b89da55_0
minikube stop
minikube dashboard
C:\Users\DELL>minikube dashboard
W0323 17:40:48.423278   11632 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
* 正在开启 dashboard ...
  - 正在使用镜像 docker.io/kubernetesui/dashboard:v2.7.0
  - 正在使用镜像 docker.io/kubernetesui/metrics-scraper:v1.0.8
* 某些 dashboard 功能需要启用 metrics-server 插件。为了启用所有功能,请运行以下命令:

        minikube addons enable metrics-server


* 正在验证 dashboard 运行情况 ...
* 正在启动代理...
* 正在验证 proxy 运行状况 ...
^C
C:\Users\DELL>minikube dashboard
W0323 17:41:42.866075   25216 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
* 正在验证 dashboard 运行情况 ...
* 正在启动代理...
* 正在验证 proxy 运行状况 ...
* 正在使用默认浏览器打开 http://127.0.0.1:59903/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ ...

k8s入门到实战(二)—— windows安装minikube-LMLPHP

minikube stop
C:\Users\DELL>minikube stop
W0323 17:53:55.131539   25916 main.go:291] Unable to resolve the current Docker CLI context "default": context "default": context not found: open C:\Users\DELL\.docker\contexts\meta\37a8eec1ce19687d132fe29051dca629d164e2c4958ba141d5f4133a33f0688f\meta.json: The system cannot find the path specified.
* 正在停止节点 "minikube" ...
* 正在通过 SSH 关闭“minikube”…
* 1 个节点已停止。
# 获取所有节点
kubectl get node
C:\Users\DELL>kubectl get node
NAME       STATUS   ROLES           AGE   VERSION
minikube   Ready    control-plane   17m   v1.28.3
# 获取所有命名空间中的Pod列表
kubectl get pods -A
C:\Users\DELL>kubectl get pods -A
NAMESPACE              NAME                                         READY   STATUS    RESTARTS      AGE
kube-system            coredns-5dd5756b68-w9wgv                     1/1     Running   0             19m
kube-system            etcd-minikube                                1/1     Running   0             19m
kube-system            kube-apiserver-minikube                      1/1     Running   0             19m
kube-system            kube-controller-manager-minikube             1/1     Running   0             19m
kube-system            kube-proxy-cdq9d                             1/1     Running   0             19m
kube-system            kube-scheduler-minikube                      1/1     Running   0             19m
kube-system            storage-provisioner                          1/1     Running   1 (18m ago)   19m
kubernetes-dashboard   dashboard-metrics-scraper-7fd5cb4ddc-lxkt2   1/1     Running   0             7m45s
kubernetes-dashboard   kubernetes-dashboard-8694d4445c-sl6cc        1/1     Running   0             7m45s
03-26 23:06