docs-v1/design_proposals/port-forward.md
Align Skaffold port-forwarding behaviour with user expectations.
Skaffold supports establishing port-forwarding to deployed Kubernetes resources through several mechanisms:
skaffold.yaml
to connect a local port to a remote port on a pod, a service, or some workload resource that
has a pod-spec (e.g., Deployment, ReplicaSet, Job).skaffold debug), Skaffold automatically configures port-forwards to pods too.Port-forwards are only established when a user runs Skaffold with --port-forward. This was a conscious
choice in #969 as Skaffold had been
forwarding all containerPorts defined on pods, and doing so led to conflicts
in ports chosen. Users with many services encountered confusion when dealing with many services
(#1564).
But putting all port-forwards behind the --port-forward flag has resulted in new user confusion
(e.g., #4163,
#4818):
discr33t 12:32 PM: I’m having a problem getting Skaffold to port-forward to my service after doing a Helm deploy. If I use the --port-forward flag it will port-forward all my services. But if I define portForward: anywhere in my
skaffold.yamlnothing is working.
Forwarding all containerPorts on pods in skaffold debug has also resulted in odd situations
such as container-ports being allocated before service ports. For example, the Skaffold
examples/react-reload example
has a service on port 8080
and a deployment/pod on port 8080.
This document proposes to change Skaffold port-forwarding's defaults in a similar fashion as proposed by @corneliusweig in https://github.com/GoogleContainerTools/skaffold/issues/1564#issuecomment-473528574. These changes are intended to be backwards-compatible with the previous version of Skaffold except where noted.
NOTE: Ideally we would re-purpose Skaffold's existing
--port-forwardCLI argument in a backward-compatible manner (still under investigation). This document assumes it is not possible.
Skaffold's --port-forward argument should be changed from a binary true/false option to
a set of comma-separated values with the following defined modes:
user: user-defined port-forwards as defined in the skaffold.yamlservices: service ports are forwardedpods: containerPorts defined on Pods and Kubernetes workload objects that have pod-specs
are forwarded (Deployment, ReplicaSet, StatefulSet, DaemonSet, Job, CronJob)debug: an internal strategy to forward debugging-related ports on Pods as set up
from skaffold debugoff: no ports are ever forwardedSkaffold will default to enabling port-forwarding for establishing user-defined port-forwards
as defined in the skaffold.yaml. Skaffold's dev and debug will be changed to the following defaults.
| Command-line | v1.15.0 default modes | New default modes |
|---|---|---|
skaffold dev | off | user |
skaffold dev --port-forward | user, services | user, services (no change) |
skaffold dev --port-forward=false | off | off (no change) |
skaffold debug | off | user, debug |
skaffold debug --port-forward | user, services, pods | user, services, debug |
skaffold debug --port-forward=false | off | off (no change) |
Compatibility Change: The behaviour of skaffold debug --port-forward no longer forwards all
containerPorts defined on pods. Container ports were forwarded as there was no other option to forward
just debug ports. With this proposed change, the debug mode will only select debug ports. Forwarding all
containerPorts was the cause of some confusion in earlier iterations of port-forwarding.
Please list any open questions here in the following format:
<Question>
Resolution: Please list the resolution if resolved during the design process or specify Not Yet Resolved
WatchingPodForwarder to take a pod/port-filter to allow determining if a port is
a debug port, as determined by the debug.cloud.google.com annotation.--port-forward into string slice argument, if possible!Please describe what new test cases you are going to consider.
skaffold dev should forward user-defined ports (no services, not container ports).skaffold dev --port-forward should forward services (no container ports).skaffold dev --port-forward=off should forward nothing.skaffold dev --port-forward=X for X={user,debug,pods,services}` should only forward those items.skaffold debug should forward user-defined ports and debug ports (no services, no other container ports).skaffold debug --port-forward should forward user-defined ports, debug ports, and services (no container ports).skaffold debug --port-forward=off should forward nothing.skaffold debug --port-forward=X for X={user,debug,pods,services}` should only forward those items.