Access a Database from Outside the Cluster
Post-deployment guide
This guide contains instructions on how to connect to a database from outside the cluster using kubectl
port-forwarding method.
Prerequisites
Installation and configuration.
The steps to install and configure kubectl to access the Kubernetes Cluster in your machine are given below.
Install kubectl.
Check the kubectl version.
Configure kubectl and create a .kube directory in your home folder.
Download the kube-config file from Rancher UI.
Place the kube-config file in the .kube folder.
Set permissions for the kube-config file.
Export the KUBECONFIG environment variable.
Verify the configuration.
You must have access to the Kubernetes Cluster.
You must have the necessary permissions to perform port-forwarding to the database service in the Kubernetes Cluster.
Procedure
Ensure that the cluster kubeconfig is set on your machine and follow the commands below to connect to the respective database.
Get the database services running in the cluster using the command below.
Confirm the database you want to connect. Perform port-forwarding for the corresponding service using the
kubectl
command.Connect to the database.
\
Notes
The
kubectl port-forward
must keep running in the foreground while you are accessing the database.Ensure that your local port (e.g., 5432) is not being used by another service on your local machine.
Last updated