kind 集群无法在 Windows 10 上绑定端口 80

kind cluster cannot bind port 80 on Windows 10

我正在使用本地 Kubernetes 集群。我尝试使用 Ingress 并按照官方文档中的下一条说明进行操作: https://kind.sigs.k8s.io/docs/user/ingress/#create-cluster

我的集群配置:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  kubeadmConfigPatches:
  - |
    kind: InitConfiguration
    nodeRegistration:
      kubeletExtraArgs:
        node-labels: "ingress-ready=true"
  extraPortMappings:
  - containerPort: 80
    hostPort: 80

但看起来我无法在 Windows 上使用端口 80:

kind create cluster --config=.\kubernetes\kind-cluster.yaml
Creating cluster "kind" ...
 • Ensuring node image (kindest/node:v1.21.1)   ...
 ✓ Ensuring node image (kindest/node:v1.21.1) 
 • Preparing nodes    ...
 ✗ Preparing nodes 
ERROR: failed to create cluster: docker run error: command "docker run --hostname kind-control-plane --name kind-control-plane --label io.x-k8s.kind.role=control-plane --privileged --security-opt seccomp=unconfined --security-opt apparmor=unconfined --tmpfs /tmp --tmpfs /run --volume /var --volume /lib/modules:/lib/modules:ro --detach --tty --label io.x-k8s.kind.cluster=kind --net kind --restart=on-failure:1 --init=false --publish=0.0.0.0:80:80/TCP --publish=127.0.0.1:55805:6443/TCP -e KUBECONFIG=/etc/kubernetes/admin.conf kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6" failed with error: exit status 125

Command Output: db8cabb573332b7f0466a0461c4b2e687350400f71bb2b04b98b337900180310
docker: Error response from daemon: Ports are not available: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

所以主要问题是:我可以将该端口更改为另一个端口 (30080) 吗?之后如何访问服务?


编辑 1: 尝试使用 30080 端口并应用文档中的命令 link:集群启动,Ingress(使用 nginx)启动,但我无法访问服务:

curl localhost/foo
curl : Not Found
HTTP Error 404. The requested resource is not found.

curl http://localhost:30080/foo
curl: Underlying connection closed: The connection was closed unexpectedly.

我想原因是 Ingress 默认使用端口 80:

 kubectl get ingress
NAME              CLASS    HOSTS   ADDRESS     PORTS   AGE
example-ingress   <none>   *       localhost   80      5m46s

在网上的某个地方,我找到了解决办法(遗憾的是,我没有保存原文link)。我的案例的解决方案的最小实现如下:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
  - containerPort: 80
    hostPort: 8080
    protocol: TCP
    listenAddress: 127.0.0.1
  - containerPort: 443
    hostPort: 9000
    protocol: TCP
    listenAddress: 127.0.0.1

这让我可以使用以下方式获得我的服务: localhost:8080127.0.0.1:8080。 假设 443 端口用于 https,但我目前没有使用它,所以无法检查它的可用性。