1

Let say there's a deployment named my-deployment which is consisted of 3 pods, now we use port-forward forward a local port to this deployment :

kubectl port-forward deployment/my-deployment 8888 9999

My question is : when I visit localhost:8888 serveral times then which pod would be forwarded to ? Always forward to a fixed pod(like first pod) ? Or forward it by random ? Or use round-roubin strategy ?

Jeffrey D.
  • 414
  • 1
  • 7
chenxinlong
  • 1,677
  • 2
  • 15
  • 30
  • 1
    Yes a fixed pod selected at the time the forwarding is established. See https://stackoverflow.com/q/51468491/1032785 – jordanm Jul 18 '22 at 17:46

1 Answers1

2

when I visit localhost:8888 serveral times then which pod would be forwarded to ?

Will forward to the first pod sorted by name.

Always forward to a fixed pod(like first pod) ?

Fixed.

Or forward it by random ? Or use round-roubin strategy ?

Fixed to the first pod sorted by name.

Presumed you have performed a port-forward command and curl successfully. Now if you scale the deployment to 0; then scale up; if you curl again now you will get an error. This is because the pod that the port forwarded to has been terminated during the scale to 0.

gohm'c
  • 13,492
  • 1
  • 9
  • 16
  • Thx a lot, is there any references that I can dive deep into it ? I've tried search this question but get nothing. – chenxinlong Jul 19 '22 at 04:42
  • 1
    You can start digging [here](https://github.com/kubernetes/kubectl/blob/master/pkg/cmd/portforward/portforward.go) and all the way to the server side, if you like. – gohm'c Jul 19 '22 at 04:55
  • That's very helpful, I'll check this out. – chenxinlong Jul 19 '22 at 04:59