tilt icon indicating copy to clipboard operation
tilt copied to clipboard

Port-forward to service instead to Pods

Open Valgard opened this issue 2 years ago • 1 comments

Describe the Feature You Want

In my tilt environment I installed the RabbitMQ operator helm chart with a cluster of 3 nodes. If I define a port-forward to the port of the management console, then the pod of one of the three nodes is randomly selected (usually the last node). With RabbitMQ, the nodes are not started in parallel, so you always have to wait until the corresponding node has started up. There should be a parameter to the port_forward() function that specifies whether to create the port forward for pods or services.

Current Behavior

Tilt choose a random pod to port-forward to it and i do not have a possibility to port-forward to a service.

Why Do You Want This?

If you can define that the port forward goes to a service instead of a pod, then you no longer have to rely on the starting order of pods, since the service is responsible for forwarding to the correct pod.

In addition, this behavior would also correspond more to the Kubernetes environment, in which services are used to connect containers within the cluster.

Currently I manage to use a local resource to create the port forward to the service (as described in #3536), but this creates a separate resource which clutters the list of resources.

Additional context I have the same problem with other operators such the MariaDB operator.

Valgard avatar Sep 03 '23 17:09 Valgard

I believe this is working as expected.

kubectl port-forward service/my-service ... picks one pod to forward traffic to. it doesn't attempt to do any load balancing across multiple endpoints. You can read more on the reasoning behind this behavior here https://github.com/kubernetes/kubernetes/issues/15180, particularly this comment https://github.com/kubernetes/kubernetes/issues/15180#issuecomment-410798267. Tilt's port-forward deliberately tries to maintain parity with kubectl port-forward.

That said, we have had some discussion about a "dev-friendly load balancer". You could probably implement it as a tilt extension that wrapped kubectl proxy or some sort of traefik-based api gateway. Here's an example of how to implement something like this on top of local_resource: https://docs.tilt.dev/local_resource#serve_cmd

we'd probably want this as a separate extension / primitive rather than changing the behavior of port-forward

nicks avatar Sep 05 '23 14:09 nicks