K8s - Install Minikube in Windows

1 - 安装 minikube

宿主机环境

  • 操作系统: Windows 10
  • 虚拟化: VirtualBox 6.1.14

Install kubectl

下载kubectl.exe,然后加入到系统环境变量PATH

Install minikube

下载 minikube-windows-amd64.exe 文件,并重命名为minikube.exe,然后加入到系统环境变量PATH

从github下载

验证

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.0", GitCommit:"e19964183377d0ec2052d1f1fa930c4d7575bd50", GitTreeState:"clean", BuildDate:"2020-08-26T14:30:33Z", GoVersion:"go1.15", Compiler:"gc", Platform:"windows/amd64"}
Unable to connect to the server: dial tcp [::1]:8080: connectex: No connection could be made because the target machine actively refused it.

$ minikube version
minikube version: v1.13.0
commit: 23aa1eb200a03ae5883dd9d453d4daf3e0f59668

2 - 创建集群

命令

minikube start --vm-driver=virtualbox --image-mirror-country=cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers --iso-url=https://kubernetes.oss-cn-hangzhou.aliyuncs.com/minikube/iso/minikube-v1.7.3.iso --registry-mirror=https://reg-mirror.qiniu.com

选项说明

  • --vm-driver: 虚拟机驱动,默认自动检测,可选值 virtualbox, vmwarefusion, hyperv, vmware
  • --image-mirror-country : 镜像国家码,默认使用全球代码,中国大陆用户可设置为 cn
  • --image-repository: 拉取集群所需镜像的仓库
  • --iso-url: 加速下载虚拟机安装和启动所需的ISO文件
  • --registry-mirror: docker registry 的镜像源,集群安装后拉取镜像加速用,可以使用其它加速器地址
  • --cpu: 虚拟机CPU数量
  • --memory: 虚拟机内存大小
  • --disk-size: 虚拟机磁盘大小
  • 更多选项minikube start --help

示例

