0

我正在使用本地 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 端口并应用来自文档链接的命令:集群启动,入口(使用 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
4

1 回答 1

0

在互联网的某个地方,我找到了一个解决方案(不幸的是,我没有保存原始链接)。我的案例的解决方案的最小实现如下:

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:8080或访问我的服务127.0.0.1:8080。假设443端口用于 https,但我目前没有使用它,所以无法检查它的可操作性。

于 2021-12-28T14:07:49.820 回答