I am running Kubernetes, which is enabled in the Docker Desktop application on my system. My application (FusionAuth) is running in pods, and I need to connect to a PostgreSQL database on my localhost. Both are on the same system, but I cannot establish a connection. I have also tried using the Docker bridge network.
For the database connection string, I attempted the following:
Server=host.docker.internal;Database=yourdatabase;User Id=yourusername;Password=yourpassword; & jdbc:postgresql://host.docker.internal:5432/yourdatabase?user=yourusername&password=yourpassword
here below my Yaml file
apiVersion: v1
kind: Namespace
metadata:
name: fusionauth # Create a namespace for FusionAuth
apiVersion: apps/v1
kind: Deployment
metadata:
name: fusionauth # Deployment for FusionAuth application
namespace: fusionauth
spec:
replicas: 1 # Number of FusionAuth replicas
selector:
matchLabels:
app: fusionauth # Label to identify the FusionAuth deployment
template:
metadata:
labels:
app: fusionauth # Labels for the pods
spec:
containers:
- name: fusionauth
image: fusionauth/fusionauth-app:latest # Latest FusionAuth image
env:
- name: DATABASE_URL
value: jdbc:postgresql://host.docker.internal:5432/postgressql # Database connection string
- name: DATABASE_USERNAME
value: # PostgreSQL username
- name: DATABASE_PASSWORD
value: # PostgreSQL password
- name: DATABASE_DRIVER_CLASS_NAME
value: org.postgresql.Driver # PostgreSQL driver class name
ports:
- containerPort: 9011 # Exposing FusionAuth port
resources:
requests:
memory: “512Mi” # Minimum memory request
cpu: “500m” # Minimum CPU request
limits:
memory: “1Gi” # Maximum memory limit
cpu: “1” # Maximum CPU limit
apiVersion: v1
kind: Service
metadata:
name: fusionauth # Service for FusionAuth
namespace: fusionauth
spec:
ports:
- port: 9011 # Port to access FusionAuth
targetPort: 9011 # Target port on the FusionAuth pod
selector:
app: fusionauth # Select pods with this label
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: fusionauth-ingress
namespace: fusionauth
spec:
ingressClassName: nginx
rules:
- http:
paths:- path: /
pathType: Prefix
backend:
service:
name: fusionauth
port:
number: 9011
- path: /