$ minikube start --vm-driver=virtualbox --image-mirror-country=cn --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
�  Microsoft Windows 10 Home China 10.0.18362 Build 18362 上的 minikube v1.13.0
✨  根据用户配置使用 virtualbox 驱动程序
✅  正在使用镜像存储库 registry.cn-hangzhou.aliyuncs.com/google_containers
�  正在下载 VM boot image...
    > minikube-v1.13.0.iso.sha256: 65 B / 65 B [-------------] 100.00% ? p/s 0s
    > minikube-v1.13.0.iso: 173.73 MiB / 173.73 MiB [ 100.00% 18.35 MiB p/s 10s
�  Starting control plane node minikube in cluster minikube
�  Creating virtualbox VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...
�  正在 Docker 19.03.12 中准备 Kubernetes v1.19.0…
    > kubectl.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubeadm.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubelet.sha256: 65 B / 65 B [--------------------------] 100.00% ? p/s 0s
    > kubectl: 41.01 MiB / 41.01 MiB [---------------] 100.00% 11.31 MiB p/s 4s
    > kubeadm: 37.30 MiB / 37.30 MiB [---------------] 100.00% 1.97 MiB p/s 19s
    > kubelet: 104.88 MiB / 104.88 MiB [-------------] 100.00% 4.87 MiB p/s 22s
�  Verifying Kubernetes components...
�  Enabled addons: default-storageclass, storage-provisioner
�  Done! kubectl is now configured to use "minikube" by default

$ minikube status
minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured


$ minikube service list
|-------------|------------|--------------|-----|
|  NAMESPACE  |    NAME    | TARGET PORT  | URL |
|-------------|------------|--------------|-----|
| default     | kubernetes | No node port |
| kube-system | kube-dns   | No node port |
|-------------|------------|--------------|-----|


$ minikube profile list
|----------|------------|---------|----------------|------|---------|---------|
| Profile  | VM Driver  | Runtime |       IP       | Port | Version | Status  |
|----------|------------|---------|----------------|------|---------|---------|
| minikube | virtualbox | docker  | 192.168.99.100 | 8443 | v1.19.0 | Running |
|----------|------------|---------|----------------|------|---------|---------|


$ minikube addons list
|-----------------------------|----------|--------------|
|         ADDON NAME          | PROFILE  |    STATUS    |
|-----------------------------|----------|--------------|
| ambassador                  | minikube | disabled     |
| dashboard                   | minikube | disabled     |
| default-storageclass        | minikube | enabled ✅   |
| efk                         | minikube | disabled     |
| freshpod                    | minikube | disabled     |
| gcp-auth                    | minikube | disabled     |
| gvisor                      | minikube | disabled     |
| helm-tiller                 | minikube | disabled     |
| ingress                     | minikube | disabled     |
| ingress-dns                 | minikube | disabled     |
| istio                       | minikube | disabled     |
| istio-provisioner           | minikube | disabled     |
| kubevirt                    | minikube | disabled     |
| logviewer                   | minikube | disabled     |
| metallb                     | minikube | disabled     |
| metrics-server              | minikube | disabled     |
| nvidia-driver-installer     | minikube | disabled     |
| nvidia-gpu-device-plugin    | minikube | disabled     |
| olm                         | minikube | disabled     |
| pod-security-policy         | minikube | disabled     |
| registry                    | minikube | disabled     |
| registry-aliases            | minikube | disabled     |
| registry-creds              | minikube | disabled     |
| storage-provisioner         | minikube | enabled ✅   |
| storage-provisioner-gluster | minikube | disabled     |
|-----------------------------|----------|--------------|


$ minikube service list
|-------------|------------|--------------|-----|
|  NAMESPACE  |    NAME    | TARGET PORT  | URL |
|-------------|------------|--------------|-----|
| default     | kubernetes | No node port |
| kube-system | kube-dns   | No node port |
|-------------|------------|--------------|-----|


$ minikube node list
minikube        192.168.99.100


$ kubectl get nodes
NAME       STATUS   ROLES    AGE   VERSION
minikube   Ready    master   62m   v1.19.0


$ kubectl get pods
No resources found in default namespace.


$ kubectl get pods -A
NAMESPACE              NAME                                        READY   STATUS    RESTARTS   AGE
kube-system            coredns-6c76c8bb89-8njsf                    1/1     Running   0          85m
kube-system            etcd-minikube                               1/1     Running   0          85m
kube-system            kube-apiserver-minikube                     1/1     Running   0          85m
kube-system            kube-controller-manager-minikube            1/1     Running   0          85m
kube-system            kube-proxy-r5vg6                            1/1     Running   0          85m
kube-system            kube-scheduler-minikube                     1/1     Running   0          85m
kube-system            storage-provisioner                         1/1     Running   0          85m
kubernetes-dashboard   dashboard-metrics-scraper-c95fcf479-znstc   1/1     Running   0          16m
kubernetes-dashboard   kubernetes-dashboard-5c448bc4bf-wtzmd       1/1     Running   0          16m


注意

minikube调用VirtualBox interface需要admin权限

执行minikube start将会自动创建C:\Users\<username>\.minikube目录

  • cache 文件夹缓存下载的文件
$ ls -la ~/.minikube/
total 52
drwxr-xr-x 1 anliven 197121    0 10月 23 22:29 ./
drwxr-xr-x 1 anliven 197121    0 10月 23 22:29 ../
drwxr-xr-x 1 anliven 197121    0 10月 23 22:26 addons/
-rw-r--r-- 1 anliven 197121 1066 10月 23 22:29 ca.crt
-rw-r--r-- 1 anliven 197121 1679 10月 23 22:29 ca.key
-rw-r--r-- 1 anliven 197121 1038 10月 23 22:27 ca.pem
drwxr-xr-x 1 anliven 197121    0 10月 23 22:28 cache/
-rw-r--r-- 1 anliven 197121 1078 10月 23 22:27 cert.pem
drwxr-xr-x 1 anliven 197121    0 10月 23 22:26 certs/
drwxr-xr-x 1 anliven 197121    0 10月 23 22:26 config/
drwxr-xr-x 1 anliven 197121    0 10月 23 22:26 files/
-rw-r--r-- 1 anliven 197121 1675 10月 23 22:27 key.pem
drwxr-xr-x 1 anliven 197121    0 10月 23 22:26 logs/
drwxr-xr-x 1 anliven 197121    0 10月 23 22:27 machines/
drwxr-xr-x 1 anliven 197121    0 10月 23 22:26 profiles/
-rw-r--r-- 1 anliven 197121 1074 10月 23 22:29 proxy-client-ca.crt
-rw-r--r-- 1 anliven 197121 1675 10月 23 22:29 proxy-client-ca.key

$ ls -la ~/.minikube/cache/
total 4
drwxr-xr-x 1 anliven 197121 0 10月 23 22:28 ./
drwxr-xr-x 1 anliven 197121 0 10月 23 22:29 ../
drwxr-xr-x 1 anliven 197121 0 10月 23 22:26 images/
drwxr-xr-x 1 anliven 197121 0 10月 23 22:26 iso/
drwxr-xr-x 1 anliven 197121 0 10月 23 22:28 linux/

3 - minikube ssh

执行minikube ssh可以进入到minikube虚拟机内部,但建议通过终端工具SSH登入

  1. 执行minikube ip获取minikube虚拟机的IP地址
  2. SSH用户名: docker
  3. 认证方式: Public Key
  4. 私钥文件: .minikube\machines\minikube\id_rsa
$ minikube ip
192.168.99.100


$ minikube ssh
                         _             _
            _         _ ( )           ( )
  ___ ___  (_)  ___  (_)| |/')  _   _ | |_      __
/' _ ` _ `\| |/' _ `\| || , <  ( ) ( )| '_`\  /'__`\
| ( ) ( ) || || ( ) || || |\`\ | (_) || |_) )(  ___/
(_) (_) (_)(_)(_) (_)(_)(_) (_)`\___/'(_,__/'`\____)

