FusionAuth
    • Home
    • Categories
    • Recent
    • Popular
    • Pricing
    • Contact us
    • Docs
    • Login

    Connection Issues Between FusionAuth and PostgreSQL in Kubernetes on Docker Desktop

    Scheduled Pinned Locked Moved
    General Discussion
    2
    2
    3.0k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • V
      vinaymanepalli30
      last edited by

      I am running Kubernetes, which is enabled in the Docker Desktop application on my system. My application (Fusion AUTH) is running in pods, and I need to connect to a PostgreSQL database on my localhost. Both are installed 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
      
      * 127.0.0.1 kubernetes.docker.internal
      
      * localhost
      
      *  host.docker.internal
      
      

      Blow my yaml file

      # Here my pod deployment file
      
      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: postgresadmin # PostgreSQL username
              - name: DATABASE_PASSWORD
                value: PGSqlAdm1n@$2024 # 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
      
      
      # Here k8s service
      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
      
      
      # here k8s ingress
      
      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
      

      Blow my yaml file

      # Here my pod deployment file
      
      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: postgresadmin # PostgreSQL username
              - name: DATABASE_PASSWORD
                value: PGSqlAdm1n@$2024 # 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
      
      
      # Here k8s service
      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
      
      
      # here k8s ingress
      
      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
      
      mark.robustelliM 1 Reply Last reply Reply Quote 0
      • mark.robustelliM
        mark.robustelli @vinaymanepalli30
        last edited by

        @vinaymanepalli30 I am not a Kubernetes expert by any means. It looks like you have the right approach. Can you connect the localhost db from the localhost? Can you run and share your ip config once all the machines are up and running?

        1 Reply Last reply Reply Quote 0
        • First post
          Last post