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

[FEATURE] Expose ports AFTER k3d creation #89

Closed
deminngi opened this issue Jul 7, 2019 · 8 comments · Fixed by #615, #656 or #670
Closed

[FEATURE] Expose ports AFTER k3d creation #89

deminngi opened this issue Jul 7, 2019 · 8 comments · Fixed by #615, #656 or #670
Assignees
Labels
DONE Issue solved, but not closed yet, due to pending release enhancement New feature or request help wanted Extra attention is needed
Milestone

Comments

@deminngi
Copy link

deminngi commented Jul 7, 2019

I had a problem how to expose the tiller ingress port AFTER k3d creation, to be able to use a local helm client and set the HELM_HOST variable to HELM_HOST=localhost:44134

Here my solution:
Forward the internal ingress port over a docker container using socat

Here my procedure:

  • Get the IP address of the k3d-default-server
$ kubectl get nodes
  • Get the k3d network
$ sudo docker network ls
  • Run a detached docker socat container
 $ docker run \
    -d \
    -p <local-port>:<local-port> \
    --name=<k3d-host>-<k3d-port>-link \
    --network <k3d-namespace> \
    alpine/socat \
      TCP4-LISTEN:<local-port>,fork,reuseaddr \
      TCP4:<k3d-host>:<k3d-port>

Example:

 $ docker run \
    -d \
    -p 44134:44134 \
    --name=k3d-default-server-44134-link \
    --network k3d-default \
    alpine/socat \
      TCP4-LISTEN:44134,fork,reuseaddr \
      TCP4:172.19.0.2:44134

Question:

  1. Is there a way to implement this as a command in k3d?
$ k3d expose -l <local-port> -h <k3d-host> -r <k3d-port> -n <k3d-namespace>|default=k3d-default>
  1. May be adding this to FAQ?
@deminngi deminngi added the enhancement New feature or request label Jul 7, 2019
@iwilltry42 iwilltry42 added this to To do in Networking via automation Aug 21, 2019
@iwilltry42 iwilltry42 added the help wanted Extra attention is needed label Jan 5, 2020
@iwilltry42 iwilltry42 changed the title [FEATURE]: How to export services AFTER k3d creation [FEATURE] Expose ports AFTER k3d creation Jan 5, 2020
@iwilltry42 iwilltry42 added this to the v2.0 milestone Jan 5, 2020
@iwilltry42 iwilltry42 removed this from the v2.0 milestone Apr 21, 2020
@mmacfadden
Copy link

mmacfadden commented Jul 30, 2020

This seems like a highly desirable feature. We don't always know exactly what is going to be deployed in k3s when creating the cluster.

@jaceksan
Copy link

+1

@iwilltry42
Copy link
Member

Hi there, apparently I didn't ever comment on this, but I remember that we already had discussions about this @giminni .
First of all: Thanks for opening this issue and providing a workaround!

This is a limitation introduced by how Docker works and nothing that we can't easily fix unfortunately.
What we could do however is: re-creating the containers (keeping the state in the volume) and adding the additional port mappings. This could surely work, but would introduce downtimes 🤔

@jaceksan
Copy link

jaceksan commented Oct 5, 2020

Personally I am now focused on stateful apps, esp. database clusters, which are managed by operators. Recreating PODs would be feasible, one by one, handled by the operator.

@LordChunk
Copy link

I understand this might not work for everyone, but if you're running a single node on your machine setting the network to the host's network, you also won't have to deal with opening up all required ports.
https://k3d.io/internals/networking/#host-network

@iwilltry42
Copy link
Member

The use cases mentioned here can be handled by the new node edit and cluster edit features in k3d v5.0.0 (landing next month) ✔️

Edit Running Resources automation moved this from To do to Done Sep 17, 2021
@keyiis
Copy link

keyiis commented Nov 18, 2021

@iwilltry42 how to expose k3d-k3s-default-server port to host,not loadbalancer

root@9b2af6447dbc:~# k3d node edit k3d-k3s-default-server-0 --port-add 1883:1883
FATA[0000] Currently only the loadbalancer can be updated!

@iwilltry42
Copy link
Member

@keyiis , this is not supported, as we have to restart (or rather re-create) the container to add ports (docker won't let you add ports to running containers). This only works properly for the loadbalancer, as it doesn't hold any state.
The K3s containers (k3d nodes) however, hold quite a lot of state, so re-creating them would break the cluster.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment