I have a kubernetes cluster set up in a private cloud. Idea is all the developers would be using this cluster to launch all the microservices needed for the app. Each developer would launch all the deployments/services in his namespace to avoid collision. Since this cloud doesn't support LoadBalancer , I have used nodePort with a port defined to expose external IP for the front end. And I access the front end using
However Since K8s can launch any number of front-end pods of different namespaces on the same node -I will have a collision because that nodePort is already assigned to the service launched first. I now cant understand on how can I allow multiple people using same services to launch in the same cluster.
Sample Service Config is below
apiVersion: v1
kind: Service
metadata:
name: frontend
labels:
name: frontend
spec:
ports:
- port: 8884
targetPort: 8081
nodePort: 30080
name: ui
selector:
app: test
type: NodePort
This frontend service can be accessed by http://node-ip:30080 if run for the first time. What happens if we run the same yaml across different namespace in the same node? How do we resolve this?
You do not need to define nodePort at all, it is then automaticaly assigned to the Service by kubernetes and henceforth it avoids any collisions whatsoever.