Nomad consul connect for mongodb

Good day,
I am trying to set up communication between a web application and a mongo database via consul connect. I have created two separate groups and I am trying to configure access from demoappgroup to mongogroup using connect stanza. I cannot connect to mongo database from demoapptask through 127.0.0.1 IP on port 8808 and application also could not do it. If I change IP to nomad client node IP it is working. I used the same configuration for providing local consul cluster in nomad cluster and it is working perfectly… Do you have any ideas? I really don’t know where is the problem. Thank you in advance for you help

job "demowebcc" {
  datacenters = ["dc1"]


  group "mongogroup" {
    network {
      mode = "bridge"
    
      port "mongo" {
        static = 27017
        to = 27017
      }
    }

    service {
        name = "mongodb"
        port = "27017"

        connect{
        sidecar_service {
        }
      }
    } 

    volume "mongodb" {
      type      = "host"
      read_only = false
      source    = "mongodb"
    }

    task "mongotask" {
      driver = "docker"

      volume_mount {
        volume      = "mongodb"
        destination = "/data/db"
        read_only   = false
      }

      config {
        image = "mongo:4.4.3"
      }
    }
  }


  group "demoappgroup" {
    count = 1

    network {
      mode  = "bridge"
      port "http" {
        static = 8081
        to = 8001
      }
    }

    service {
        name = "demoapp"
        port = "http"

        connect {
          sidecar_service {
            proxy {
              upstreams {
                destination_name = "mongodb"
                local_bind_port = 8808
              }
            }
          }
        }

    }
    
    task "demoapptask" {
      driver = "docker"
      config {
        image = "registry.gitlab.com/demo-app:v1"
        auth {
          server_address = "registry.gitlab.com"
          username = "gitlab-ci-token"
          password = "XXXXX"
        }
      }

      env {
          SPRING_DATA_MONGODB_URI = "mongodb://127.0.0.1:8808/dbname"
          SPRING_DATA_MONGODB_DATABASE = "dbname"
          SERVER_PORT = "8001"
          MANAGEMENT_SERVER_PORT = "9080"
          APP_META_ENVIRONMENT = "dev"
      }

    } 

  }
}

Hi @zhiliaev,

I don’t see anything particularly wrong with the job you posted, which might indicate that there might be something wrong in the environment.

Could you check if your clients have the proper CNI and Consul configuration? Could you also try running the Countdash example as well?

1 Like