Kubernetes - Get the public URL of a service into my ConfigMap

5/17/2018

I have my Kubernetes service of which I'm getting the url in my minikube installation using:

minikube service postgres --url

Which returns the URL like: http://192.xxx.xx.xxxx:3xx62

However I want this URL to be used in my ConfigMap as the pghost and pgport - so for example:

apiVersion: v1
kind: ConfigMap
metadata:
  name: firsttest
  labels:
    app: firsttest
data:
  pgdatabase: "first_test"
  pguser: "postgresql_user"
  pghost: ""
  pgport: ""
  pgpool_size: "5"
  auth_user: "unique"

And the service looks like:

apiVersion: v1
kind: Service
metadata:
  name: postgres
spec:
  type: NodePort
  ports:
  - name: pgql
    port: 5432
    targetPort: 5432
    protocol: TCP
  selector:
    app: postgres

Is this possible?

Any help appreciated.

Thanks.

-- userMod2
kubernetes
minikube

1 Answer

5/17/2018

I will just compile a list of some crucial things about interaction with Services:

  1. You can create a Service object before creating pods with services, it is OK.
  2. To access the service inside a cluster, you should use "ClusterIP."
  3. You cannot use variables like a name of a service, but you can use FQDN of the service, and it's IP address, which is static and will be available until you delete a service.
  4. Service's IP and port are what you need to access pods behind a service.
-- Anton Kostenko
Source: StackOverflow