vidyadhar reddy
vidyadhar reddy

Reputation: 103

kubernetes nodePort service on a range

I wanted to expose my application on all the ports between 3000-14000. For this, I have changed the default nodePort range 30k - 32767 by updating kubeapi-server manifest file field "--service-node-port-range=3000-14000". For me, it is almost impossible to expose by specifying all the port numbers manually following the below template.

apiVersion: v1
kind: Service
metadata: 
   name: myapp-service
spec:
  type: nodePort
  selector:
   app: myapp
  ports:
  - targetPort: 3000
    port: 3000
    nodePort: 3000
  ...................
  ...................
 - targetPort: 14000
    port: 14000
    nodePort: 14000

Do we have any other alternative solution/plugins to this, so as to open all ports between the range 3k - 14k.

Upvotes: 1

Views: 1551

Answers (2)

kool
kool

Reputation: 3613

Unfortunately Kubernetes doesn't yet support exposing range of ports (it's possible in Docker).

As a workaround use Helm templates to create chart with service template and ports in values.yaml file. Or create a script to automate creation of a service yaml to expose each port.

Upvotes: 3

Marc ABOUCHACRA
Marc ABOUCHACRA

Reputation: 3463

Well based on the comments this is just the same as having 11k app (sic!).
So you have to do it the "normal" way I suppose... meaning you have to map all your 11k port manually.

However, in order to make it less painfull, you can omit the nodePort attribute. Kubernetes will automatically assign one that is not used.

Upvotes: 1

Related Questions