Traefik 2.x has a big change compared to 1.7.x architecture. As shown in the architecture diagram above, the main function is to support TCP protocol and add the concept of Router.
Here we use Traefik 2.1 deployed in the kubernetes cluster. Business access is requested to traefik Ingress through haproxy. The following are some concepts involved in the construction process:
EntryPoints: Traefik’s network entry, defining the port where the request is accepted (regardless of http or tcp)
CRD: Extension of Kubernetes API
IngressRouter: forwards incoming requests to services that can handle requests. In addition, Middlewares can dynamically update requests before forwarding requests
Middlewares: dynamically process request parameters before the request reaches the service, such as header or forwarding rules, etc.
TraefikService: If this type is defined in CRD, IngressRouter can directly reference it. It is located between IngressRouter and the service, similar to the Maesh architecture. It is more suitable for more complex scenarios and can be omitted in general.
kubernetes configuration
Configure SSL certificate
Because the business service uses https, configure the SSL certificate here first:
apiVersion:traefik.containo.us/v1alpha1kind:TLSOptionmetadata:name:mytlsoptionnamespace:kube-systemspec:minversion: VersionTLS12 snistrict: true ciphersuites:- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 - TLS_RSA_WITH_AES_256_GCM_SHA384 - TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 - TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305 - T LS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 ```## CRD configurationIngressRoute, Middleware, TLSOption, IngressRouteTCP, and TraefikService are defined here, of which TraefikService is a new CRD added in version 2.1```yamlapiVersion:apiextensions.k8s.io/v1beta1kind:CustomResourceDefinitionmetadata:name:ingressroutes.traefik.containo.usspec:group:traefik.containo.usversion:v1alpha1names:kind:IngressRouteplural:ingressroutessingular:ingressroutescope:Namespaced---apiVersion:apiextensions.k8s.io/v1beta1kind:CustomResourceDefinitionmetadata:name:middlewares.traefik.containo.usspec:group:traefik.containo.usversion: v1alpha1 names: kind: Middleware plural: middlewares singular: middleware scope: Namespaced --- apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: tlsoptions.traefik.containo.us spec: group: traefik.containo.us version: v1alpha1 names: kind: TLSOption plural: tlsoptions singular: tlsoption scope: Namespaced --- apiVersion: apiextensions.k8s.io/v1beta1 kind: CustomResourceDefinition metadata: name: ingressroutetcps.traefik.containo.us spec: group: traefik.containo.us version: v1alpha1 names: kind:IngressRouteTCPplural:ingressroutetcpssingular:ingressroutetcpscope:Namespaced---apiVersion:apiextensions.k8s.io/v1beta1kind:CustomResourceDefinitionmetadata:name:traefikservices.traefik.containo.usspec:group:traefik.containo.usversion:v1alpha1names:kind:TraefikServiceplural:traefikservicessingular:traefikservicescope:Namespaced
TraefikService configuration
TraefikService is somewhat similar to Maesh in solving the calling logic between services, but Maesh relies on coredns; in addition, traefik service can also set the backend service weight and configure the traffic mirroring of the service.
Here we configure the traefik dashboard and rancher’s traefikservice type service. For other service configurations, you can refer to rancher’s traefik service here. The traefik service will forward requests to the kubernetes service type (in the previous section, we have created the rancher service through helm3). Here is just an example: