Как получить доступ к сервису Kong в декларативной конфигурации без базы данных

Я настроил конг с декларативным подходом. Моя служба и маршруты настроены как.

services:
 - name: mock-service
   url: http://mockbin.org/request
   path: /
   tags:
   - example
   routes:
    - name: mock-route
      methods:
      - GET
      hosts: ["mockbin.org"]
      paths: ["/mock"] 

Моя служба и маршруты были зарегистрированы, и я вижу ответ как

http://localhost:8001/services  :-  Response 


{ 
   "next":null,
   "data":[ 
      { 
         "host":"mockbin.org",
         "created_at":1577708204,
         "connect_timeout":60000,
         "id":"9ff0ee4e-7c2b-51e3-9490-f93f946547e8",
         "protocol":"http",
         "name":"mock-service",
         "read_timeout":60000,
         "port":80,
         "path":"/request",
         "updated_at":1577708204,
         "client_certificate":null,
         "tags":[ 
            "example"
         ],
         "write_timeout":60000,
         "retries":5
      }
   ]
}


http://localhost:8001/routes   Response

{ 
   "next":null,
   "data":[ 
      { 
         "id":"21113e89-d366-5f75-b44a-cef07644d282",
         "tags":null,
         "updated_at":1577708204,
         "destinations":null,
         "headers":null,
         "protocols":[ 
            "http",
            "https"
         ],
         "created_at":1577708204,
         "snis":null,
         "hosts":[ 
            "mockbin.org"
         ],
         "name":"mock-route",
         "preserve_host":false,
         "regex_priority":0,
         "strip_path":true,
         "sources":null,
         "methods":[ 
            "GET"
         ],
         "https_redirect_status_code":426,
         "paths":[ 
            "/mock"
         ],
         "service":{ 
            "id":"9ff0ee4e-7c2b-51e3-9490-f93f946547e8"
         }
      }
   ]
}

When i am trying to acess the my mockbin service though kong . i not getting the response .

http://localhost:8000/mock    if host is not passed in header

{
"message": "no Route matched with those values"
}


http://localhost:8000/mock   if host is passed in header

-header 

 Host   mockbin.org

 response status :- 500 

 An unexpected error occurred

Ошибка в файле журнала kong:

2019/12/30 17:46:44 [notice] 60919#0: *2 [kong] init.lua:298 declarative config loaded from /var/kong.yml, context: init_worker_by_lua*
2019/12/30 17:46:44 [warn] 60917#0: *1 [lua] globalpatches.lua:52: sleep(): executing a blocking 'sleep' (0.001 seconds), context: init_worker_by_lua*
2019/12/30 17:49:56 [error] 60920#0: *1586 upstream timed out (110: Connection timed out) while connecting to upstream, client: 172.21.200.35, server: kong, request: "GET /mock HTTP/1.1", upstream: "http://3.228.254.201:80/request", host: "mockbin.org"
2019/12/30 17:49:56 [error] 60920#0: *1586 [lua] balancer.lua:917: balancer_execute(): DNS resolution failed: dns server error: 100 cache only lookup failed. Tried: ["(short)mockbin.org:(na) - cache-miss","mockbin.org:1 - cache only lookup failed/dns server error: 100 cache only lookup failed","mockbin.org:33 - cache only lookup failed/dns server error: 100 cache only lookup failed","mockbin.org:5 - cache only lookup failed/dns server error: 100 cache only lookup failed"] while connecting to upstream, client: 172.21.200.35, server: kong, request: "GET /mock HTTP/1.1", upstream: "http://3.228.254.201:80/request", host: "mockbin.org"
2019/12/30 17:49:56 [error] 60920#0: *1586 [lua] init.lua:800: balancer(): failed to retry the dns/balancer resolver for mockbin.org' with: dns server error: 100 cache only lookup failed while connecting to upstream, client: 172.21.200.35, server: kong, request: "GET /mock HTTP/1.1", upstream: "http://3.228.254.201:80/request", host: "mockbin.org"
2019/12/30 17:57:02 [error] 60918#0: *6694 upstream timed out (110: Connection timed out) while connecting to upstream, client: 172.21.200.35, server: kong, request: "GET /mock HTTP/1.1", upstream: "http://3.228.254.201:80/request", host: "mockbin.org"
2019/12/30 17:58:02 [error] 60918#0: *6694 upstream timed out (110: Connection timed out) while connecting to upstream, client: 172.21.200.35, server: kong, request: "GET /mock HTTP/1.1", upstream: "http://52.21.131.234:80/request", host: "mockbin.org"
2019/12/30 17:58:02 [error] 60918#0: *6694 [lua] balancer.lua:917: balancer_execute(): DNS resolution failed: dns server error: 100 cache only lookup failed. Tried: ["(short)mockbin.org:(na) - cache-miss","mockbin.org:1 - cache only lookup failed/dns server error: 100 cache only lookup failed","mockbin.org:33 - cache only lookup failed/dns server error: 100 cache only lookup failed","mockbin.org:5 - cache only lookup failed/dns server error: 100 cache only lookup failed"] while connecting to upstream, client: 172.21.200.35, server: kong, request: "GET /mock HTTP/1.1", upstream: "http://52.21.131.234:80/request", host: "mockbin.org"
2019/12/30 17:58:02 [error] 60918#0: *6694 [lua] init.lua:800: balancer(): failed to retry the dns/balancer resolver for mockbin.org' with: dns server error: 100 cache only lookup failed while connecting to upstream, client: 172.21.200.35, server: kong, request: "GET /mock HTTP/1.1", upstream: "http://52.21.131.234:80/request", host: "mockbin.org"

