You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/05/12 08:36:55 UTC
[GitHub] [apisix-ingress-controller] tokers opened a new issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
tokers opened a new issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441
### Issue description
Currently, when we specify a Kubernetes service in `ApisixRoute` as the backend, we push all endpoints/pod to the target upstream in APISIX.
Sometimes a Kubernetes Service will contain multiple versions, for instance, some endpoints are `v1` while others are `v2`. Users might need to do some traffic management among these different releases. But this is not feasible in apisix-ingress-controller.
So a subset can be introduced when we select a Kubernetes Service as the backend, just like what istio [provides](https://istio.io/latest/docs/reference/config/networking/destination-rule/), for instance:
```yaml
apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: foo-route
spec:
http:
- name: foo-canary-route
priority: 1
match:
paths: ["/*"]
hosts: ["foo.org"]
exprs:
- subject:
scope: Cookie
name: sessionid
op: Equal
value: "33333"
backend:
serviceName: foo
servicePort: 80
subset:
name: v2-subset
labels:
version: v2
app: foo
- name: foo-stable-route
priority: 0
match:
paths: ["/*"]
hosts: ["foo.org"]
backend:
serviceName: foo
servicePort: 80
subset:
name: v1-subset
labels:
version: v1
app: foo
```
In the above example, requests which `sesssionid` in cookie is `33333` will hit the first route then forward to the subset of foo service where pods version is `v2`. For requests which don't meet the route conditions, will hit the second route then forward to the subset of foo service where pods version is `v1`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] vicaya commented on issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
vicaya commented on issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441#issuecomment-998993132
The current subsets doesn't support dynamic label based on route matching as my example illustrated, which means people need write extra code to maintain/sync the routes when the statefulset resizes.
> @vicaya This function is already supported, you can refer to this test case as an example
>
> https://github.com/apache/apisix-ingress-controller/blob/7b6237521b322c3662bece3ab701661f58bed347/test/e2e/features/subset.go#L123-L138
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tao12345666333 closed issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
tao12345666333 closed issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] vicaya commented on issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
vicaya commented on issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441#issuecomment-998422905
IMO, it's still cleaner to do subsets in route, as subsets are fundamentally part of routing policies that could be dynamically depend on the route match. One of the common use cases is to expose endpoints in statefulset pods via headless service, where each pod already has a distinct pod-name label. It'd be great if we could expose these endpoints concisely with a more expressive label selection for individual pods within a (headless) service. e.g.:
```yaml
apiVersion: apisix.apache.org/v2beta1
kind: ApisixRoute
metadata:
name: foo-route
spec:
http:
- name: route1
match:
exprs:
- name: context
subject:
scope: Path
op: RegexMatch
value: "^/prefix-([^/]+).*"
backends:
- serviceName: foo-service
servicePort: 9080
labels:
statefulset.kubernetes.io/pod-name: "${.match.context.value.1}"
```
Otherwise, we'd need to dynamically maintain individual routes when the statefulset resizes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tao12345666333 commented on issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441#issuecomment-998480439
@vicaya SGTM. This is a useful scene.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] vicaya edited a comment on issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
vicaya edited a comment on issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441#issuecomment-998993132
The current subsets doesn't support dynamic label based on route matching as my example illustrated, which means people need write extra code to maintain/sync the routes when the statefulset resizes.
Maybe I should create a new feature request for this?
> @vicaya This function is already supported, you can refer to this test case as an example
>
> https://github.com/apache/apisix-ingress-controller/blob/7b6237521b322c3662bece3ab701661f58bed347/test/e2e/features/subset.go#L123-L138
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tao12345666333 commented on issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
tao12345666333 commented on issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441#issuecomment-998524760
@vicaya This function is already supported, you can refer to this test case as an example
https://github.com/apache/apisix-ingress-controller/blob/7b6237521b322c3662bece3ab701661f58bed347/test/e2e/features/subset.go#L123-L138
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] tokers commented on issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
tokers commented on issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441#issuecomment-846400865
> ### Issue description
> Currently, when we specify a Kubernetes service in `ApisixRoute` as the backend, we push all endpoints/pod to the target upstream in APISIX.
>
> Sometimes a Kubernetes Service will contain multiple versions, for instance, some endpoints are `v1` while others are `v2`. Users might need to do some traffic management among these different releases. But this is not feasible in apisix-ingress-controller.
>
> So a subset can be introduced when we select a Kubernetes Service as the backend, just like what istio [provides](https://istio.io/latest/docs/reference/config/networking/destination-rule/), for instance:
>
> ```yaml
> apiVersion: apisix.apache.org/v2alpha1
> kind: ApisixRoute
> metadata:
> name: foo-route
> spec:
> http:
> - name: foo-canary-route
> priority: 1
> match:
> paths: ["/*"]
> hosts: ["foo.org"]
> exprs:
> - subject:
> scope: Cookie
> name: sessionid
> op: Equal
> value: "33333"
> backend:
> serviceName: foo
> servicePort: 80
> subset:
> name: v2-subset
> labels:
> version: v2
> app: foo
> - name: foo-stable-route
> priority: 0
> match:
> paths: ["/*"]
> hosts: ["foo.org"]
> backend:
> serviceName: foo
> servicePort: 80
> subset:
> name: v1-subset
> labels:
> version: v1
> app: foo
> ```
>
> In the above example, requests which `sesssionid` in cookie is `33333` will hit the first route then forward to the subset of foo service where pods version is `v2`. For requests which don't meet the route conditions, will hit the second route then forward to the subset of foo service where pods version is `v1`.
After deep consideration, I found it's not a good idea to define subset in ApisixRoute directly, the following problem has to be addressed in such a case:
* How to name the Apisix Upstream?
We cannot just use service namespace + service name + service port to name an upstream, as there might exist multiple subsets for the service, we may need to use subset name as the extra component to compose the upstream name. If so, we'll meet another problem, how to find this upstream when endpoints for this service change? we know nothing in the endpoints controller loop. It will be tough to traverse all ApisixRoute objects or mapping the reference relationship between ApisixRoute and Service.
The definition and reference of the subset should be separated. A good way is define subset to ApisixUpstream and use it in ApisixRoute (just by its name).
```yaml
apiVersion: apisix.apache.org/v1
kind: ApisixUpstream
metadata:
name: foo-service
spec:
subsets:
- name: group-v1
labels:
version: v1
app: foo
env: prod
- name: group-v2
labels:
version: v2
app: foo
env: prod
---
apiVersion: apisix.apache.org/v2alpha1
kind: ApisixRoute
metadata:
name: foo-route
spec:
http:
- name: route1
match:
paths: ["/*"]
backends:
- serviceName: foo-service
servicePort: 9080
subset: v1
- serviceName: foo-service
servicePort: 9080
subset: v2
```
By this design, we name an upstream with the subset component (if any), and when endpoints change, subset array still can be found since the name of ApisixUpstream is named to the Service, i.e. the endpoint.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-ingress-controller] gxthrj commented on issue #441: Support to use a subset of Kubernetes Service as the backend of ApisixRoute
Posted by GitBox <gi...@apache.org>.
gxthrj commented on issue #441:
URL: https://github.com/apache/apisix-ingress-controller/issues/441#issuecomment-839775732
I like this feature, it will be useful.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org