'Kubernetes (K8s) Minikubes : how to use service URL in ConfigMap so other pods can use it
database-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: postgres
name: postgres-db
spec:
replicas:
selector:
matchLabels:
app: postgres-db
template:
metadata:
labels:
app: postgres-db
spec:
containers:
- name: postgres-db
image: postgres:latest
ports:
- protocol: TCP
containerPort: 1234
env:
- name: POSTGRES_DB
value: "classroom"
- name: POSTGRES_USER
value: temp
- name: POSTGRES_PASSWORD
value: temp
database-service.yaml
apiVersion: v1
kind: Service
metadata:
name: database-service
spec:
selector:
app: postgres-db
ports:
- protocol: TCP
port: 1234
targetPort: 1234
I want to use this database-service url for other deployment so i tried to add it in configMap
my-configMap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: classroom-configmap
data:
database_url: database-service
[Not Working] Expected - database_url : database-service (will be replaced with corresponding service URL)
ERROR - Driver org.postgresql.Driver claims to not accept jdbcUrl, database-service
[Working] - database_url: jdbc:postgresql://database-service:5432/classroom
$ kubectl describe configmaps classroom-configmap
Output :
Name: classroom-configmap
Namespace: default
Labels: <none>
Annotations: <none>
Data
====
database_url:
----
database-service
BinaryData
====
Events: <none>
Solution 1:[1]
According to the error you are having:
Driver org.postgresql.Driver claims to not accept jdbcUrl
It seems that there are a few issues with that URL, and a latest PSQL driver may complain.
jdbc:postgres:isn't right, usejdbc:postgresql:instead- Do not use
jdbc:postgresql://<username>:<passwor>..., user parameters instead: jdbc:postgresql://<host>:<port>/<dbname>?user=<username>&password=<password> - In some cases you have to force SSL connection by adding
sslmode=requireparameter
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pepe T. |
