---
schema_version: "1"
id: 6116c5ae0deb41f6c59c9a8fa76dee3cba2636b6321453ffe6bb3cd09fde2753
title: Publishing an API Instance with Multiple Upstream Services in Local Mode
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.13/local-publish-api-multiple-services.md
canonical_url: https://docs.mulesoft.com/gateway/1.13/local-publish-api-multiple-services
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 568a07835d521dd0658d8e371b4d1507bb1f4b28b84200861c998fd35a5a14d8
description: MuleSoft Documentation Site
release: "1.13"
latest: false
---
---
product: Omni Gateway
version: 1.13
---

# Publishing an API Instance with Multiple Upstream Services in Local Mode

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

Omni Gateway running in Local Mode supports API instances that expose multiple upstream services
through a single consumer endpoint.

Omni Gateway manages traffic by using multiple routes with a defined route order and individual
rulesets to direct traffic to different sets of upstream services. Each API instance supports
multiple routes that can each direct traffic to multiple upstream services.

For Omni Gateways running in Local Mode, API instances with multiple upstream services are
configured by using the `ApiInstance` and the `PolicyBinding` YAML configuration resources. The
`ApiInstance` resource defines an API instance, and the `route-weighted` policy resource defines a
single route to one or multiple upstream services. To add additional routes, add multiple
`route-weighted` resources.

