nutanix-cloud-native / ndb-operator

Nutanix NDB Kubernetes Operator
Apache License 2.0
12 stars 24 forks source link

The Kubernetes service automatically generated to point to the deployed DB instance does not allow specifying the port #201

Open fabricekrebs opened 4 months ago

fabricekrebs commented 4 months ago

When an NDB operator deploys a database solution, a Kubernetes service is automatically deployed, configuring the deployed database as the endpoint.

However, it is not currently possible to specify the port on which the service will listen, and port 80 is set by default.

It should be feasible, when setting up the resources of type 'Database', to specify the port on which the Kubernetes service would listen. The Custom Resource Definition (CRD) should provide the option to define something similar:

The actual result is

apiVersion: v1
kind: Service
metadata:
  name: demoappdb02-svc
spec:
  clusterIP: 172.19.94.227
  clusterIPs:
  - 172.19.94.227
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - port: 80
    protocol: TCP
    targetPort: 5432

We should be able to create resources like this

apiVersion: ndb.nutanix.com/v1alpha1
kind: Database
metadata:
  # This name that will be used within the kubernetes cluster
  name: demoappdb02
spec:
  # Name of the NDBServer resource created earlier
  ndbRef: gdb
  isClone: false
  servicePort : 5432
  exposedPort : 5432

Then we should get similar result:

apiVersion: v1
kind: Service
metadata:
  name: demoappdb02-svc
spec:
  clusterIP: 172.19.94.227
  clusterIPs:
  - 172.19.94.227
  internalTrafficPolicy: Cluster
  ipFamilies:
  - IPv4
  ipFamilyPolicy: SingleStack
  ports:
  - port: 5432
    protocol: TCP
    targetPort: 5432
manavrajvanshi commented 4 months ago

Hey @fabricekrebs! As I understand, you're looking for the functionality to be able to specify the port for the K8s service that the clients would consume (exposed port). We will be tracking this issue internally.

I wanted to know what would be the use of specifying the service port explicitly? Wouldn't it be easier for the user to just specify the port that they want to connect to on the K8s service (exposed port), and the NDB Operator determines the service port based on the interactions with NDB ? Can you please let us know if there's any use case of specifying the service port that we might have missed?

fabricekrebs commented 4 months ago

Hello @manavrajvanshi,

Allowing customers to specify the exposed port provides greater flexibility in designing their Kubernetes application architecture. It is not logical for an application owner to access PostgreSQL on a port like 80, which is commonly associated with HTTP.

By default, the same port defined at the endpoint should be used. For instance, PostgreSQL should use 5432:5432 instead of 80:5432.