last day (15 days later) » 

08:52
0
Q: Unable to establish connection with postgres by using ClusterIP service

LordCan't reach database server at postgres-srv:5432 Please make sure your database server is running at postgres-srv:5432. depl.yaml apiVersion: v1 kind: ConfigMap metadata: name: postgres-config labels: app: postgres data: POSTGRES_DB: postgresdb POSTGRES_USER: postgres POSTGRES_PASSW...

Try with postgres-srv.default:5432
@Yayotrón thank you but same result: Can't reach database server at postgres-srv.default:5432
Could you show us your deployment configuration? deployment yaml and pod yaml
Ummm I just tried the same setup you pasted here in my cluster and I was able to connect to the database using psql cli. How are you trying to connect? From where? Is it another pod?
yes from different pod
Is this pod in the same namespace? Which mechanism are you using to establish the connection (psql cli/some postgres client)?
08:52
they are in the same name space, I am using prisma orm
Could you try with postgres-srv.default.svc.cluster.local:5432?
Can't reach database server at postgres-srv.default.svc.cluster.local:5432
hey mate
hi
I'll try help you troubleshooting, your setup looks fine and works in my cluster so I suspect it's either misconfiguration on your cluster's dns setup or an issue with the client you're using to connect
08:54
it's been a rough day, I am trying to establish connection almost 3 hr's
sure that's will be great help, by the way I am new to kubernets world :D
By default, k8 cluster exposes an internal DNS record for every service under <service-name>.<namespace-name>.svc.cluster.local, so that should be the address you use to connect
To discard issues with your client, could you deploy a pod with psql cli on it?
We'll try to connect from there
An image with ubuntu and running
apt-get update
apt-get install -y postgresql-client

Should do it
sure, thanks, by the way I am able to access the psql inside of my pod, will it help?
Inside the other pod (not the database itself)?
I download postgres image from docker and deployed in k8s cluster
If you have psql from there, try connecting using this:

PGPASSWORD=root psql -h postgres-srv.default.svc.cluster.local -p 5432 -U postgres -d postgresdb
Try running that from a pod (other than your db) with psql CLI
09:00
ok
I have 2 pod, 2nd one dose not have bash access
you're running that from your machine, please run it from inside the pod
kubectl exec -it {podName} -- bash
if there's no bash try with sh
which base image are you using? that looks like alpine
will I be able to install postgresql-client, inside busybox?
yes that is alpine
try apk add postgresql-client then
alpine doesnt have apt-get
09:14
ok
so yes, you were able to connect :)
Then the issue is with your client specifically
please advice me how I will debug
How are you trying to establish the connection from your other client?
You mentioned you're using prisma orm or something
According to their docs, you should connect doing somethnig like this

datasource db {
provider = "postgresql"
url = "postgresql://postgres:[email protected]:5432/postgresdb?schema=public"
}
09:24
unsuccessful
How are you trying this code? Are you running it locally?
yes
...
This domain postgres-srv.default.svc.cluster.local only exists inside the kubernetes cluster
You won't be able to access it from your machine
If you want to access the database from your machine you have a few options
I am inside minikube,
Given that it's a database I'd recommend doing a port-forwarding as you don't want to expose it through the public internet
I mean but are you deploying your code to the cluster as a deployment ? Or you're running it from the IDE?
09:27
cluster as a deployment
Could you show me how you are deploying it?
The deployment.yaml of your client
apiVersion: v1
kind: ConfigMap
metadata:
name: postgres-config
labels:
app: postgres
data:
POSTGRES_DB: postgresdb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: root
---
kind: PersistentVolume
apiVersion: v1
metadata:
name: postgres-pv-volume
labels:
app: postgres
type: local
spec:
storageClassName: manual
capacity:
storage: 5Gi
accessModes:
- ReadWriteMany
hostPath:
path: /var/lib/data
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: postgres-pv-claim
labels:
app: postgres
spec:
storageClassName: manual
Ok but this what you have here is the deployment of your database
I'm asking now about the client (your nodejs application) how are you running it?
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecom-master-depl
spec:
replicas: 1
selector:
matchLabels:
app: ecom-master
template:
metadata:
labels:
app: ecom-master
spec:
containers:
- name: ecom-master
image: lordrafiq/ecom-master
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
env:
- name: NATS_CLIENT_ID
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NATS_URL
value: "http://nats-srv:4222"
- name: NATS_CLUSTER_ID
value: "ticketing"

- name: JWT_KEY
And you are deploying this to try connect to the database? Where are you configuring the db connection?
09:32
inside schema.prisma file
datasource db {
provider = "postgresql"
url = "postgresql://postgres:[email protected]:5432/postgresdb?schema=public"
}

generator client {
provider = "prisma-client-js"
}
and have you generated a new docker image with this new url?
This image is what you're deploying
image: lordrafiq/ecom-master
yes
this image contain schema.prisma file
by the way, I am using skaffold
also pushing and syncing image from docker hub
Umm :/ I'm not sure then, what you're having is not a kubernetes issue anymore as you can connect to your database from other clients
I think you should ask another question specific to nodejs/prisma setup now
Or try with other configurations for this prisma stuff
I'm not a js guy so I can't help much there :(
Yes after debugging, I am agree with you, It 's not Kubernetes issues.
Thank you, your help gave me a new lead.

last day (15 days later) »