文档简介:
操作场景
前提条件
操作步骤
安装 Traefik
helm repo add traefik https://helm.traefik.io/traefik
providers:kubernetesIngress:publishedService:enabled: true # 让 Ingress 的外部 IP 地址状态显示为 Traefik 的 LB IP 地址additionalArguments:- "--providers.kubernetesingress.ingressclass=traefik" # 指定 ingress class 名称- "--log.level=DEBUG"service:annotations:service.cloud.tencent.com/direct-access: "true" # 网关类的应用建议使用 LB 直通 Pod (绕过 NodePort)。
若使用 VPC-CNI 与 Global Router 两种网络模式混用,用此注解来显示声明 LB 直绑 Pod (绕过 NodePort);
若创建集群时就选的 VPC-CNI 网络模式,则不需要显示声明 (默认 LB 直通 Pod)。
详情请参见官方文档 https://cloud.tencent.com/document/product/457/48793
service.kubernetes.io/tke-existed-lbid: lb-lb57hvgl # 用此注解绑定提前创建好的 LB,
使得即便 Traefik 日后重建,也能保证流量入口不变。若不指定此注解,默认自动创建新的 LB。
详情请参见官方文档 https://cloud.tencent.com/document/product/457/45491
ports:web:expose: trueexposedPort: 80 # 对外的 HTTP 端口号,使用标准端口号在国内需备案websecure:expose: trueexposedPort: 443 # 对外的 HTTPS 端口号,使用标准端口号在国内需备案deployment:enabled: truereplicas: 1podAnnotations:tke.cloud.tencent.com/networks: "tke-route-eni" # 在 VPC-CNI 与 Global Router
两种网络模式混用的情况下,显示声明 Pod 要使用弹性网卡,与以下 eni-ip 的 request 与 limit 一起配合使用
resources:requests:tke.cloud.tencent.com/eni-ip: "1"limits:tke.cloud.tencent.com/eni-ip: "1"
kubectl create ns ingresshelm upgrade --install traefik -f values-traefik.yaml traefik/traefik
$ kubectl get service -n ingressNAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGEtraefik LoadBalancer 172.22.252.242 49.233.239.84 80:31650/TCP,443:32288/TCP 42h
使用 Ingress
Traefik 支持使用 Kubernetes 的 Ingress 资源作为动态配置,可直接在集群中创建 Ingress
资源用于对外暴露集群,需要加上指定的 Ingress class(安装 Traefik 时定义)。示例如下:
apiVersion: networking.k8s.io/v1beta1kind: Ingressmetadata:name: test-ingressannotations:kubernetes.io/ingress.class: traefik # 这里指定 ingress class 名称spec:rules:- host: traefik.demo.comhttp:paths:- path: /testbackend:serviceName: nginxservicePort: 80
使用 IngressRoute
apiVersion: traefik.containo.us/v1alpha1kind: IngressRoutemetadata:name: test-ingressroutespec:entryPoints:- webroutes:- match: Host(`traefik.demo.com`) && PathPrefix(`/test`)kind: Ruleservices:- name: nginxport: 80