reactive-tech / kubegres

Kubegres is a Kubernetes operator allowing to deploy one or many clusters of PostgreSql instances and manage databases replication, failover and backup.
https://www.kubegres.io
Apache License 2.0
1.32k stars 74 forks source link

Service Type in CR #46

Open Seljuke opened 3 years ago

Seljuke commented 3 years ago

Hi,

It would be great to have a way to change primary and replica service types from default ClusterIP to LoadBalancer and NodePort. Right now I'm using nginx ingress TCP loadbalancing but it adds complexity and dependency to ingress pod.

Something like below would be great;

apiVersion: kubegres.reactive-tech.io/v1
kind: Kubegres
metadata:
  name: mypostgres
  namespace: default

spec:

   replicas: 3
   image: postgres:13.2

  service:
    primary:
      type: LoadBalancer
    replica:
      type: NodePort
      nodePort: 30543

   database:
      size: 200Mi

   env:
      - name: POSTGRES_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mypostgres-secret
              key: superUserPassword

      - name: POSTGRES_REPLICATION_PASSWORD
        valueFrom:
           secretKeyRef:
              name: mypostgres-secret

If method at #44 wouldn't require UID of original service I could create a helm chart that can create external facing service with pre-install hook.

alex-arica commented 3 years ago

Thank you for your suggestion.

Is this feature for a production usage of for a local usage?

Exposing Postgres database via NodePort can expose security risks in production.

Seljuke commented 3 years ago

I'm using kubegres in production and staging environments mainly for creating HA environments to third party tools like keycloak. Our infrastructure running behind firewalls and clusters are on-premise servers so just exposing ports wouldn't produce risks for us.

alex-arica commented 3 years ago

Thank you for those details.

I added this feature in the backlog and I will use the current issue number when committing my changes.

In term of availability, I will try to get it done this week. If it cannot be done this week, it would be end of October as I am working on this project during the last week of each month and for 1 week consecutively.

phamnhuvu-dev commented 2 years ago

I am not sure this way is right but it has worked for me and doesn't require any uid

apiVersion: v1
kind: Service
metadata:
  name: postgres-write
  namespace: default
  labels:
    app: postgres-write
spec:
  type: NodePort
  ports:
  - name: postgres-write
    port: 5432
    nodePort: 30001
  selector:
    app: postgres
    replicationRole: primary
---
apiVersion: v1
kind: Service
metadata:
  name: postgres-read
  namespace: default
  labels:
    app: postgres-read
spec:
  type: NodePort
  ports:
  - name: postgres-read
    port: 5432
    nodePort: 30002
  selector:
    app: postgres
    replicationRole: replica
ssethuma1155 commented 1 year ago

Is LoadBalancer and Nodeport are available in the current release of Kubegres?