Cannot connect to my webservice when creating new API (Upstream host lookup failed)

Hi,

I have a webservice named “snapshot” on docker cloud BYON (on my own server) and i would like to deploy TYK on this server.

My snapshot WS is running with a stackfile on docker cloud (nodejs service and redis) and exposing the port 3000.

I don’t know how to deploy TYK on dockercloud via the docker cloud web interface so i’ve cloned the tyk_quickstart github repo on my server and launch it with the docker-compose file.

I can connect to the TYK Dashboard, but when i create a API for my snapshot WS deployed with a stackfile through the cloud.docker.com web interface, it seems the TYK gateway doesn’t see my snapshot WS and i get this error : “Upstream host lookup failed”. (http://apidomain/snapshot/)

How can i deploy TYK on dockercloud or how can i make “dockercloud” network and “gateway” network (from docker-compose) communicate together please ?

Hello!

Docker cloud stackfiles are basically almost same as docker-compose configuration files.
I did not tried docker cloud yet (and this is something we are working on to have in our documentation and examples), but seems like removing “services” and “version” fields from docker-compose file https://github.com/TykTechnologies/tyk_quickstart/blob/master/docker-compose.yml should be enough to run it on docker cloud. You probably also need to create data volume, copy configuration files to it, and update “volumes” section in yml file.

How can i deploy TYK on dockercloud or how can i make “dockercloud” network and “gateway” network (from docker-compose) communicate together please ?

So, to summary: your API accessible only to internal docker cloud network, and your local app do not see it? If so, then for sure you should try run Tyk inside docker cloud, and include it to your stackfile along with your app. Another option will be make your API accessible to the public, but allow it only to IP address of your Tyk gateway (if docker cloud allows IP whitelisting): but well, it is for sure not so reliable as the first option.

Leonid, Tyk team

Hi!

Thank you very much for your answer !!

I tried successfully to write a stackfile from the docker-compose file, here is my stackfile for your documentation and examples :

(you need to remove, “services”, “version”, “networks” (and aliases). I remove tyk_ prefixes in services names (because you cannot use underscores in service name in stackfile). I also remove useless “hostnames” and i replace http://tyk_dashboard:3000 to http://dashboard:3000 in tyk.conf file. And i set absolutes paths in volumes entries.

dashboard:
    image: 'tykio/tyk-dashboard:latest'
    ports:
        - '3000:3000'
        - '5000:5000'
    volumes:
        - '/usr/src/app/tyk_quickstart/tyk_analytics.conf:/opt/tyk-dashboard/tyk_analytics.conf'
gateway:
    image: 'tykio/tyk-gateway:latest'
    ports:
        - '80:8080'
        - '8080:8080'
    volumes:
        - '/usr/src/app/tyk_quickstart/tyk.conf:/opt/tyk-gateway/tyk.conf'
mongo:
    command: mongod --smallfiles
    image: 'mongo:latest'
    ports:
        - '27017:27017'
pump:
    image: 'tykio/tyk-pump-docker-pub:latest'
    volumes:
        - '/usr/src/app/tyk_quickstart/pump.conf:/opt/tyk-pump/pump.conf'
redis:
    image: 'redis:latest'
    ports:
        - '6379:6379'

I was wondering if we could configure TYK through environments variables instead of externals config files in volumes entries (in order to wrap everything in only one single file and make it easier to manage) ?

Great! We will update our documentation!

Well, I’ll be honest, Tyk is very powerful platform with a lot of functionality and components. It is indeed possible to make it run without configuration files, but not sure if this will be useful for any use case, except tutorials. Or we can define few dozens of environment variables :slight_smile:

Leonid, Tyk Team

I understand, thank you ! Maybe i will use a container with a volume in an another container in my “tyk” stack.

Unfortunately, i cannot connect to my portal i don’t know if it’s because of my stackfile, my conf or something else ?

Tyk dashboard is on the domain : api.domain.com

Theses DNS entries is redirecting to my server :

I replaced “custom domain url” in the three API (created by default, in grey) to : developers.domain.com. When i click on the link Your Developer Portal > Open Your Portal, i get the error :

{
    "error": "There was a problem proxying the request"
}

I don’t know why ?

Just to clarify, does it means that without custom domains it works fine? I mean Docker cloud probably gives some built-in DNS records by default.

Do you use SSL? Expired TLS certificates may also cause issues like you described.

No, it doesn’t work without custom domains and i don’t use SSL

The default custom domain was something like www.tyk-portal-test.com

Is portal domain need to be different from API domain ?

EDIT:

It works !!! I have manually replaced “localhost” to “dashboard” which is the hostname (service name) in the stackfile :

http://localhost:3000/588fae1ab41fd60001333285/portal/ => http://dashboard:3000/588fae1ab41fd60001333285/portal/

But the only way to access to the portal is by this URL : http://api.domain.com/portal but, i would like to access from the root : http://api.domain.com. Is it possible ?

Great!

This section in Tyk quick start may be helpful https://github.com/TykTechnologies/tyk_quickstart#note-to-enable-the-portal

Especially this paragraph:

If you wish to change your portal domain - DO NOT USE the drop-down option in the navigation, instead, change the domain names in the three site entries in the API section. However, if you want clean URLs constructed for your APIs in the dashboard, setting this value will show the URLs for your APIs as relative to the domain you’ve set.

Leonid, Tyk team

Thank you very much leon !!

I have one more pleasant surprise for you :slight_smile:

One of my co-workers noticed that we actually have support for configuring via environment variables, and I completely forgot about it!

You can override almost any configuration variable using it. Example for gateway:
TYK_GW_LISTEN_PORT=8080 TYK_GW_STORAGE_HOST=tyk-redis ./tyk

Every component have own environment variable prefix: tyk - TYK_GW, tyk-analytics - TYK_DB, tyk-pump - TYK_PMP

Variable names should have same names as configuration options, if it is nested, separate it by “_” (like STORAGE_HOST above).

Leonid, Tyk Team

Cool, thank you !

Do i need to specify the full configuration for each component ? Or, can i run all the components without specifying any configuration (file or env) ? Is there a “default” configuration ?

How can i change the “superadmin” password which is “12345” by default ? Can i change it with a environment variable ?

I don’t find the way to set the secretkey with environment variable ?

Each component has a default configuration, and theoretically, should run even without config (it will assume that all databases on localhost). I can guarantee that it works for Tyk Gateway but rest of services needs to be tested.

For “admin” password try TYK_DB_ADMIN_SECRET variable.

Leonid, Tyk Team

Thank you Leon, it works :slight_smile:

1 Like