I have a local .NET Core application for a web API, and my PostgreSQL (psql) database is deployed in a Kubernetes cluster, specifically for my development environment. As per the requirements, I cannot install the database locally. Now, I need to test my API's POST code, which utilizes Entity Framework (EF), by checking if tables are created and data is saved in the database. I have obtained the connection string from the cluster, which is as follows:
Host=postgres-new-postgresql-helm.database-new.svc.cluster.local; Port=54000; Username=admin; Password=admin; Database=db; SearchPath=public;
I would like to connect to this database from my local machine and use pgAdmin4 to view the changes in the development cluster-deployed database. Specifically, I want to see the tables created and verify if the data is being saved correctly. Could you please guide me on how to establish a connection to this database using pgAdmin4 and visualize the changes made in the development cluster-deployed database? I would like to use the graphical user interface (GUI) provided by pgAdmin4 for this purpose.
Thank you in advance for your assistance.
Brahma Prakash ShuklaPosted Jun 30, 2023, 11:27 AM
Hi Sujeet,
To enable your local machine to access the Kubernetes cluster where the database is deployed, you need to set up the necessary network connectivity and configure the Kubernetes resources. Here are the steps you can follow:
Expose the PostgreSQL service:
LoadBalancerorNodePort. For example, to expose the service using aLoadBalancertype, you can run the following command:with the name of your PostgreSQL service andwith the desired name for the externally accessible service.Obtain the external IP or domain name:
Update local machine's hosts file (if necessary):
/etc/hostson Unix-like systems orC:\Windows\System32\drivers\etc\hostson Windows) using a text editor with administrative privileges.with the actual IP obtained in the previous step andmy-postgres-clusterwith the desired hostname.Connect from local machine:
By following these steps, you should be able to establish the necessary network connectivity between your local machine and the Kubernetes cluster. Remember to ensure that your cluster's network policies and firewall rules allow inbound connections from your local machine to the exposed PostgreSQL service.
Tuhin PaulPosted Jul 2, 2023, 10:08 AM
1. If your PostgreSQL deployment is in a specific namespace within the Kubernetes cluster, you'll need to provide the namespace when running the kubectl commands.
2. Before exposing the service, it's essential to verify the service type associated with your PostgreSQL deployment. The service type determines how the service will be exposed.
3. Specify the port number along with the external IP or domain name when connecting to the PostgreSQL database.
Sujeet RamanPosted Jun 30, 2023, 9:57 AM
i want to know this step-local machine can access the Kubernetes cluster where the database is deployed and that the necessary network connectivity is established.what needs to be done from cluster
Brahma Prakash ShuklaPosted Jun 30, 2023, 8:38 AM
To connect to your PostgreSQL database deployed in a Kubernetes cluster using pgAdmin4 and visualize the changes, you can follow these steps:
Step 1: Install pgAdmin4
Step 2: Launch pgAdmin4
Step 3: Add a new server
Step 4: Configure the server connection
postgres-new-postgresql-helm.database-new.svc.cluster.localin your case.54000.adminand the password isadmin.db.Step 5: Connect to the server
Step 6: Explore the database
By following these steps, you should be able to connect to your PostgreSQL database deployed in the development cluster using pgAdmin4 and visualize the tables and data. Make sure that your local machine can access the Kubernetes cluster where the database is deployed and that the necessary network connectivity is established.