Ingress中的property字段如何实现与社区client-go兼容?
使用场景
社区Ingress结构体中没有property属性,导致用户使用client-go调用创建ingress的api接口时,创建的Ingress中没有property属性。为了与社区的client-go兼容,CCE提供了如下解决方案。
解决方案
在使用client-go创建Ingress实例时,在annotation中做如下声明:
kubernetes.io/ingress.property: '[{"host":"test.com","path":"/test","matchmode":"STARTS_WITH"},{"host":"test.com","path":"/dw","matchmode":"EQUAL_TO"}]'
匹配规则:用户调用CCE的Kubernetes接口创建Ingress时,会试图匹配Ingress rules中的host和path两个字段,如果和annotation中的host和path一致,则会在这条path下面注入property属性,示例如下:
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: test
namespace: default
resourceVersion: '2904229'
generation: 1
labels:
isExternal: 'true'
zone: data
annotations:
kubernetes.io/ingress.class: cce
kubernetes.io/ingress.property: '[{"host":"test.com","path":"/test","matchmode":"STARTS_WITH"},{"Path":"/dw","MatchMode":"EQUAL_TO"}]'
spec:
rules:
- host: test.com
http:
paths:
- path: /ss
backend:
serviceName: zlh-test
servicePort: 80
- path: /dw
backend:
serviceName: zlh-test
servicePort: 80
转换后的格式如下:
kind: Ingress
apiVersion: extensions/v1beta1
metadata:
name: test
namespace: default
resourceVersion: '2904229'
generation: 1
labels:
isExternal: 'true'
zone: data
annotations:
kubernetes.io/ingress.class: cce
kubernetes.io/ingress.property: '[{"host":"test.com","path":"/ss","matchmode":"STARTS_WITH"},{"host":"","path":"/dw","matchmode":"EQUAL_TO"}]'
spec:
rules:
- host: test.com
http:
paths:
- path: /ss
backend:
serviceName: zlh-test
servicePort: 80
property:
ingress.beta.kubernetes.io/url-match-mode: STARTS_WITH
- path: /dw
backend:
serviceName: zlh-test
servicePort: 80
|
参数 |
参数类型 |
描述 |
|---|---|---|
|
host |
String |
域名配置。 若不配置,会自动匹配path。 |
|
path |
String |
匹配路径。 |
|
ingress.beta.kubernetes.io/url-match-mode |
String |
路由匹配策略,取值如下:
|