0

How can I find all nodeports are free in a kubernetes cluster that can be used by any service?

Currently I'm using netstat -pant | grep <12345>

Is there any better command?

Tom Carrick
  • 6,349
  • 13
  • 54
  • 78
  • why do you need this info? – Arghya Sadhu May 27 '20 at 11:28
  • 1
    By default, Kubernetes set NodePort range as 30000 - 32767. refer https://stackoverflow.com/questions/37648553/is-there-anyway-to-get-the-external-ports-of-the-kubernetes-cluster this will fulfil your requirement. `kubectl get svc --all-namespaces -o go-template='{{range .items}}{{range.spec.ports}}{{if .nodePort}}{{.nodePort}}{{"\n"}}{{end}}{{end}}{{end}}'` – hariK May 27 '20 at 11:31
  • If I absolutely needed a NodePort service, I'd let Kubernetes pick the port for me. Usually a LoadBalancer service or an HTTP ingress setup will be much easier to work with. – David Maze May 27 '20 at 12:33

1 Answers1

0

That's the way how nodeport works. It is same as you can't run two web services on same port of 80 on same server.

You have to adjust the port in your real environment.

Otherwise, let kubernetes to manage

BMW
  • 42,880
  • 12
  • 99
  • 116