---
title: "How to Proxy External Services in Apache APISIX Ingress Controller - API7.ai"
description: "The methods of proxying external services in APISIX Ingress Controller are introduced."
url: "https://api7.ai/blog/proxy-services-in-apisix-ingress-controller"
---

[Blog](https://api7.ai/blog)

[Products](https://api7.ai/category/products)[Technology](https://api7.ai/category/technology)[Ecosystem](https://api7.ai/category/ecosystem)[Case Study](https://api7.ai/category/usercase)[Team & Community](https://api7.ai/category/community)

Search

⌘ + K

[Blog](https://api7.ai/blog)

Products

# How to Proxy External Services in Apache APISIX Ingress Controller

Yeqi Peng

January 13, 2023

[Products](https://api7.ai/category/products)

In this tutorial, we will introduce how to configure external services in ApisixUpstream resources.

This is useful when your service depends on a third-party service or a service from another K8s cluster. It also provides a way to manage your ApisixRoute with shared ExternalName services, without modifying a large number of ApisixRoutes when the referenced service name is updated.

## Prerequisites

- an available Kubernetes cluster
- an available APISIX and APISIX Ingress Controller installation

We assume that your APISIX is installed in the `apisix` namespace.

## Introduction

APISIX Ingress supports configuring external services as backends, both for K8s ExternalName services and direct domains.

In this case, we don't configure the `backends` field in the ApisixRoute resource. Instead, we will use the `upstreams` field to refer to an ApisixUpstream resource with the `externalNodes` field configured.

For example:

```
# httpbin-route.yaml
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: httpbin-route
spec:
  http:
  - name: rule1
    match:
      hosts:
      - local.httpbin.org
      paths:
      - /*
    # backends:  # We won't use the `backends` field
    #    - serviceName: httpbin
    #      servicePort: 80
    upstreams:
    - name: httpbin-upstream
```

This configuration tells the ingress controller not to resolve upstream hosts through the K8s services but to use the configuration defined in the referenced ApisixUpstream.

The referenced ApisixUpstream *MUST* have the `externalNodes` field configured. For example:

```
# httpbin-upstream.yaml
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
  name: httpbin-upstream
spec:
  externalNodes:
  - type: Domain
    name: httpbin.org
```

In this yaml example, we configured `httpbin.org` as the backend. The type `Domain` indicates that this is a third-party service, and any domain name is supported here.

If you want to use an external name service in the K8s cluster, the type should be `Service` and the name should be the service name. By configuring ApisixUpstream with the type `Service`, the ingress controller will automatically keep track of the content of the ExternalName service and its changes.

## External Domain Upstream

```
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: httpbin-route
spec:
  http:
  - name: rule1
    match:
      hosts:
      - local.httpbin.org
      paths:
      - /*
    upstreams:
    - name: httpbin-upstream
---
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
  name: httpbin-upstream
spec:
  externalNodes:
  - type: Domain
    name: httpbin.org
```

After applying the above configuration, we can try to access `httpbin.org` directly through APISIX.

```
kubectl exec -it -n apisix APISIX_POD_NAME -- curl -i -H "Host: local.httpbin.org" http://127.0.0.1:9080/get
```

If everything works, you will see the result like this:

```
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 321
Connection: keep-alive
Date: Thu, 15 Dec 2022 10:47:30 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/3.0.0

{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "local.httpbin.org",
    "User-Agent": "curl/7.29.0",
    "X-Amzn-Trace-Id": "Root=xxxxx",
    "X-Forwarded-Host": "local.httpbin.org"
  },
  "origin": "127.0.0.1, xxxxxxxxx",
  "url": "http://local.httpbin.org/get"
}
```

The header `Server: APISIX/3.0.0` indicates that the request has been sent from APISIX. And the response contains `X-Amzn-Trace-Id` indicating that the request was handled by the online httpbin service.

## External Name Service Upstream

Let's deploy a simple httpbin app in the namespace `test` as the backend for the external name service we will create later.

```
kubectl create ns test
kubectl -n test run httpbin --image-pull-policy IfNotPresent --image=kennethreitz/httpbin --port 80
kubectl -n test expose pod/httpbin --port 80
```

Then use the following configuration to create an ExternalName service in the `apisix` namespace.

```
apiVersion: v1
kind: Service
metadata:
  name: ext-httpbin
spec:
  type: ExternalName
  externalName: httpbin.test.svc
```

Now we can create an ExternalName service ApisixRoute and ApisixUpstream.

```
apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: ext-route
spec:
  http:
  - name: rule1
    match:
      hosts:
      - ext.httpbin.org
      paths:
      - /*
    upstreams:
    - name: ext-upstream
---
apiVersion: apisix.apache.org/v2
kind: ApisixUpstream
metadata:
  name: ext-upstream
spec:
  externalNodes:
  - type: Service
    name: ext-httpbin
```

Once the configurations are synced, try to access it with the following command.

The only argument that changes is the header we pass.

```
kubectl exec -it -n apisix APISIX_POD_NAME -- curl -i -H "Host: ext.httpbin.org" http://127.0.0.1:9080/get
```

The output should be like:

```
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 234
Connection: keep-alive
Date: Thu, 15 Dec 2022 10:54:21 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/3.0.0

{
  "args": {},
  "headers": {
    "Accept": "*/*",
    "Host": "ext.httpbin.org",
    "User-Agent": "curl/7.29.0",
    "X-Forwarded-Host": "ext.httpbin.org"
  },
  "origin": "127.0.0.1",
  "url": "http://ext.httpbin.org/get"
}
```

We can see the response is similar to the previous one, but some fields don't exist. That's because the request was sent to our local httpbin service rather than the online one.

## Domain In External Name Service

The external name service can also hold any domain name outside the K8s cluster.

Let's update the external service configuration we applied in the previous section.

```
apiVersion: v1
kind: Service
metadata:
  name: ext-httpbin
spec:
  type: ExternalName
  externalName: httpbin.org
```

Try reaccessing it, and the output should contain multiple `origin` and an `X-Amzn-Trace-Id` header, which means we are accessing the online `httpbin.org` service.

## Conclusion

In this tutorial, we extend the functional boundaries of the APISIX Ingress Controller by proxying requests to external services. It allows users to easily integrate third-party services, such as [authentication](https://api7.ai/blog/api-gateway-authentication) services or cross-cluster services.

For more information about API gateway, please visit our [blogs](https://api7.ai/blog) or [contact us](https://api7.ai/contact).

Tags:

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Kubernetes](https://api7.ai/tags/kubernetes)

Share article link

Share

Related Posts

[![How to Use Gateway API in APISIX Ingress Controller](https://static.api7.ai/uploads/2024/09/06/jTbR13pX_Gateway%20API.png)](https://api7.ai/blog/how-to-use-gateway-api-in-apisix-ingress-controller)

## [How to Use Gateway API in APISIX Ingress Controller](https://api7.ai/blog/how-to-use-gateway-api-in-apisix-ingress-controller)

[![Why Is APISIX Ingress Controller a Better Choice Compared with Traefik?](https://static.api7.ai/uploads/2024/09/06/ldwwEzTf_APISIX%20Ingress%20Controller-3.png)](https://api7.ai/blog/apisix-ingress-better-than-traefik)

## [Why Is APISIX Ingress Controller a Better Choice Compared with Traefik?](https://api7.ai/blog/apisix-ingress-better-than-traefik)

Table of Contents

- [Prerequisites](#prerequisites)
- [Introduction](#introduction)
- [External Domain Upstream](#external-domain-upstream)
- [External Name Service Upstream](#external-name-service-upstream)
- [Domain In External Name Service](#domain-in-external-name-service)
- [Conclusion](#conclusion)

## Related Posts

[![Why Is APISIX Ingress Controller a Better Choice than Emissary-ingress?](https://static.api7.ai/uploads/2024/12/24/CLpj341F_apisix-ingress-controller-vs-emissary.png)](https://api7.ai/blog/apisix-ingress-vs-emissary-ingress)

Products

March 17, 2023

#### [Why Is APISIX Ingress Controller a Better Choice than Emissary-ingress?](https://api7.ai/blog/apisix-ingress-vs-emissary-ingress)

This article compares the performance of APISIX Ingress Controller and Emissary-ingress from multiple dimensions such as scalability and service discovery integration.

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Kubernetes](https://api7.ai/tags/kubernetes)

[Emissary-Ingress](https://api7.ai/tags/emissary-ingress)

[![APISIX Ingress Controller Integrates with Service Discovery](https://static.api7.ai/uploads/2024/12/25/yzN9mzLr_apisix-ingress-controller-service-discovery.png)](https://api7.ai/blog/apisix-ingress-integrates-with-service-discovery)

Products

January 13, 2023

#### [APISIX Ingress Controller Integrates with Service Discovery](https://api7.ai/blog/apisix-ingress-integrates-with-service-discovery)

APISIX Ingress Controller integrates with service discovery to reduce deployment costs for microservices.

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Kubernetes](https://api7.ai/tags/kubernetes)

[Service Discovery](https://api7.ai/tags/service-discovery)

[![Why Is APISIX Ingress Controller Better than NGINX Ingress Controller?](https://static.api7.ai/2023/01/05/63b6900e1d793.png)](https://api7.ai/blog/apisix-ingress-vs-ingress-nginx)

Products

December 6, 2022

#### [Why Is APISIX Ingress Controller Better than NGINX Ingress Controller?](https://api7.ai/blog/apisix-ingress-vs-ingress-nginx)

This article mainly compares the basic functionalities of APISIX Ingress and Ingress NGINX. APISIX Ingress is better than Ingress NGINX in terms of scalability, extensibility, and functionality.

[APISIX Ingress Controller](https://api7.ai/tags/apisix-ingress-controller)

[Kubernetes](https://api7.ai/tags/kubernetes)

[Traefik](https://api7.ai/tags/traefik)
