How Can I Achieve Compatibility Between Ingress's property and Kubernetes client-go?
Scenario
The Kubernetes ingress structure does not contain the property attribute. Therefore, the ingress created by client-go through API calling does not contain the property attribute. CCE provides a solution to ensure compatibility with the Kubernetes client-go.
Solution
When using client-go to create an ingress instance, make the following declaration in annotation:
kubernetes.io/ingress.property: '[{"host":"test.com","path":"/test","matchmode":"STARTS_WITH"},{"host":"test.com","path":"/dw","matchmode":"EQUAL_TO"}]' Matching rule: When a user calls the Kubernetes interface of CCE to create an ingress instance, CCE attempts to match the host and path fields in ingress rules. If the host and path fields in ingress rules are the same as those in annotation, CCE injects the property attribute to the path. The following is an example:
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 The format after conversion is as follows:
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 | Parameter | Type | Description |
|---|---|---|
| host | String | Domain name configuration. If this parameter is not set, path is automatically matched. |
| path | String | Matching path. |
| ingress.beta.kubernetes.io/url-match-mode | String | Route matching policy. The values are as follows:
|
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.