$ docker ps
CONTAINER ID        IMAGE                                                           COMMAND                  CREATED             STATUS              PORTS               NAMES
448f70c7f8e2        kubernetesui/metrics-scraper                                    "/metrics-sidecar"       10 minutes ago      Up 10 minutes                           k8s_dashboard-metrics-scraper_dashboard-metrics-scraper-c95fcf479-znstc_kubernetes-dashboard_7a3e77c6-093d-4154-822b-7baf21145cb1_0
55a85ae3c2ad        kubernetesui/dashboard                                          "/dashboard --insecu…"   10 minutes ago      Up
10 minutes                           k8s_kubernetes-dashboard_kubernetes-dashboard-5c448bc4bf-wtzmd_kubernetes-dashboard_69701406-e4ec-4a60-b6c0-d945a745a180_0
5d15da4f6606        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 10 minutes ago      Up 10 minutes                           k8s_POD_dashboard-metrics-scraper-c95fcf479-znstc_kubernetes-dashboard_7a3e77c6-093d-4154-822b-7baf21145cb1_0
864559bce79a        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 10 minutes ago      Up 10 minutes                           k8s_POD_kubernetes-dashboard-5c448bc4bf-wtzmd_kubernetes-dashboard_69701406-e4ec-4a60-b6c0-d945a745a180_0
34432b64b1ff        bad58561c4be                                                    "/storage-provisioner"   About an hour ago   Up About an hour                        k8s_storage-provisioner_storage-provisioner_kube-system_e757cda2-612f-4a67-9727-523e80221162_0
7890bf43797a        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About an hour ago   Up About an hour                        k8s_POD_storage-provisioner_kube-system_e757cda2-612f-4a67-9727-523e80221162_0
f27b7bf41f1f        bfe3a36ebd25                                                    "/coredns -conf /etc…"   About an hour ago   Up
About an hour                        k8s_coredns_coredns-6c76c8bb89-8njsf_kube-system_455e485c-1373-4f0f-bac5-7ed64a6a56ce_0
7bfb425cf8cb        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About an hour ago   Up About an hour                        k8s_POD_coredns-6c76c8bb89-8njsf_kube-system_455e485c-1373-4f0f-bac5-7ed64a6a56ce_0
1896d79c4c35        bc9c328f379c                                                    "/usr/local/bin/kube…"   About an hour ago   Up
About an hour                        k8s_kube-proxy_kube-proxy-r5vg6_kube-system_cfe16a25-94fa-424b-a75d-e819bac57068_0
8bd0bc430e96        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About an hour ago   Up About an hour                        k8s_POD_kube-proxy-r5vg6_kube-system_cfe16a25-94fa-424b-a75d-e819bac57068_0
21c54a187d46        d4ca8726196c                                                    "etcd --advertise-cl…"   About an hour ago   Up
About an hour                        k8s_etcd_etcd-minikube_kube-system_e9aabf1795110e3aa8779deb082e84c6_0
314b4160ecc5        cbdc8369d8b1                                                    "kube-scheduler --au…"   About an hour ago   Up
About an hour                        k8s_kube-scheduler_kube-scheduler-minikube_kube-system_a58b14f747704acef7fc4d3a19ced088_0
07681229f3f8        09d665d529d0                                                    "kube-controller-man…"   About an hour ago   Up
About an hour                        k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_45ac13b940779ae8f250c55c1b668de4_0
152f08e101aa        1b74e93ece2f                                                    "kube-apiserver --ad…"   About an hour ago   Up
About an hour                        k8s_kube-apiserver_kube-apiserver-minikube_kube-system_b9d786c0c16e0c94627f9bd2f22955eb_0
4e44a7106e31        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About an hour ago   Up About an hour                        k8s_POD_etcd-minikube_kube-system_e9aabf1795110e3aa8779deb082e84c6_0
ef6cd7886928        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About an hour ago   Up About an hour                        k8s_POD_kube-scheduler-minikube_kube-system_a58b14f747704acef7fc4d3a19ced088_0
22653f97f0ef        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About an hour ago   Up About an hour                        k8s_POD_kube-controller-manager-minikube_kube-system_45ac13b940779ae8f250c55c1b668de4_0
0cce920163b3        registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.2   "/pause"                 About an hour ago   Up About an hour                        k8s_POD_kube-apiserver-minikube_kube-system_b9d786c0c16e0c94627f9bd2f22955eb_0
$
$ docker images
REPOSITORY                                                                    TAG                 IMAGE ID            CREATED
     SIZE
