我已经阅读了十几篇关于如何在 Windows 上使用 Minikube(或相反,取决于你如何看待它)设置 Docker CLI 的文章。
这个想法是在观看这个 YouTube 视频时产生的:DevOps Toolkit - 适用于 Mac 和 Windows 的免费 Docker 桌面替代品
到目前为止我做了什么,首先我已经设置了必要的包:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
choco install docker-cli minikube k9s -y
...
然后启动 Minikube:
$ minikube start
? minikube v1.25.1 on Microsoft Windows 11 Pro 10.0.22000 Build 22000
✨ Automatically selected the hyperv driver
? Starting control plane node minikube in cluster minikube
? Creating hyperv VM (CPUs=2, Memory=6000MB, Disk=20000MB) ...
? Preparing Kubernetes v1.23.1 on Docker 20.10.12 ...
▪ kubelet.housekeeping-interval=5m
▪ Generating certificates and keys ...
▪ Booting up control plane ...
▪ Configuring RBAC rules ...
? Verifying Kubernetes components...
▪ Using image gcr.io/k8s-minikube/storage-provisioner:v5
? Enabled addons: storage-provisioner, default-storageclass
? Done! kubectl is now configured to use "minikube" cluster and "default" namespace by default
并显示环境变量以使用 minikube 的 Docker 守护进程,即管道 docker 到 minikube
$ minikube docker-env
$Env:DOCKER_TLS_VERIFY = "1"
$Env:DOCKER_HOST = "tcp://172.22.43.208:2376"
$Env:DOCKER_CERT_PATH = "C:\Users\natalie-perret\.minikube\certs"
$Env:MINIKUBE_ACTIVE_DOCKERD = "minikube"
# To point your shell to minikube's docker-daemon, run:
# & minikube -p minikube docker-env --shell powershell | Invoke-Expression
我已立即执行:
$ & minikube -p minikube docker-env --shell powershell | Invoke-Expression
我可以使用 Docker CLI 看到 kube 容器:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5fffd86809db 6e38f40d628d "/storage-provisioner" 41 minutes ago Up 41 minutes k8s_storage-provisioner_storage-provisioner_kube-system_ad473bd3-57aa-448d-87d4-26f7786d5321_1
e939d8c637de a4ca41631cc7 "/coredns -conf /etc…" 42 minutes ago Up 42 minutes k8s_coredns_coredns-64897985d-z9k9m_kube-system_64e26de3-b379-49db-800e-6041f6f5b384_0
1866d17e5126 k8s.gcr.io/pause:3.6 "/pause" 42 minutes ago Up 42 minutes k8s_POD_coredns-64897985d-z9k9m_kube-system_64e26de3-b379-49db-800e-6041f6f5b384_0
1e7f8815c7d9 b46c42588d51 "/usr/local/bin/kube…" 42 minutes ago Up 42 minutes k8s_kube-proxy_kube-proxy-qbjd8_kube-system_6a1016cc-7272-404e-8528-582615333943_0
81ea804ae46e k8s.gcr.io/pause:3.6 "/pause" 42 minutes ago Up 42 minutes k8s_POD_kube-proxy-qbjd8_kube-system_6a1016cc-7272-404e-8528-582615333943_0
160dd07d4e57 k8s.gcr.io/pause:3.6 "/pause" 42 minutes ago Up 42 minutes k8s_POD_storage-provisioner_kube-system_ad473bd3-57aa-448d-87d4-26f7786d5321_0
37d7f248a31c 71d575efe628 "kube-scheduler --au…" 42 minutes ago Up 42 minutes k8s_kube-scheduler_kube-scheduler-minikube_kube-system_b8bdc344ff0000e961009344b94de59c_0
06b7d0007a1b 25f8c7f3da61 "etcd --advertise-cl…" 42 minutes ago Up 42 minutes k8s_etcd_etcd-minikube_kube-system_a9ff16e4ba59eb7890b7fb3e6b59a60b_0
9aca0a09e443 b6d7abedde39 "kube-apiserver --ad…" 42 minutes ago Up 42 minutes k8s_kube-apiserver_kube-apiserver-minikube_kube-system_86c1ec74f5feb61f5b7f86812aea2e10_0
0898146be8d2 f51846a4fd28 "kube-controller-man…" 42 minutes ago Up 42 minutes k8s_kube-controller-manager_kube-controller-manager-minikube_kube-system_d3f0dbc1c3a23fddbc9f30b9e08c775e_0
c9daa18706bd k8s.gcr.io/pause:3.6 "/pause" 42 minutes ago Up 42 minutes k8s_POD_kube-scheduler-minikube_kube-system_b8bdc344ff0000e961009344b94de59c_0
fe9808d7fc2e k8s.gcr.io/pause:3.6 "/pause" 42 minutes ago Up 42 minutes k8s_POD_kube-controller-manager-minikube_kube-system_d3f0dbc1c3a23fddbc9f30b9e08c775e_0
852aa124d436 k8s.gcr.io/pause:3.6 "/pause" 42 minutes ago Up 42 minutes k8s_POD_kube-apiserver-minikube_kube-system_86c1ec74f5feb61f5b7f86812aea2e10_0
bd884e37ea62 k8s.gcr.io/pause:3.6 "/pause" 42 minutes ago Up 42 minutes k8s_POD_etcd-minikube_kube-system_a9ff16e4ba59eb7890b7fb3e6b59a60b_0
到目前为止一切都很好,但是是吗?好吧,有两件事我仍然非常挣扎(并且在标题中都非常明确地指出):
我仍然有端口映射问题,我无法真正弄清楚如何做到这一点,根据我的肤浅理解,minikube 有它的“自己的 IP 地址”。我的意思是显示 Minikube 帮助,其中包括:
Troubleshooting Commands: ssh-key Retrieve the ssh identity key path of the specified node ssh-host Retrieve the ssh host key of the specified node ip Retrieves the IP address of the specified node logs Returns logs to debug a local Kubernetes cluster update-check Print current and latest version number version Print the version of minikube options Show a list of global command-line options (applies to all commands).
$ minikube ip 172.22.42.203
但是,我希望 minikube ip 指向本地主机,不确定这是否可行。
一个简单的 nginx 用例:
$ docker run -it --rm -d -p 8080:80 --name web nginx Unable to find image 'nginx:latest' locally latest: Pulling from library/nginx 5eb5b503b376: Pull complete 1ae07ab881bd: Pull complete 78091884b7be: Pull complete 091c283c6a66: Pull complete 55de5851019b: Pull complete b559bad762be: Pull complete Digest: sha256:2834dc507516af02784808c5f48b7cbe38b8ed5d0f4837f16e78d00deb7e7767 Status: Downloaded newer image for nginx:latest 9f00b9c8ab74436bdf1525c6255cab2aab86fe47163d2ed304c8e65dd98b0b4a
这不可避免地导致这不起作用
$ [System.Net.WebRequest]::Create('http://127.0.0.1:8080').GetResponse() | % {$_.StatusCode} MethodInvocationException: Exception calling "GetResponse" with "0" argument(s): "No connection could be made because the target machine actively refused it. [::ffff:127.0.0.1]:8080(127.0.0.1:8080)"
虽然该命令显然可以:
[System.Net.WebRequest]::Create('http://172.22.42.203:8080').GetResponse() | % {$_.StatusCode} OK
如何
& minikube -p minikube docker-env --shell powershell | Invoke-Expression
在启动时和每个命令行提示符下应用?如果我不在每个 PowerShell 提示符中应用该命令,我最终会得到:error during connect: In the default daemon configuration on Windows, the docker client must be run with elevated privileges to connect.: Get "http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.24/containers/json": open //./pipe/docker_engine: The system cannot find the file specified.