K8S的学习之旅-基于docker desktop安装minikube
K8S的学习之旅-安装minikube安装 docker desktop取消settings中的use the WSL 2 based enginedocker desktop 默认已经安装了kubectl安装minikube启动集群minikube start启动失败,提示* Microsoft Windows 10 Education 10.0.18363 Build 18363 上的 min
·
K8S的学习之旅-安装minikube
安装 docker desktop
取消settings中的use the WSL 2 based engine
- docker desktop 默认已经安装了kubectl
安装minikube
启动集群
minikube start
启动失败,提示
* Microsoft Windows 10 Education 10.0.18363 Build 18363 上的 minikube v1.16.0
* Unable to pick a default driver. Here is what was considered, in preference order:
- vmware: Not installed: exec: "docker-machine-driver-vmware": executable file not found in %PATH%
- docker: Not installed: exec: "docker": executable file not found in %PATH%
- hyperv: Not healthy: Hyper-V requires Administrator privileges
- podman: Not installed: exec: "podman": executable file not found in %PATH%
- virtualbox: Not installed: unable to find VBoxManage in $PATH
原因是没有默认的驱动,这里选择的是docker做为driver。
minikube支持的driver有五种
- vmware
- docker
- hyperv
- podman
- virtualbox
vmware、virtualbox相信装过虚拟机的同学都知道这两个虚拟机应用程序。
docker是比虚拟机还轻量的容器技术。
hyper-v是Windows系统的本地虚拟机管理程序,可在程序与功能->启用或关闭 Windows功能中查看到。
podman则是一个无守护进程的容器引擎,用于在Linux上开发、运行或管理OCI容器。
- 查看docker是否开启
docker -v
- 成功启动docker后,再次启动集群
minikube start
-
自动下载driver,拉去image
-
完成后有默认的命名空间(获取命名空间:kubectl get ns)
C:\Users\Caisi>kubectl get ns
NAME STATUS AGE
default Active 30m
kube-node-lease Active 30m
kube-public Active 30m
kube-system Active 30m
- 查看集群运行情况
C:\Users\Caisi>kubectl get pod -A
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-system coredns-74ff55c5b-jcpt7 1/1 Running 0 48m
kube-system etcd-minikube 1/1 Running 0 48m
kube-system kube-apiserver-minikube 1/1 Running 0 48m
kube-system kube-controller-manager-minikube 1/1 Running 0 48m
kube-system kube-proxy-mj5vg 1/1 Running 0 48m
kube-system kube-scheduler-minikube 1/1 Running 0 48m
kube-system storage-provisioner 1/1 Running 1 48m
都启动成功
- 启动minikube dashboard控制台
C:\Users\Caisi>minikube dashboard
* 正在开启 dashboard ...
* 正在验证 dashboard 运行情况 ...
* Launching proxy ...
* 正在验证 proxy 运行状况 ...
* Opening http://127.0.0.1:53756/api/v1/namespaces/kubernetes-dashboard/services/http:kubernetes-dashboard:/proxy/ in your default browser...
部署示例应用(这里是个坑,看看就可以了)
- 创建应用
C:\Users\Caisi>kubectl create deployment hello-minikube --image=k8s.gcr.io/echoserver:1.4
deployment.apps/hello-minikube created
- 公开应用端口(在集群中)
C:\Users\Caisi>kubectl expose deployment hello-minikube --type=NodePort --port=8080
service/hello-minikube exposed
- 查看服务
C:\Users\Caisi>kubectl get services hello-minikube
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.111.191.44 <none> 8080:32207/TCP 20s
- 查看pod容器启动情况
C:\Users\Caisi>kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-minikube-6ddfcc9757-mbtkk 0/1 ImagePullBackOff 0 7m54s
这里显示镜像拉取失败了
- 使用命令查看pod运行详情
C:\Users\Caisi>kubectl describe pods hello-minikube-6ddfcc9757-mbtkk
Name: hello-minikube-6ddfcc9757-mbtkk
Namespace: default
Priority: 0
Node: minikube/192.168.49.2
···
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 8m14s default-scheduler Successfully assigned default/hello-minikube-6ddfcc9757-mbtkk to minikube
Normal Pulling 5m51s (x4 over 8m13s) kubelet Pulling image "k8s.gcr.io/echoserver:1.4"
Warning Failed 5m36s (x4 over 7m58s) kubelet Failed to pull image "k8s.gcr.io/echoserver:1.4": rpc error: code = Unknown desc = Error response from daemon: Get https://k8s.gcr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
Warning Failed 5m36s (x4 over 7m58s) kubelet Error: ErrImagePull
Warning Failed 5m9s (x7 over 7m57s) kubelet Error: ImagePullBackOff
Normal BackOff 3m2s (x15 over 7m57s) kubelet Back-off pulling image "k8s.gcr.io/echoserver:1.4"
- 也可以通过minikube bashboard查看
这里出现问题的原因是k8s.gcr.io是国外Google的网站,国内无法访问,也就拉取不了镜像了。
##真正成功的部署示例应用
解决方法是使用国内的镜像源如:aliyuncs
删除刚刚的deployment和service
C:\Users\Caisi>kubectl delete deployment hello-minikube
deployment.apps "hello-minikube" deleted
C:\Users\Caisi>kubectl delete service hello-minikube
service "hello-minikube" deleted
- 重新创建应用
C:\Users\Caisi>kubectl create deployment hello-minikube --image=registry.cn-hangzhou.aliyuncs.com/google_containers/echoserver:1.10
deployment.apps/hello-minikube created
C:\Users\Caisi>kubectl get pods
NAME READY STATUS RESTARTS AGE
hello-minikube-8947b65df-g78l7 1/1 Running 0 88s
可以看到pod已经运行成功了
- 重新设置集群公开端口
C:\Users\Caisi>kubectl expose deployment hello-minikube --type=NodePort --port=8080
service/hello-minikube exposed
C:\Users\Caisi>kubectl get services hello-minikube
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hello-minikube NodePort 10.102.25.156 <none> 8080:32470/TCP 8s
- 设置转发端口让本地可以访问
C:\Users\Caisi>kubectl port-forward service/hello-minikube 7080:8080
Forwarding from 127.0.0.1:7080 -> 8080
Forwarding from [::1]:7080 -> 8080
Handling connection for 7080
Handling connection for 7080
使用浏览器访问http://localhost:7080/可以看到服务的请求信息
管理集群
- 暂停(不影响已部署的应用程序)
minikube pause
- 停止
minikube stop
- 查看内置的已安装的服务目录
C:\Users\Caisi>minikube addons list
|-----------------------------|----------|--------------|
| ADDON NAME | PROFILE | STATUS |
|-----------------------------|----------|--------------|
| ambassador | minikube | disabled |
| csi-hostpath-driver | minikube | disabled |
| dashboard | minikube | enabled ✅ |
| 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 |
| volumesnapshots | minikube | disabled |
|-----------------------------|----------|--------------|
- 删除所有集群
minikube delete --all
总结
- 学会了一些markdown的编辑技巧
- 最近弄的好多都需要国外的网站,如这次的k8s.gcr.io,还有昨天在GitHub上面找的几个super-resolution都是国外的项目,有现成的模型,但是下载很麻烦,2M多下了半天,还一直下载失败。所以,在学习新的技术前,要了解一下需不需要国外的资源,以及国内有没有相应的资源可供选择。
- 这次只是简单的环境搭建,开了个头,接下来的才是开始。
- 简单的安装了docker、minikube,以及运行了示例应用。
更多推荐
已为社区贡献2条内容
所有评论(0)