Send trafic to ingress-gateway

Hello guys,

I’m using nomad 1.3.5 and consul 1.13.1.

I’m trying to send trafic to consul ingress-gateway deployed in nomad with the following:

job "ingress-gateway" {
  region      = "europe-west1"
  datacenters = ["europe-west1"]
  type        = "service"

  update {
    max_parallel     = 1
    health_check     = "task_states"
    min_healthy_time = "15s"
    healthy_deadline = "60s"
    canary           = 1
    auto_revert      = true
    auto_promote     = true
  }

  group "ingress-gateway" {
    count = 1
    network {
      mode = "bridge"
      port "inbound" {
        to = 8080
      }
    }

    service {
      name = "ingress-gateway"
      port = "inbound"

      connect {
        gateway {
          proxy {}

          ingress {
            listener {
              port = 8080
              protocol = "http"
              
              service {
                name = "nginx"
                hosts = ["*"]
              }
            }
          }
        }
      }
    }
  }

  group "nginx" {
    count = 1
    network {
      mode = "bridge"
      port "http" {
        to     = 8080
      }
    }

    service {
      name = "nginx"
      port = "8080"

      check {
        expose   = true
        type     = "http"
        path     = "/health"
        interval = "10s"
        timeout  = "2s"
      }

      connect {
        sidecar_service {}
      }
    }

    task "nginx" {
      driver = "docker"

      config {
        image = "nginx:latest"
        ports = ["http"]

        volumes = [
          "local:/etc/nginx/conf.d",
        ]
      }

      template {
        data = <<EOF
server {
   listen 8080;

   location / {
     add_header Content-Type text/plain;
     return 200 "[host] = $host [http_host] = $http_host";
   }

   location = /health {
     add_header Content-Type text/plain;
     return 200 "OK";
   }
}
EOF

        destination   = "local/default.conf"
        change_mode   = "signal"
        change_signal = "SIGHUP"
      }
    }
  }

    group "loadbalancer-nginx" {
    count = 1
    network {
      mode = "bridge"
      port "http" {
        static = 9090
        to     = 8080
      }
    }

    service {
      name = "loadbalancer-nginx"
      port = "8080"

      check {
        expose   = true
        type     = "http"
        path     = "/health"
        interval = "10s"
        timeout  = "2s"
      }

      connect {
        sidecar_service {
          proxy {
            upstreams {
              destination_name = "ingress-gateway"
              local_bind_port  = 10000
              local_bind_address = "127.0.0.1"
            }
          }
        }
      }
    }

    task "nginx" {
      driver = "docker"

      config {
        image = "nginx:latest"
        ports = ["http"]

        volumes = [
          "local:/etc/nginx/conf.d",
        ]
      }

      template {
        data = <<EOF
server {
   listen 8080;
   error_log  /var/log/nginx/error.log debug;
   server_name _;

   location / {
     proxy_http_version 1.1;
     proxy_set_header Upgrade $http_upgrade;
     proxy_set_header Connection "upgrade";
     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:10000;

     #add_header Content-Type text/plain;
     #return 200 "[host] = $host [http_host] = $http_host";
   }

   location = /health {
     add_header Content-Type text/plain;
     return 200 "OK";
   }
}
EOF

        destination   = "local/default.conf"
        change_mode   = "signal"
        change_signal = "SIGHUP"
      }
    }
  }
}
cat >/tmp/consul_service_defaults.hcl<<EOF
> Kind      = "service-defaults"
Name      = "nginx"
Protocol  = "http"
EOF
consul config write /tmp/consul_service_defaults.hcl

On the nomad host here is the curl result:

curl http://127.0.0.1:9090
<html>
<head><title>502 Bad Gateway</title></head>
<body>
<center><h1>502 Bad Gateway</h1></center>
<hr><center>nginx/1.23.1</center>
</body>
</html>

From the docker container loadbalancer-nginx here is the curl result:

root@db25fea5ae8d:/etc/nginx/conf.d# curl http://127.0.0.1:10000
curl: (56) Recv failure: Connection reset by peer

I created ingress-gateway with a dynamic port instead of static in order to have multiple instances.

Why am I having connection reset?
Any help?
I’m supposed to receive an HTTP 200.

@shoenig Following this issue Multiple Ingress Gateways - Can't seem to get it to work - #3 by microadam do you have any idea what’s wrong?
My purpose is to have an ingress-gateway per nomad namespace and loadbalancer-nginx will send the appropriate trafic to the right namespace.

The answer is here Send trafic to ingress-gateway · Issue #14616 · hashicorp/nomad · GitHub