How to setup load-balancing with yaml file?

Hi,

I am new to Kong, and am trying to get Kong (version 1.3.0rc2) working with a yaml configuration to set it up as a load-balancer. From my understanding I need to use upstream objects for this and then set multiple targets.

From the documentation I understand that the host field in the service should be the same as that of the upstream name. Though this does not seem to work as it fails to resolve:

2019/08/26 14:26:34 [error] 36124#0: *2853 [lua] balancer.lua:848: execute(): DNS resolution failed: dns server error: 2 server failure. Tried: ["(short)a-upstream:(na) - cache-miss","a-upstream:33 - cache-miss/scheduled/querying/dns server error: 2 server failure","a-upstream:1 - cache-miss/scheduled/querying/dns server error: 2 server failure","a-upstream:5 - cache-miss/scheduled/querying/dns server error: 2 server failure"], client: 192.168.184.129, server: kong, request: "GET /a HTTP/1.1", host: "ubuntu.local"

kong.conf

proxy_listen = 0.0.0.0:80, 0.0.0.0:443 ssl
admin_listen = 127.0.0.1:8001, 127.0.0.1:8444 ssl

database = off
declarative_config = /etc/kong/kong.yml

kong.yml file:

_format_version: "1.1"

services:
  - name: a-service
    host: a-upstream
    routes:
      - paths:
          - /a

upstreams:
  - name: a-upstream
    targets:
      - target: httpbin.org

Anyone got a clue how to fix this?

Hello Max,

Try this config, I found default port for target is 8000, we need to spicify port number.

_format_version: "1.1"

services:
- name: a-service
  host: a-upstream
  routes:
  - paths:
    - /a

upstreams:
- name: a-upstream
  targets:
  - target: httpbin.org:80
1 Like

Thanks for your comment Narate!

I copied your yaml and deployed it, but unfortunately this does not seem to resolve my issue, I’m still getting the same dns error in the error.log.

Though this probably will save me some headache later on :slight_smile:

Any thoughts? I might have read the documentation wrong

Set log_level = debug in kong.conf, maybe you can see more log

Well it’s a miracle, somehow it now works…
All I did differently was instead of kong reload ..., i now did kong stop kong start ...

Strange thing though is that when I use the reload command and call the admin api, I do get the updated version of the yaml. But somewhere it seems it does not load the ring balancer? ( I guess )

Thanks for thinking with me Narate!