如何使用micropk8s使能端口转发



我正在摆弄microk8s,我只想在同一台机器上运行apache服务器并导航到其默认页面。我在mac手臂上m1:

microk8s kubectl run test-pod --image=ubuntu/apache2:2.4-20.04_beta --port=80
~ $ microk8s kubectl get pods                                                                                             2
NAME                                   READY   STATUS             RESTARTS       AGE
test-pod                               1/1     Running            0              8m43s

然后我试着启用转发:

◼ ~ $ microk8s kubectl port-forward test-pod :80
Forwarding from 127.0.0.1:37551 -> 80

但:

◼ ~ $ wget http://localhost:37551
--2022-12-24 18:54:37--  http://localhost:37551/
Resolving localhost (localhost)... 127.0.0.1, ::1
Connecting to localhost (localhost)|127.0.0.1|:8080... failed: Connection refused.
Connecting to localhost (localhost)|::1|:8080... failed: Connection refused.

日志看起来很好:

◼ ~ $ microk8s kubectl  logs test-pod                                                                           130
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 10.1.254.96. Set the 'ServerName' directive globally to suppress this message

仪表板代理确实工作得很好,我可以导航到它:

◼ ~ $ microk8s dashboard-proxy
Checking if Dashboard is running.
Dashboard will be available at https://192.168.64.2:10443

回答自己:

  1. 我应该使用Multipass的客户机分配的IP。这不是docker
  2. 由于某种原因,我还没有弄清楚,正如这里所问的,从客人的转发在mac上不能正常工作。我应该打开一个客人的shell并从那里转发。这样,它就会起作用。请参阅链接帖子上的答案。

希望这将为未来的mac用户节省一些时间。

最新更新