Eu li uma dúzia de artigos sobre como configurar o Docker CLI com o Minikube (ou vice-versa, dependendo de como você o vê) no Windows.
A ideia surgiu enquanto assistia a este vídeo do YouTube: DevOps Toolkit - Free Docker Desktop Alternative For Mac And Windows
O que eu fiz até agora, bem, primeiro configurei os pacotes necessários:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-All
choco install docker-cli minikube k9s -y
...
Então começou o 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
e exibiu as variáveis env para usar o daemon Docker do minikube, ou seja, canalizar o docker para o 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
que eu executei prontamente:
$ & minikube -p minikube docker-env --shell powershell | Invoke-Expression
e pude ver os contêineres kube com a CLI do Docker:
$ 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
Até aí tudo bem, mas será? Bem, há duas coisas com as quais ainda estou muito lutando (e que são indicadas bastante explicitamente no título):
Ainda tenho problema de mapeamento de portas e não consegui descobrir como fazer isso, com base no meu entendimento superficial, o minikube tem seu "próprio endereço IP". Quero dizer, exibir a ajuda do Minikube, mostra entre outras coisas:
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
No entanto, eu gostaria que o ip do minikube apontasse para o host local, não tenho certeza se isso é factível.
Um caso de uso simples com 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
o que inevitavelmente leva a que isso não funcione
$ [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)"
enquanto esse comando obviamente faz:
[System.Net.WebRequest]::Create('http://172.22.42.203:8080').GetResponse() | % {$_.StatusCode} OK
Como
& minikube -p minikube docker-env --shell powershell | Invoke-Expression
aplicar na inicialização e para todos os prompts de linha de comando? Se eu não aplicar o comando em todos os prompts do PowerShell, terei: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.