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

version 1.9 creates cluster IP services with "None". The Documentation doesn't address this #41

Closed Hisdad closed 3 years ago

Hisdad commented 3 years ago

on the getting started page it says:

In this example, Kubegres created 2 Kubernetes clusterIP services using the name defined in YAML (e.g. "mypostgres"):

a Kubernetes service "mypostgres" allowing to access to the Primary PostgreSql instances
a Kubernetes service "mypostgres-replica" allowing to access to the Replica PostgreSql instances

Consequently, a client app running inside a Kubernetes cluster, would use the hostname "mypostgres" to connect to the Primary PostgreSql for read and write requests, and optionally it can also use the hostname "mypostgres-replica" to connect to any of the available Replica PostgreSql for read requests.


Which is incorrect. The Services created are unusable, apparently by design. They have no Cluster IP address. See issue #1. The documentation needs to cover manually creating the services.

Hisdad commented 3 years ago

And if you do pre-create the service, it still tries to create it anyway. get events

6m56s Warning ServiceDeploymentErr kubegres/postgres-nextcloud Unable to deploy Primary Service. 'Service name': postgres-nextcloud - services "postgres-nextcloud" already exists

alex-arica commented 3 years ago

Thank you for your message.

In Kubernetes, when we create a Service and we do not define the field 'spec.type', then it is by default of a type ClusterIP.

However, Kubegres creates "headless services" by setting the field 'clusterIP: None' and Kubernetes configures automatically DNS since Kubegres has defined selectors in the service's YAML

That means if a client app is running inside its own Pod and wants to access to a cluster of Postgres Pods inside the same namespace, it can do so by using the hostname matching the name of the Postgres cluster name created with Kubegres (e.g. "mypostgres").

Could you please provide more details about your use-case?

What type of service are you trying to create (ClusterIP, NodePort, LoadBalancer), etc...?

Hisdad commented 3 years ago

Thanks that clarifies things. I was seeing

kubectl get svc

postgres-nextcloud ClusterIP None 5432/TCP 96s postgres-nextcloud-replica ClusterIP None 5432/TCP 53s

Which implied there was no ip. Particularly since the php-fpm image I was using failed with "cannot resolve host postgresql-nextcloud" yep, spot the obvious error!

Dns lookup does work.

k exec dnsutils -it -- nslookup postgres-nextcloud Server: 10.96.0.10 Address: 10.96.0.10#53

Name: postgres-nextcloud.default.svc.cluster.local Address: 10.244.2.121

Perhaps you could explain in the quick start guide that not having a clusterIp on the svc is correct?

Thanks for your time in replying! --John

alex-arica commented 3 years ago

Good point. I will update the documentation as you suggested.

alex-arica commented 3 years ago

I updated the Getting-started page, as follows:

" Note that because Kubegres creates Headless services and configure them with selectors, then no cluster IP addresses are created and the DNS resolves directly to the IPs of the Postgres Pods. "