Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kind extraPortMappings issue #3681

Open
Ky4t opened this issue Jul 11, 2024 · 5 comments
Open

Kind extraPortMappings issue #3681

Ky4t opened this issue Jul 11, 2024 · 5 comments
Labels
kind/support Categorizes issue or PR as a support question.

Comments

@Ky4t
Copy link

Ky4t commented Jul 11, 2024

Creating cluster "k8s-proj" ...
βœ“ Ensuring node image (kindest/node:v1.30.0) πŸ–Ό
βœ— Preparing nodes πŸ“¦ πŸ“¦ πŸ“¦
Deleted nodes: ["k8s-proj-worker" "k8s-proj-worker2" "k8s-proj-control-plane"]
ERROR: failed to create cluster: command "docker run --name k8s-proj-worker2 --hostname k8s-proj-worker2 --label io.x-k8s.kind.role=worker --privileged --security-opt seccomp=unconfined --security-opt apparmor=unconfined --tmpfs /tmp --tmpfs /run --volume /var --volume /lib/modules:/lib/modules:ro -e KIND_EXPERIMENTAL_CONTAINERD_SNAPSHOTTER --detach --tty --label io.x-k8s.kind.cluster=k8s-proj --net kind --restart=on-failure:1 --init=false --cgroupns=private --publish=127.0.0.1:80:30000/TCP --publish=127.0.0.1:443:31000/TCP --publish=127.0.0.1:15021:32000/TCP kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e" failed with error: exit status 125
Command Output: 90e96a94f270f108b9861949cb539484b7b9be34c1fad906d991e9373be7df0a
docker: Error response from daemon: Ports are not available: exposing port TCP 127.0.0.1:80 -> 0.0.0.0:0: listen tcp 127.0.0.1:80: bind: An attempt was made

Here is the error occurred when I create a cluster with config file including extra port mappings.

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
  extraPortMappings:
   - containerPort: 30000
     hostPort: 80
     listenAddress: "127.0.0.1"
     protocol: TCP
   - containerPort: 31000
     hostPort: 443
     listenAddress: "127.0.0.1"
     protocol: TCP
   - containerPort: 32000
     hostPort: 15021
     listenAddress: "127.0.0.1"
     protocol: TCP
- role: worker
  extraPortMappings:
   - containerPort: 30000
     hostPort: 80
     listenAddress: "127.0.0.1"
     protocol: TCP
   - containerPort: 31000
     hostPort: 443
     listenAddress: "127.0.0.1"
     protocol: TCP
   - containerPort: 32000
     hostPort: 15021
     listenAddress: "127.0.0.1"
     protocol: TCP
@Ky4t Ky4t added the kind/support Categorizes issue or PR as a support question. label Jul 11, 2024
@stmcginnis
Copy link
Contributor

You have both workers trying to bind to the same ports on the host. That will not work.

What you probably want is to add the port mappings to the control-plane container, then use ingress to expose your applications running on the workers.

@Ky4t
Copy link
Author

Ky4t commented Jul 11, 2024

Can you give me some example for my config?

@stmcginnis
Copy link
Contributor

As far as just creating the cluster, this should work:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
   - containerPort: 30000
     hostPort: 80
   - containerPort: 31000
     hostPort: 443
   - containerPort: 32000
     hostPort: 15021
- role: worker
- role: worker

@Ky4t
Copy link
Author

Ky4t commented Jul 11, 2024

Creating cluster "k8s-proj" ...
βœ“ Ensuring node image (kindest/node:v1.30.0) πŸ–Ό
βœ— Preparing nodes πŸ“¦ πŸ“¦ πŸ“¦
Deleted nodes: ["k8s-proj-worker" "k8s-proj-control-plane" "k8s-proj-worker2"]
ERROR: failed to create cluster: command "docker run --name k8s-proj-control-plane --hostname k8s-proj-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 -e KIND_EXPERIMENTAL_CONTAINERD_SNAPSHOTTER --detach --tty --label io.x-k8s.kind.cluster=k8s-proj --net kind --restart=on-failure:1 --init=false --cgroupns=private --publish=0.0.0.0:80:30000/TCP --publish=0.0.0.0:443:31000/TCP --publish=0.0.0.0:15021:32000/TCP --publish=127.0.0.1:35207:6443/TCP -e KUBECONFIG=/etc/kubernetes/admin.conf kindest/node:v1.30.0@sha256:047357ac0cfea04663786a612ba1eaba9702bef25227a794b52890dd8bcd692e" failed with error: exit status 125
Command Output: a93a88ffe4c358fa9eaabfade0a92e7d9f6e679d97dbc785d4d3d50d91163a7f
docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:80 -> 0.0.0.0:0: listen tcp 0.0.0.0:80: bind: An attempt was made to access a socket in a way forbidden by its access permissions.

Still showing the error

@BenTheElder
Copy link
Member

something else on your host may already be using port 80?

setting listenAddress: "127.0.0.1" but otherwise the config above would be a good starting point.

also, if you don't have a specific use-case in mind, I'd highly recommend using a single node cluster and just doing:

kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
  extraPortMappings:
   - containerPort: 30000
     hostPort: 80
     listenAddress: "127.0.0.1"
   - containerPort: 31000
     hostPort: 443
     listenAddress: "127.0.0.1"
   - containerPort: 32000
     hostPort: 15021
     listenAddress: "127.0.0.1"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/support Categorizes issue or PR as a support question.
Projects
None yet
Development

No branches or pull requests

3 participants