Skip to content

Commit 67d60fe

Browse files
docs: add external service discovery tutorial (#1535)
1 parent f162f71 commit 67d60fe

2 files changed

Lines changed: 93 additions & 1 deletion

File tree

docs/en/latest/config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
"tutorials/manage-ingress-certificates-with-cert-manager",
3636
"tutorials/enable-authentication-and-restriction",
3737
"tutorials/how-to-access-Apache-APISIX-Prometheus-Metrics-on-k8s",
38-
"tutorials/how-to-use-go-plugin-runner-in-apisix-ingress"
38+
"tutorials/how-to-use-go-plugin-runner-in-apisix-ingress",
39+
"tutorials/external-service",
40+
"tutorials/external-service-discovery"
3941
]
4042
},
4143
{
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: Using External Services Discovery In ApisixUpstream
3+
---
4+
5+
<!--
6+
#
7+
# Licensed to the Apache Software Foundation (ASF) under one or more
8+
# contributor license agreements. See the NOTICE file distributed with
9+
# this work for additional information regarding copyright ownership.
10+
# The ASF licenses this file to You under the Apache License, Version 2.0
11+
# (the "License"); you may not use this file except in compliance with
12+
# the License. You may obtain a copy of the License at
13+
#
14+
# http://www.apache.org/licenses/LICENSE-2.0
15+
#
16+
# Unless required by applicable law or agreed to in writing, software
17+
# distributed under the License is distributed on an "AS IS" BASIS,
18+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
# See the License for the specific language governing permissions and
20+
# limitations under the License.
21+
#
22+
-->
23+
24+
In this tutorial, we will introduce how to configure external services discovery in the ApisixUpstream resources.
25+
26+
APISIX already supports various service discovery components, such as DNS, consul, nacos, etc.
27+
Please see [Integration service discovery registry](https://apisix.apache.org/docs/apisix/discovery/) for details.
28+
29+
## Prerequisites
30+
31+
- An available Kubernetes cluster
32+
- An available APISIX and APISIX Ingress Controller installation
33+
34+
We assume that your APISIX is installed in the `apisix` namespace.
35+
36+
## Introduction
37+
38+
Integration of APISIX Ingress with service discovery components is configured through the ApisixUpstream resource.
39+
In this case, we don't configure the `backends` field in the ApisixRoute resource.
40+
Instead, we will use the `upstreams` field to refer to an ApisixUpstream resources with the `discovery` field configured.
41+
42+
For example:
43+
44+
```yaml
45+
# httpbin-route.yaml
46+
apiVersion: apisix.apache.org/v2
47+
kind: ApisixRoute
48+
metadata:
49+
name: httpbin-route
50+
spec:
51+
http:
52+
- name: rule1
53+
match:
54+
hosts:
55+
- local.httpbin.org
56+
paths:
57+
- /*
58+
# backends: # We won't use the `backends` field
59+
# - serviceName: httpbin
60+
# servicePort: 80
61+
upstreams:
62+
- name: httpbin-upstream
63+
```
64+
65+
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.
66+
The referenced ApisixUpstream *MUST* have `discovery` field configured. For example:
67+
68+
```yaml
69+
# httpbin-upstream.yaml
70+
apiVersion: apisix.apache.org/v2
71+
kind: ApisixUpstream
72+
metadata:
73+
name: httpbin-upstream
74+
spec:
75+
discovery:
76+
type: dns
77+
serviceName: httpbin.default.svc.cluster.local
78+
```
79+
80+
In this yaml example, we configured `httpbin.default.svc.cluster.local` as the backend.
81+
The type of service discovery needs to be pre-configured in APISIX. For example:
82+
83+
```yaml
84+
discovery:
85+
dns:
86+
servers:
87+
- "10.96.0.10:53" # default kube-dns cluster IP.
88+
```
89+
90+
After applying the above configuration, we can try to access `httpbin.default.svc.cluster.local` directly through APISIX.

0 commit comments

Comments
 (0)