HostRule
The Operator is the primary user of the HostRule CRD. The CRD is used to express additional virtual host properties. The virtual host FQDN is matched from either the Kubernetes ingress or OpenShift route-based objects.
With
AKO
version 1.11.1, HostRule is transitioned to version v1beta1
. There are no schema changes between version v1alpha1
and v1beta1
. AKO
1.11.1 supports both versions v1alpha1
and v1beta1
. However, it is recommended to create new CRD objects in v1beta1
and transition the existing objects to this version.AKO
will deprecate v1alpha1
in the upcoming releases.A sample HostRule CRD looks as shown below:
apiVersion: ako.vmware.com/v1beta1 kind: HostRule metadata: name: my-host-rule namespace: red spec: virtualhost: fqdn: foo.region1.com fqdnType: Exact enableVirtualHost: true tls: sslKeyCertificate: name: avi-ssl-key-cert type: ref alternateCertificate: name: avi-ssl-key-cert2 type: ref sslProfile: avi-ssl-profile termination: edge gslb: fqdn: foo.com includeAliases: false httpPolicy: policySets: - avi-secure-policy-ref overwrite: false datascripts: - avi-datascript-redirect-app1 wafPolicy: avi-waf-policy applicationProfile: avi-app-ref networkSecurityPolicy: avi-network-security-policy-ref icapProfile: - avi-icap-ref analyticsProfile: avi-analytics-ref errorPageProfile: avi-errorpage-ref analyticsPolicy: fullClientLogs: enabled: true throttle: HIGH logAllHeaders: true tcpSettings: listeners: - port: 8081 - port: 6443 enableSSL: true loadBalancerIP: 10.10.10.1 aliases: - bar.com
Usage of HostRule
HostRule CRD can be created in a given namespace where the operator requires better control. This section explains the details and associated rules of using each field of the HostRule CRD.
- HostRule to Virtual Service Matching Using FQDN/FQDNType
- A given HostRule is applied to a virtual service if the virtual service hosts the FQDN mentioned in the HostRule CRD. This FQDN must exactly match the one the virtual service is hosting. However, to simplify the user experience and provide an easy way to apply a HostRule to an individual or multiple virtual services, theFQDNTypefield can be employed. It provides great flexibility when it comes to specifying the string in the FQDN field.With the FQDN Type, one of the three matching criteria listed below can be specified:
- Exact: Matches the string character by character to the virtual service FQDNs in an exact match fashion.
- Wildcard: Matches the string to multiple virtual service FQDNs and matches the FQDNs with the provided string as the suffix. The string must start with a * to qualify for wildcard matching.fqdn: *.alb.vmware.com fqdnType: Wildcard
- Contains: Matches the string to multiple virtual service FQDNs and matches the FQDNs with the provided string as a substring of any possible FQDNs programmed byAKO.fqdn: Shared-VS-L7-1 fqdnType: ContainsThefqdnTypefield defaults toExact.
- Enable/Disable Virtual Host
- HostRule CRD can be used to activate/deactivate corresponding virtual services created byAKOonVMware Avi Load Balancer. This removes any virtual host related configuration from the data plane (VMware Avi Load BalancerService Engines) in addition to deactivating traffic on the virtual host/FQDN.enableVirtualHost: falseThis property can be applied only for secure FQDNs and cannot be applied for insecure routes. The default value istrue.
- Express httppolicyset Object Refs
- HostRule CRD can be used to expresshttppolicysetreferences.Thehttppolicysetobjects must be pre-created in theAvi Load Balancer Controller.httpPolicy: policySets: - "avi-secure-policy-ref" overwrite: falseThehttppolicysetcurrently is only applicable for secure FQDNs and cannot be applied for insecure routes. The order of evaluation of thehttppolicysetrules is in the same order they appear in the CRD definition. The list ofhttppolicysetrules is always intepreted as anANDoperation.AKOcurrently useshttppolicysetobjects on the SNI virtual services to route traffic based on host/path matches. These rules are always at a lower index than thehttppolicysetobjects specified in the CRD object. If a user wants to overwrite allhttppolicysetobjects on an SNI virtual service with the ones specified in the HostRule CRD, theoverwriteflag can be set totrue. The default value foroverwriteisfalse.
- Express WAF Policy Object Refs
- HostRule CRD can be used to express WAF policy references. Create the WAF policy object in theAvi Load Balancer Controllerprior to the CRD creation as follows:wafPolicy: "avi-waf-policy"This property can be applied only for secure FQDNs and cannot be applied for insecure routes. WAF policies are useful when deep layer 7 packet filtering is required.
- Express Custom Application Profiles
- HostRule CRD can be used to express application profile references. Create the application profile reference in theAvi Load Balancer Controllerprior to the CRD creation. The application profile must be of TypeAPPLICATION_PROFILE_TYPE_HTTP.applicationProfile: "my-app-ref"This property can be applied only for secure FQDNs and cannot be applied for insecure routes. The application profiles can be used for various HTTP/HTTP2 protocol settings.
- Express Custom ICAP profile
- HostRule CRD can be used to express a single ICAP profile reference per host. The ICAP profile reference must have been created in theAvi Load Balancer Controllerprior to this CRD creation.icapProfile: - avi-icap-refThis property can be applied for both secure and insecure hosts through EVH parent and child virtual services, SNI child Virtual Services, and dedicated virtual services. The ICAP Profile can be used for transporting HTTP traffic to 3rd party services for processes such as content sanitization and antivirus scanning. For more information, see Internet Content Adaptation Protocol topic in theVMware Avi Load BalancerConfiguration Guide
- Express Custom Analytics Profiles
- HostRule CRD is used to express analytics profile references.Create the analytics profile reference in theAvi Load Balancer Controllerprior to this CRD creation.analyticsProfile: avi-analytics-ref`This property can be applied only for secure FQDNs and cannot be applied for insecure routes. The analytics profiles can be used for various Network/HTTP/Health score analytics settings, log processing, and so on.
- Express Custom Error Page Profiles
- HostRule CRD can be used to express error page profile references.Create the error page profile reference in theAvi Load Balancer Controllerprior to this CRD creation.errorPageProfile: avi-errorpage-refThis property can be applied only for secure FQDNs and cannot be applied for insecure routes. The error page profiles can be used to send a custom error page to the client generated by the proxy.
- Express DataScripts
- HostRule CRD can be used to express error DataScript references.Create the DataScript references in theAvi Load Balancer Controllerprior to this CRD creation.datascripts: - avi-datascript-redirect-app1This property can be applied only for secure FQDNs and cannot be applied for insecure routes. The DataScripts can be used to apply custom scripts to data traffic. The order of evaluation of the DataScripts is in the same order they appear in the CRD definition.
- Express TLS Configuration
- For theAKOto control the TLS termination from a privileged namespace, the HostRule CRD can be created in such a namespace.tls: sslKeyCertificate: name: avi-ssl-key-cert type: ref alternateCertificate: name: avi-ssl-key-cert2 type: ref sslProfile: avi-ssl-profile termination: edgeHere,namerefers to anVMware Avi Load Balancerobject with theTypeasref. Alternatively, we also support a kubernetesSecretto be specified where thesslkeyandcertificateobject is created byAKOusing theSecret.tls: sslKeyCertificate: name: k8s-app-secret type: secret termination: edgeCurrently, only Edge is supported as the type of termination.AnalternateCertificateoption is provided if the application needs to be configured to provide multiple server certificates, typically when trying to configure both RSA and ECC signed certificates. TheAvi Load Balancer Controllerallows a virtual service to be configured with two certificates at a time, one each of RSA and ECC. This enables the Controller to negotiate the optimal algorithm or cipher with the client. If the client supports ECC, the ECC algorithm is preferred, and RSA is used as a fallback in cases where the clients do not support ECC.ThesslProfile, additionally, can be used to determine the set of SSL versions and ciphers to accept for SSL/TLS terminated connections. If thesslProfileis not defined,AKOdefaults to thesslProfileSystem-Standard-PFSdefined inVMware Avi Load Balancer.
- Configure GSLB FQDN
- A GSLB FQDN can be specified within the HostRule CRD. This is only used ifAKOis used withAMKOand not otherwise.gslb: fqdn: foo.comThis additional FQDN inherits all the properties of the root FQDN specified under the virtualHost section. Use this flag if you would want traffic with a GSLB FQDN to get routed to a site local FQDN. For example, in the above CRD, the client request from a GSLB DNS will arrive with the host header asfoo.comto the VIP hostingfoo.region1.cominregion1. This CRD property would ensure that the request is routed appropriately to the backend service offoo.region1.com.In SNI mode, if a GSLB FQDN is specified for an insecure hostname (defined in an Ingress or OpenShift route) or a secure hostname in an OpenShift route with theinsecureEdgeTerminationPolicyset toAllow, the GSLB FQDN can only be defined for a limited number of such hostnames per shared parent virtual service. This is because specifying a GSLB FQDN adds one httppolicyset to the parent-shared virtual service for each hostname in the above category. However, there is a limitation on the number of httppolicysets that can be associated with a virtual service, depending on the license. For example, an Enterprise license supports a limit of sixteen (16). Therefore, if a SMALL shard size is used in theAKOconfiguration andAKOcreates only one shared parent virtual service, the GSLB FQDN will be configured for the first sixteen hostnames processed in the above category.This knob is currently supported only with the SNI model and not with Enhanced Virtual Hosting model. TheincludeAliasesis used byAMKO. Whenever a GSLB FQDN is provided, and theuseCustomGlobalFqdnis set totrueinAMKO, a GSLB Service is created for the GSLB FQDN instead of the local FQDN(hostname). For more information, seeDeriving GslbService FQDNstopic in theGuide.Avi Multi-Cluster Kubernetes OperatorWhen this flag is set tofalse, the Domain Name of the GSLB Service is set to the GSLB FQDN. When this flag is set totruein addition to the GSLB FQDN,AMKOadds the FQDNs mentioned under aliases to domain names of the GSLB Service.
- Configure Aliases for FQDN
- The Aliases field adds the ability to have multiple FQDNs configured under a specific route/ingress for the child virtual service instead of creating the route/ingress multiple times.aliases: - bar.com - baz.comThis list of FQDNs inherits all the properties of the root FQDN specified under the virtualHost section. Traffic arrives with the host header asbar.comto the VIP hostingfoo.region1.comand this CRD property would ensure that the request is routed appropriately to the backend service offoo.region1.com.Aliases field must contain unique FQDNs and must not contain GSLB FQDN or the root FQDN. Users must ensure that thefqdnTypeis set asExactbefore setting this field.
- Express Custom Network Security Policy Object Ref
- HostRule CRD can be used to express network security policy object references. The network security policy object must be created in theAvi Load Balancer Controllerbefore this CRD creation. ThenetworkSecurityPolicysetting, in addition to any other parameters provided in the HostRule, is only applied to Parent virtual services and dedicated virtual services. ThenetworkSecurityPolicysetting does not have any effect on child virtual services.networkSecurityPolicy: avi-network-security-policy-ref
- This property is available only in HostRule v1beta1 schema definition.
- Since the HostRule CRD is unknown of the misconfigurations that may occur if it is applied to a Child virtual service during the creation process, the HostRule will still be accepted.AKOwill print a warning message regarding this.
- Configure Analytics Policy
- The HostRule CRD can be used to configure analytics policies such as enable/disable non-significant logs, throttle the number of non-significant logs per second on each SE, enable/disable logging of all headers, and, so on:analyticsPolicy: fullClientLogs: enabled: true throttle: HIGH logAllHeaders: trueThe throttle will be in effect only whenenabledis set totrue. The possible values of throttle areDISABLED (0),LOW (50),MEDIUM (30), and HIGH (10).AKOsets the duration of logging the non-significant logs to infinity by default.It is recommended to deactivate the non-significant logs when it is no longer required.
- Configure TCP Settings
- The TCP Settings section is responsible for configuring Parent virtual service specific parameters using the HostRule CRD. ThetcpSettingsblock, in addition to any other parameters provided in the HostRule, is only applied to Parent virtual services and dedicated virtual services.ThetcpSettingsblock does not have any effect on child VSes. To consume TCP setting configurations for parent virtual services, the HostRule must be matched to a Shared/Dedicated VS FQDN, using the existingfqdnfield in HostRule. When dedicated virtual services are created corresponding to a single application, shared virtual services host multiple application FQDNs. Therefore, to apply a HostRule to a dedicated VS, users can simply provide the application FQDN in the HostRulefqdnfield. For Shared virtual services, users can either provide theAKOprogrammed shared virtual service FQDN, or utilize thefqdnType: Containsparameter with the Shared virtual service name itself.fqdn: foo.com # dedicated VS fqdnType: Exact tcpSettings: listeners: - port: 6443 enableSSL: true fqdn: Shared-VS-L7-1.admin.avi.com # AKO configured Shared VS fqdn fqdnType: Exact tcpSettings: loadBalancerIP: 10.10.10.1 fqdn: Shared-VS-L7-1 # bound for clusterName--Shared-VS-L7-1 fqdnType: Contains tcpSettings: loadBalancerIP: 10.10.10.1Custom Ports: To overwrite the ports opened for the virtual services created byAKO, users can provide the port details under the listeners setting. The ports mentioned under this section overwrite the default open ports, 80 and 443 (SSL enabled). This is applicable only for Shared or Dedicated virtual services.tcpSettings: listeners: - port: 80 - port: 8081 - port: 6443 enableSSL: true
- At least one of the ports that are mentioned in the setting must have theenableSSLfield set totrue.
- IfenableHTTP2is set totrue, then the HTTP2 traffic will be supported from client to Service Engine.
L7 Static IP: TheloadBalancerIPfield can be used to provide a valid, preferred IPv4 address for L7 virtual services created for the Shared or Dedicated virtual service. The preferred IP must be part of the IPAM configured for the Cloud, and must not overlap with any other IP addresses already in use. When misconfigurations occur,AKOfails to configure the virtual service, appropriately throwing an ERROR log for the same.tcpSettings: loadBalancerIP: 10.10.10.199The HostRule CRD is not aware of the misconfigurations while it is being created and so, the HostRule will be accepted. - L7Rule
- TheL7rulefield can be used to specify the name of L7Rule CRD. It is used to modify select VS Properties which are not part of HostRule CRD.This property is available only in HostRule v1beta1 schema definition.
Enable Regular Expression in path
If any paths in a Kubernetes Ingress or OpenShift Route are regular expressions, the hostrule must be defined with the
useRegex
field. This field is optional.Based on whether a hostrule is defined with the
useRegex
field, AKO
will manage the ingress/route in the following ways.
- If a hostrule is defined with the useRegex field set toTruefor a given host, then all paths defined for that host, regardless of the Ingress/Route they are defined on, will be considered as case-insensitive regular expressions.Avi Load Balancerwill create rules for each path for regex pattern matching.fqdn: test-avi.vmware.com fqdnType: Exact useRegex: trueAvi Load Balancerwill always use the longest match approach to match the path in the incoming request URL against the available regex paths for the host.apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: test-ingress spec: rules: - host: test-avi.vmware.com http: paths: - backend: service: name: my-app-0 port: number: 80 path: /bar.* pathType: ImplementationSpecific - backend: service: name: my-app-1 port: number: 80 path: /bar/foo pathType: ImplementationSpecific tls: - hosts: - test-avi.vmware.com secretName: ingress-secretFor the above Ingress definition, if a hostrule is created with theuseRegexfield set to True, then:
- A request made to the URLhttps://test-avi.vmware.com/bar/foowill be routed to the backendmy-app-1.
- A request made to the URLhttps://test-avi.vmware.com/bar/bazwill be routed to the backendmy-app-0.
- If a hostrule is defined with theuseRegexfield set toFalse, or if no hostrule is defined for a host and the user specifies regular expression paths in the Ingress/Route for that host, thenAvi Load Balancerwill not consider the paths as regular expressions and create rules that match the whole path instead of regex pattern matching.
- This property is available only in the HostRule v1beta1 schema definition.
- TheuseRegexfield is not supported for insecure ingress/route whenAKOis running in SNI mode or SNI Dedicated mode.
- For secure SNI and secure SNI dedicated virtual services, pool creation inAvi Load Balancercan fail when regular expression paths are used and the hostrule is not defined withuseRegexset toTrue. This limitation is due toAKO's pool naming convention, which includes the path in the pool name, and some special characters are not allowed inAvi Load Balancer Controllerpool names. To overcome the above limitation for secure SNI and secure SNI dedicated virtual services, the user must always define a hostrule withuseRegexset toTruewhen regular expression paths are used in secure Ingress/Route. WithuseRegexset asTrue,AKOwill create the pool using an encoded name.
Express Application Root Redirect path
If the application root path (i.e., path
/
) for a given host, defined in Ingress or Route, is mapped to a different path on the backend and needs to be redirected, then set this field to the desired path in the hostrule to redirect the requests. This field is optional.The host and query strings in the redirect URI remain unchanged. The port in the redirect request is set to the front-end port specified in the ingress, and the redirect protocol is determined by the redirect port (HTTPS for ports 443 and 6443, and HTTP for all other ports).
fqdn: test-avi.vmware.com fqdnType: Exact applicationRootPath: /foo
If any other path (in addition to the application root path /) is specified for the host in the ingress/route,
Avi Load Balancer
will route requests to that path without any redirects. The path specified as the applicationRootPath
must not be used as a regular path in the ingress/route because it can lead to ambiguity when selecting the backend in Avi Load Balancer
.apiVersion: networking.k8s.io/v1 kind: Ingress metadata: name: test-ingress spec: rules: - host: test-avi.vmware.com http: paths: - backend: service: name: my-app-0 port: number: 80 path: /bar pathType: ImplementationSpecific - backend: service: name: my-app-1 port: number: 443 path: / pathType: Exact tls: - hosts: - test-avi.vmware.com secretName: ingress-secret
For the above Ingress definition, if a hostrule is created with the
applicationRootPath
set to /foo
, then:
- A request made to the URLhttps://test-avi.vmware.com/will first be redirected tohttps://test-avi.vmware.com:443/fooand then routed to the backendmy-app-1.
- A request made to the URLhttps://test-avi.vmware.com/barwill be routed to the backendmy-app-0.
- This property is available only in the HostRule v1beta1 schema definition.
- TheapplicationRootPathfield is not supported for insecure ingress/route whenAKOis running in SNI mode or SNI Dedicated mode.
- TheuseRegexandapplicationRootPathfields can be used together. That is,useRegexcan be set toTrue, andapplicationRootPathcan be specified within the same hostrule. Both properties will function as described in their respective sections.
Status Messages
The status messages are used to give instant feedback about the reference objects specified in the HostRule CRD.
Following are some of the sample status messages:
- Accepted HostRule Object:$ kubectl get hr NAME HOST STATUS AGE secure-waf-policy foo.avi.internal Accepted 3d3hA HostRule is accepted only when all the reference objects specified inside it exist in theAvi Load Balancer Controller.
- A Rejected HostRule Object:$ kubectl get hr NAME HOST STATUS AGE secure-waf-policy-alt foo.avi.internal Rejected 2d23hThe reason for rejection can be obtained from the status:status: error: duplicate fqdn foo.avi.internal found in default/secure-waf-policy-alt status: Rejected
Caveats
- Converting Insecure FQDNs to Secure
- The HostRule CRD can be used to convert an insecure host FQDN to a secure one. This is done by specifying a TLS section in the CRD object. ThesslKeyCertificateis provided for the FQDN, will override allsslkeyandcertificatesgenerated for the FQDN. This is useful if:
- The operator wants to convert an insecure ingress FQDN to secure.
- The operator wants to override any existing secrets for a given host FQDN and define TLS termination semantics.
- Certificate Precedence
- If the ingress object specifies a secret for SNI termination and the HostRule CRD also specifies asslKeyCertificatefor the samevirtualhost, thesslkeycertificatein the HostRule CRD will take precedence over the Secret object associated with the Ingress.
- HostRule Deletion
- If a HostRule is deleted, all the settings for the FQDNs are withdrawn from theAvi Load Balancer Controller.
- HostRule Admission
- A HostRule CRD is only admitted if all the objects referenced in it, exist in theAvi Load Balancer Controller. If after admission, the object references are deleted out-of-band, theAKOdoes not re-validate the associated HostRule CRD objects. The user needs to manually edit or delete the object for new changes to take effect.
- Duplicate FQDN rules
- Two HostRule CRDs cannot be used for the same FQDN information across namespaces. IfAKOfinds a duplicate FQDN in more than one HostRules,AKOhonors the first HostRule that gets created and rejects the others. WhenAKOreboots occur, the CRD that gets honored might not be the same as the one honored earlier.