The following tutorials use a preconfigured `route-weighted` policy resource. For information about
how to configure the resource, see
[Traffic Management for Multiple Upstream Services (Weighted)](https://docs.mulesoft.com/gateway/1.13/policies-included-traffic-management).

<table><colgroup><col> <col> <col></colgroup><tbody><tr><td><div><div><p><span><a href="#linux"><img src="https://docs.mulesoft.com/gateway/1.13/_images/install-linux-logo.png" alt="20%" width="20%"></a></span></p></div></div></td><td><div><div><p><span><a href="#docker"><img src="https://docs.mulesoft.com/gateway/1.13/_images/install-docker-logo.png" alt="25%" width="25%"></a></span></p></div></div></td><td><div><div><p><span><a href="#kubernetes"><img src="https://docs.mulesoft.com/gateway/1.13/_images/install-kubernetes-logo.png" alt="20%" width="20%"></a></span></p></div></div></td></tr><tr><td><div><div><p><a href="#linux">Publish an API Running Behind Omni Gateway on Linux</a></p></div></div></td><td><div><div><p><a href="#docker">Publish an API Running Behind Omni Gateway in a Docker Container</a></p></div></div></td><td><div><div><p><a href="#kubernetes">Publish an API Running Behind Omni Gateway in a Kubernetes Cluster</a></p></div></div></td></tr></tbody></table>

## Publish an API Running Behind Omni Gateway on Linux

### Before You Begin

Before getting started, ensure that you have:

- Downloaded Omni Gateway. For more information, see [Downloading Omni Gateway](https://docs.mulesoft.com/gateway/1.13/install).

- Registered Omni Gateway and are running it in Local Mode. For more information, see
  [Register and Run in Local Mode](https://docs.mulesoft.com/gateway/1.13/local-reg-run).

- Your upstream service URLs.

### Publish an API

1.  Create a configuration file with a `.yaml` file extension:

    1.  Give the file a custom name.

    2.  Save the file in the Omni Gateway configuration directory
        `/etc/mulesoft/flex-gateway/conf.d/custom`. This directory can contain multiple
        configuration files.

2.  Copy and paste the following YAML snippet into the file, substituting the configuration field
    values with your values.

    The snippet refers to the fictional `products-api` and `products-api-beta` services and a
    fictional `json-http` API instance. Specify your own API name and your own service details:

    apiVersion: gateway.mulesoft.com/v1alpha1 kind: ApiInstance metadata: name: json-http spec:
    address: http://0.0.0.0:8080/json ​
    ---

    ​ apiVersion: gateway.mulesoft.com/v1alpha1 kind: PolicyBinding metadata: name:
    weight-routing-test spec: targetRef: name: json-http policyRef: name: route-weighted config:
    routes: - weight: 75 # max\_value=100, min\_value=1 destinationPath: /posts/ destinationRef:
    name: products-api - weight: 25 destinationPath: /posts/ destinationRef: name: products-api-beta
    rules:
    - path: (.\*) methods: POST headers: x-test: true host: test.com
    - methods: GET|POST headers: x-test: true y-test: false host: test.com

3.  Save the file. The gateway automatically refreshes the configuration.

4.  View the logs by executing the following command:

    journalctl -u flex-gateway-\*

    The response looks something like this:

    \[agent\]\[info\] Generating config \[agent\]\[info\] Gateway default/18b4e890fe7d: Adding
    ApiInstance default/products-users-api http://0.0.0.0:8080 \[agent\]\[info\] Gateway
    default/18b4e890fe7d: Adding Route: &{host: path:/api/products(/.\*) methods:
    headerConditions:\[\] profile:0xc0030529f0} => {Kind:Service Name:products-users-api-products
    Namespace:default} \[agent\]\[info\] Gateway default/18b4e890fe7d: Adding Route: &{host:
    path:/api/users(/.\*) methods: headerConditions:\[\] profile:0xc0030529f0} => {Kind:Service
    Name:products-users-api-users Namespace:default} \[agent\]\[info\] Gateway default/18b4e890fe7d:
    Adding Policy default/envoy.filters.http.router \[agent\]\[info\] Gateway default/18b4e890fe7d:
    Adding Service default/monitoring\_metrics http://0.0.0.0:9881 \[agent\]\[debug\] generating
    service monitoring\_metrics.default.svc hostname: 0.0.0.0 port: 9881 \[agent\]\[info\] Gateway
    default/18b4e890fe7d: Adding Service default/products-users-api-products
    https://<your products URL>:<your port>/ \[agent\]\[info\] Gateway default/18b4e890fe7d: Adding
    Service default/products-users-api-users https://<your users URL>:<your port>/
    \[agent\]\[debug\] generating service products-users-api-products.default.svc hostname:
    <your products URL> port: <your port> \[agent\]\[debug\] generating service
    products-users-api-users.default.svc hostname: <your users URL> port: <your port>
    \[agent\]\[info\] Writing envoy bootstrap configuration to /tmp/envoy.json \[envoy\]\[info\]
    cds: add 2 cluster(s), remove 2 cluster(s) \[envoy\]\[info\] cds: added/updated 1 cluster(s),
    skipped 1 unmodified cluster(s)

An API with multiple upstream services now runs behind Omni Gateway.

## Publish an API Running Behind Omni Gateway in a Docker Container

### Before You Begin

Before getting started, ensure that you have:

- Downloaded Omni Gateway. For more information, see [Downloading Omni Gateway](https://docs.mulesoft.com/gateway/1.13/install).

- Registered Omni Gateway and are running it in Local Mode. For more information, see
  [Register and Run in Local Mode](https://docs.mulesoft.com/gateway/1.13/local-reg-run).

- Your upstream service URLs.

### Publish an API

1.  Open a terminal and navigate to the directory that will contain your Omni Gateway configuration
    files. This directory was specified when you started Omni Gateway.

2.  Create a configuration file with a `.yaml` file extension:

    1.  Give the file a custom name.

    2.  Save the file.

3.  Copy and paste the following YAML snippet into the file, substituting configuration fields with
    your values.

    The snippet refers to the fictional `products-api` and `products-api-beta` services and a
    fictional `json-http` API instance. Specify your own API name and your own service details:

    apiVersion: gateway.mulesoft.com/v1alpha1 kind: ApiInstance metadata: name: json-http spec:
    address: http://0.0.0.0:8080/json ​
    ---

    ​ apiVersion: gateway.mulesoft.com/v1alpha1 kind: PolicyBinding metadata: name:
    weight-routing-test spec: targetRef: name: json-http policyRef: name: route-weighted config:
    routes: - weight: 75 # max\_value=100, min\_value=1 destinationPath: /posts/ destinationRef:
    name: products-api - weight: 25 destinationPath: /posts/ destinationRef: name: products-api-beta
    rules:
    - path: (.\*) methods: POST headers: x-test: true host: test.com
    - methods: GET|POST headers: x-test: true y-test: false host: test.com

4.  Save the file. The gateway automatically refreshes the configuration.

5.  View the Docker container logs, which look something like this:

    \[agent\]\[info\] Generating config \[agent\]\[info\] Gateway default/18b4e890fe7d: Adding
    ApiInstance default/products-users-api http://0.0.0.0:8080 \[agent\]\[info\] Gateway
    default/18b4e890fe7d: Adding Route: &{host: path:/api/products(/.\*) methods:
    headerConditions:\[\] profile:0xc0030529f0} => {Kind:Service Name:products-users-api-products
    Namespace:default} \[agent\]\[info\] Gateway default/18b4e890fe7d: Adding Route: &{host:
    path:/api/users(/.\*) methods: headerConditions:\[\] profile:0xc0030529f0} => {Kind:Service
    Name:products-users-api-users Namespace:default} \[agent\]\[info\] Gateway default/18b4e890fe7d:
    Adding Policy default/envoy.filters.http.router \[agent\]\[info\] Gateway default/18b4e890fe7d:
    Adding Service default/monitoring\_metrics http://0.0.0.0:9881 \[agent\]\[debug\] generating
    service monitoring\_metrics.default.svc hostname: 0.0.0.0 port: 9881 \[agent\]\[info\] Gateway
    default/18b4e890fe7d: Adding Service default/products-users-api-products
    https://<your products URL>:<your port>/ \[agent\]\[info\] Gateway default/18b4e890fe7d: Adding
    Service default/products-users-api-users https://<your users URL>:<your port>/
    \[agent\]\[debug\] generating service products-users-api-products.default.svc hostname:
    <your products URL> port: <your port> \[agent\]\[debug\] generating service
    products-users-api-users.default.svc hostname: <your users URL> port: <your port>
    \[agent\]\[info\] Writing envoy bootstrap configuration to /tmp/envoy.json \[envoy\]\[info\]
    cds: add 2 cluster(s), remove 2 cluster(s) \[envoy\]\[info\] cds: added/updated 1 cluster(s),
    skipped 1 unmodified cluster(s)

An API with multiple upstream services is now running behind Omni Gateway.

## Publish an API Running Behind Omni Gateway in a Kubernetes Cluster

### Before You Begin

Before getting started, ensure that you have:

- Downloaded Omni Gateway. For more information, see [Downloading Omni Gateway](https://docs.mulesoft.com/gateway/1.13/install).

- Registered Omni Gateway and are running it in Local Mode. For more information, see
  [Register and Run in Local Mode](https://docs.mulesoft.com/gateway/1.13/local-reg-run).

- Your upstream service URLs.

If you use [Kubernetes Service](https://kubernetes.io/docs/concepts/services-networking/service/) as
an upstream service or you apply a policy that makes requests to a Kubernetes Service, set the
following parameters in the `service` resource:

- `spec.ports[].protocol` to `TCP`

- `spec.ports[].name`

Your `spec.ports[].name` service must adhere to the `<protocol>[-<suffix>]` structure. `[-<suffix>]`
is optional, and the valid options for `<protocol>` are:

- HTTP

- H2

- HTTPS

### Publish an API

1.  Use the `kubectl apply` command to apply the following `.yaml` configuration file, substituting
    the configuration field values with your values.

    The snippet refers to the fictional `products-api` and `products-api-beta` services and a
    fictional `json-http` API instance. Specify your own API name and your own service details:

    apiVersion: gateway.mulesoft.com/v1alpha1 kind: ApiInstance metadata: name: json-http spec:
    address: http://0.0.0.0:8080/json ​
    ---

    ​ apiVersion: gateway.mulesoft.com/v1alpha1 kind: PolicyBinding metadata: name:
    weight-routing-test spec: targetRef: name: json-http policyRef: name: route-weighted config:
    routes: - weight: 75 # max\_value=100, min\_value=1 destinationPath: /posts/ destinationRef:
    name: products-api - weight: 25 destinationPath: /posts/ destinationRef: name: products-api-beta
    rules:
    - path: (.\*) methods: POST headers: x-test: true host: test.com
    - methods: GET|POST headers: x-test: true y-test: false host: test.com

2.  Enter the following command to view the pods logs and ensure that the API was created
    successfully:

kubectl logs -f <pod-name>
