0

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.

E_net4
  • 27,810
  • 13
  • 101
  • 139
vidyadhar reddy
  • 83
  • 3
  • 15

2 Answers2

2

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.

kool
  • 3,214
  • 1
  • 10
  • 26
0

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.

Marc ABOUCHACRA
  • 3,155
  • 12
  • 19
  • I was specifying the nodePort attribute because I require my targetPort and NodePort to be same. Anyhow thanks for a reasonable answer. Do you have any idea about the 'service mesh' Istio, can it be achieved by using it? – vidyadhar reddy Dec 16 '19 at 15:23
  • Yes i know (a little) Istio. However, I know the principle of service mesh and i don't see how it will solve your problem. They are essentially here to facilitate observability, reliability and security. They do not auto-populate your service (or at least i'm not aware of that feature). Also, if you just don't want to write all the yaml file (which is understandable) you can still code it. Just write a bash/python/java/[insert your favorite language] script that will edit your file. That's what i would do. – Marc ABOUCHACRA Dec 16 '19 at 15:33