kubernetes 无法使用mac m1上的docker desktop从浏览器访问安装在kind群集上的metallb分配的负载平衡器外部ip地址

jjhzyzn0  于 2023-03-01  发布在  Kubernetes
关注(0)|答案(1)|浏览(210)

我有Mac M1运行Docker桌面(V20. 10. 17)。Kubernetes没有启用,只是Docker引擎在运行。
我安装了Kind Cluster:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
# Can add additional control planes
#- role: control-plane
#- role: control-plane
- role: control-plane
- role: worker
- role: worker
- role: worker

然后,我使用https://kind.sigs.k8s.io/docs/user/loadbalancer/中的步骤安装了Metalllb
然后我部署了nginx:kubectl create deploy nginx --image nginx
如果我端口转发,我可以从浏览器到达nginx。
然后,我将我的部署公开为LoadBalancer类型的服务:kubectl expose deploy nginx --port 8080 --type LoadBalancer
不幸的是,如果我尝试通过显示的外部IP地址访问服务,我无法访问nginx。
请告知。

scyqe7ek

scyqe7ek1#

LoadBalancers通过利用云提供商(如GCP或AWS)上的负载平衡器来工作,因此本地运行的Kind群集可能会使用NodePort服务而不是部署/StatefulSet中的Loadbalancers来公开nginx,但要仔细检查选项。
目前我正在为Postgres部署Kind,当我遇到类似的连接和端口转发问题时,解决方案是在Kind配置文件中添加一个侦听地址-在这两种情况下,问题都是使服务可以在集群之外访问。我相信您也可以像下面这样公开一个externalIP,但要测试一下。

kind-config.yaml(一些值来自Postgres)

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  # port forward 5432 on the host to 5432 on this node
  extraPortMappings:
  - containerPort: 5432
    hostPort: 5432
    # optional: set the bind address on the host
    # 0.0.0.0 is the current default
    listenAddress: "127.0.0.1"
    # optional: set the protocol to one of TCP, UDP, SCTP.
    # TCP is the default
    protocol: TCP
networking:
  ipFamily: ipv4
  apiServerAddress: 192.168.1.175
  apiServerPort: 10000

相关问题