---
schema_version: "1"
id: cf1c40e28cc451e00b0c931d69c218ed14b45b1a1a6f66f97057839c175384ec
title: Publishing a Simple API Instance in Local Mode
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.12/flex-local-publish-simple-api.md
canonical_url: https://docs.mulesoft.com/gateway/1.12/flex-local-publish-simple-api
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 90f06fedc93242b1e3b9156ae427529f0fc1c8c2135846e9e88416a8be74cdef
description: MuleSoft Documentation Site
release: "1.12"
latest: false
---
---
product: Omni Gateway
version: 1.12
---

# Publishing a Simple API Instance in Local Mode

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

Publish a simple API running behind Flex Gateway in Local Mode, modifying YAML configuration data by
one of the following methods:

- Linux and Docker: `.yaml` files

- Kubernetes: `kubectl apply`

The following procedures demonstrate applying a simple YAML configuration for an unsecured API with
a single upstream service.

<table><colgroup><col> <col> <col></colgroup><tbody><tr><td><div><div><p><span><a href="#linux"><img src="https://docs.mulesoft.com/gateway/1.12/_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.12/_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.12/_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 Flex Gateway on Linux</a></p></div></div></td><td><div><div><p><a href="#docker">Publish an API Running Behind Flex Gateway in a Docker Container</a></p></div></div></td><td><div><div><p><a href="#kubernetes">Publish an API Running Behind Flex Gateway in a Kubernetes Cluster</a></p></div></div></td></tr></tbody></table>

## Publish an API Running Behind Flex Gateway on Linux

### Before You Begin

Before getting started, ensure that you have:

- Flex Gateway installed and running in Local Mode. See [Downloading Flex Gateway](https://docs.mulesoft.com/gateway/1.12/flex-install) for
  more information about installing and running the gateway.

- Your upstream service URL. The following example refers to a fictional `orders-api` service, but
  you can specify your own API name in `metadata.name` and your service details in `spec.services`.

### 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 Flex 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 your values where
    indicated:

    apiVersion: gateway.mulesoft.com/v1alpha1 kind: ApiInstance metadata: name: orders-api spec:
    address: http://0.0.0.0:8080 services: orders: address: https://<your orders URL>:<your port>/
    routes: - rules: - path: /api/orders(/.\*)

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/animal-facts-api http://0.0.0.0:8080 \[agent\]\[info\] Gateway
    default/18b4e890fe7d: Adding Route: &{host: path:/api/orders(/.\*) methods:
    headerConditions:\[\] profile:0xc0030529f0} => {Kind:Service Name:orders-api-orders
    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/orders-api-orders
    https://<your orders URL>:<your port>/ \[agent\]\[debug\] generating service
    orders-api-orders.default.svc hostname: <your orders 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)

A simple API is now running behind Flex Gateway.

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

### Before You Begin

Before getting started, ensure that you have:

- Flex Gateway installed. See [Downloading Flex Gateway](https://docs.mulesoft.com/gateway/1.12/flex-install) for more information.

- Flex Gateway registered and running in Local Mode. See
  [Register and Run in Local Mode](https://docs.mulesoft.com/gateway/1.12/flex-local-reg-run) for more information.

- Your upstream service URL. The following example refers to a fictional `orders-api` service, but
  you can specify your own API name in `metadata.name` and your service details in `spec.services`.

### Publish an API

1.  Open a terminal and navigate to the directory that will contain your Flex Gateway configuration
    files. This directory was specified when you started Flex 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 your values where
    indicated:

    apiVersion: gateway.mulesoft.com/v1alpha1 kind: ApiInstance metadata: name: orders-api spec:
    address: http://0.0.0.0:8080 services: orders: address: https://<your orders URL>:<your port>/
    routes: - rules: - path: /api/orders(/.\*)

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/animal-facts-api http://0.0.0.0:8080 \[agent\]\[info\] Gateway
    default/18b4e890fe7d: Adding Route: &{host: path:/api/orders(/.\*) methods:
    headerConditions:\[\] profile:0xc0030529f0} => {Kind:Service Name:orders-api-orders
    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/orders-api-orders
    https://<your orders URL>:<your port>/ \[agent\]\[debug\] generating service
    orders-api-orders.default.svc hostname: <your orders 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)

A simple API is now running behind Flex Gateway.

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

### Before You Begin

Before getting started, ensure that you have:

- Flex Gateway installed and running in Local Mode. See [Downloading Flex Gateway](https://docs.mulesoft.com/gateway/1.12/flex-install) for
  more information about installing and running the gateway.

- A Docker image stored in a Docker repository. The following example refers to a fictional
  `orders-api` application, but you can specify your own Docker repository and Docker image in the
  `Deployment` configuration resource (in `spec.spec.image`).

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.  Using the `kubectl apply` command, install a Docker image named "orders-api" from a given
    repository.

    The following YAML snippet defines two configuration resources: `Service`, and `Deployment`. The
    `Service` resource declares the `orders-api` service. The `Deployment` resource declares the
    desired deployment state by specifying information such as the number of replicas to create, and
    the Docker image to sideload.

    cat <<EOF | kubectl apply -f -
    ---

    apiVersion: v1 kind: Service metadata: name: orders-api labels: app: orders-api service:
    orders-api spec: ports:
    - name: http port: 80 targetPort: http selector: app: orders-api

    ***

    apiVersion: apps/v1 kind: Deployment metadata: name: orders-api spec: replicas: 1 selector:
    matchLabels: app: orders-api version: v1 template: metadata: labels: app: orders-api version: v1
    spec: containers: - image: <repository>/<dockerfile> imagePullPolicy: IfNotPresent name:
    orders-api ports: - name: http containerPort: 3000 resources: limits: cpu: 100m memory: 64Mi EOF

2.  Again using `kubectl apply`, create the ingress to route traffic.

    The following YAML example defines one configuration resource: `Ingress`.

    cat <<EOF | kubectl apply -f -
    ---

    apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: orders-api spec:
    ingressClassName: ingress-http.gateway rules:
    - http: paths:
      - path: /api/orders(/.\*) pathType: ImplementationSpecific backend: service: name: orders-api
        port: number: 80 EOF

A simple API is now running behind Flex Gateway.
