Configure Ingress resources to define routes for accessing Services in Kubernetes cluster from outside the cluster. For more information about Ingress, please refer to Ingress .
Refer to ingress.yaml when configuring Ingress resources in yaml files.
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: simple-ingress
spec:
rules:
- host: whoami.com
http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: whoami
port:
number: 80
Above example defines a Ingress resource, and
-
sets
kubernetes.io/ingress.class
tobfe
, means this Ingress will be handled by BFE Ingress Controller -
defines a simple route rule. A request will be forwarded to port 80 of Service
whoami
, if it matches both below conditions:- hostname is
whoami.com
- path has prefix
/testpath
- hostname is
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: complex-ingress
namespace: my-namespace
annotations:
bfe.ingress.kubernetes.io/loadbalance: '{"foo": {"sub-foo1":80, "sub-foo2":20}}'
bfe.ingress.kubernetes.io/router.cookie: "Session: 123"
bfe.ingress.kubernetes.io/router.header: "Content-Language: zh-cn"
spec:
tls:
- hosts:
- foo.com
secretName: secret-foo-com
rules:
- host: foo.com
http:
paths:
- path: /foo
pathType: Prefix
backend:
service:
name: foo
port:
number: 80
- path: /bar
pathType: Exact
backend:
service:
name: bar
port:
number: 80
Above Ingress resource defines 2 advanced route rules, and configure TLS certificate for foo.com
. Rule options supported by BFE are defined with annotations.
-
Route rule 1:a request will be forwarded to port 80 of service
foo
, if it matches all below conditions. Servicefoo
is composed of two Services:sub-foo1
andsub-foo2
, serving 80% and 20% of total requests tofoo
. See Load balancing between Services.- hostname is
foo.com
- path has prefix
/foo
- value of a Cookie named
Session
is123
- value of a Header named
Content-Language
iszh-cn
- hostname is
-
Route rule 2:a request will be forwarded to port 80 of service
bar
, if it matches all below conditions.- hostname is
foo.com
- path has prefix
/bar
- value of a cookie named
Session
is123
- value of a header named
Content-Language
iszh-cn
- hostname is
Specified by host
in a rule
BFE Ingress Controller support hostname conditions defined by Kubernetes.
Specified by path
and pathType
in a rule
BFE Ingress Controller support below pathType:
- Prefix: prefix match.
- Exact: exact match
- ImplementationSpecific: default,implemented by BFE Ingress Controller as prefix match
BFE Ingress Controller supports advanced conditions by configuring annotation
.
Advanced conditions are shared in an Ingress resource. So all the rules in the same Ingress resource will be restrained by advanced conditions, if configured.
Currently, BFE Ingress Controller supports two types of advanced condition: cookie and header.
Format:
bfe.ingress.kubernetes.io/router.cookie: "key: value"
Explanation:
Requests containing a cookie with name=key
and value=value
are considered as matching this condition.
Format:
bfe.ingress.kubernetes.io/router.header: "key: value"
Explanation:
Requests containing a header with name=key
and value=value
are considered match this condition.
-
In an Ingress resource, for each advanced condition type, no more than one
Annotation
can be configured. -
If more than one
Annotation
s of the same advanced condition type are configured in the same Ingress resource, the last one takes effect.# example annotation: bfe.ingress.kubernetes.io/router.header: "key1: value1" # not take effect bfe.ingress.kubernetes.io/router.header: "key2: value2" # takes effect
BFE Ingress Controller supports user to configure ingress class in two ways:
Set kubernetes.io/ingress.class
in annotations of Ingress. Default value is bfe
annotations:
kubernetes.io/ingress.class: bfe
the format of set IngressClass in k8s are varies from the versions of K8S.
For k8s versions from 1.19
apiVersion: networking.k8s.io/v1
metadata:
name: external-lb
labels:
app.kubernetes.io/component: controller
annotations:
ingressclass.kubernetes.io/is-default-class: 'true'
spec:
controller: bfe-networks.com/ingress-controller
For K8S versions from 1.14 to 1.18, set controller to bfe-networks.com/ingress-controller
in IngressClass of K8S Cluster. Example:
apiVersion: networking.k8s.io/v1beta1
kind: IngressClass
metadata:
name: external-lb
controller: bfe-networks.com/ingress-controller
Then set ingressClassName
to external-lb
in Ingress:
apiVersion: "networking.k8s.io/v1beta1"
kind: "Ingress"
metadata:
name: "example-ingress"
spec:
ingressClassName: "external-lb"
...
For information about IngressClass, refer to IngressClass