Я следил за статьей, чтобы решить эту проблему. но не удалось.

https://docs.konghq.com/0.13.x/getting-started/configuring-a-service/

https://www.jerney.io/secure-apis-kong-keycloak-1/

https://medium.com/@vasista/explaining-kong-plugins-key-authentication-and-rate-limiting-on-flask-api-9f922c4f051


person shiv roy    schedule 30.12.2019    source источник


Ответы (1)


У меня была такая же проблема, и я решил ее таким образом: я использовал конфигурацию ниже: kong.yml

services:
  - name: userapi-service
    url: http://localhost:8082/userapi
    tags:
    - userapi
  routes:
  - name: userapi-route
    paths:
    - /userapi

Попадание ниже при доступе к http://localhost:8001/services

{
"next": null,
"data": [
    {
        "host": "localhost",
        "created_at": 1584710150,
        "connect_timeout": 60000,
        "id": "973c6d1e-b31b-5453-8424-20ad70a0c6c2",
        "protocol": "http",
        "name": "userapi-service",
        "read_timeout": 60000,
        "port": 8082,
        "path": "/userapi",
        "updated_at": 1584710150,
        "client_certificate": null,
        "tags": [
            "userapi"
        ],
        "write_timeout": 60000,
        "retries": 5
    }
  ]
}

и, как показано ниже, при доступе к маршрутам: http://localhost:8001/services/userapi-service/routes

{
"next": null,
"data": [
    {
        "id": "3ba059ab-673e-5c4e-9eb6-eb5aa3437476",
        "path_handling": "v0",
        "paths": [
            "/"
        ],
        "destinations": null,
        "headers": null,
        "protocols": [
            "http",
            "https"
        ],
        "created_at": 1584710150,
        "snis": null,
        "service": {
            "id": "973c6d1e-b31b-5453-8424-20ad70a0c6c2"
        },
        "name": "userapi-route",
        "tags": null,
        "preserve_host": false,
        "regex_priority": 0,
        "strip_path": true,
        "sources": null,
        "updated_at": 1584710150,
        "https_redirect_status_code": 426,
        "hosts": [
            "example.com"
        ],
        "methods": null
    }
  ]
}

и использовал http://localhost:8000/ -header Host: example.com и использовал относительный путь моего вызов api: http://localhost:8000/userapi/xxxxx/xxxx

person Rajan Mishra    schedule 20.03.2020