registry.cn-hangzhou.aliyuncs.com/google_containers/storage-provisioner       v3                  bad58561c4be        7 weeks ago
     29.7MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy                v1.19.0             bc9c328f379c        8 weeks ago
     118MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver            v1.19.0             1b74e93ece2f        8 weeks ago
     119MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller-manager   v1.19.0             09d665d529d0        8 weeks ago
     111MB
registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler            v1.19.0             cbdc8369d8b1        8 weeks ago
     45.7MB
registry.cn-hangzhou.aliyuncs.com/google_containers/etcd                      3.4.9-1             d4ca8726196c        3 months ago
     253MB
registry.cn-hangzhou.aliyuncs.com/google_containers/dashboard                 v2.0.3              503bc4b7440b        4 months ago
     225MB
kubernetesui/dashboard                                                        v2.0.3              503bc4b7440b        4 months ago
     225MB
registry.cn-hangzhou.aliyuncs.com/google_containers/coredns                   1.7.0               bfe3a36ebd25        4 months ago
     45.2MB
kubernetesui/metrics-scraper                                                  v1.0.4              86262685d9ab        7 months ago
     36.9MB
registry.cn-hangzhou.aliyuncs.com/google_containers/metrics-scraper           v1.0.4              86262685d9ab        7 months ago
     36.9MB
registry.cn-hangzhou.aliyuncs.com/google_containers/pause                     3.2                 80d28bedfe5d        8 months ago
     683kB
$
$ exit
logout

4 - 启动dashboard

执行minikube dashboard命令会自动打开浏览器,进入 Dashboard

$ minikube dashboard
�  正在开启 dashboard ...
�  正在验证 dashboard 运行情况 ...
�  Launching proxy ...
�  正在验证 proxy 运行状况 ...
�  Opening http://127.0.0.1:51609/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default
browser...

5 - References

posted @ 2020-10-24 00:06  Anliven  阅读(869)  评论(0编辑  收藏  举报