• Traefik Ingress Controller
    • Traefik Ingress Controller

    Traefik Ingress Controller

    我们在前面部署了 Traefik 作为Ingress Controller,如果集群外部直接访问Kubenretes内部服务的话,可以直接创建Ingress如下所示:

    1. apiVersion: extensions/v1beta1
    2. kind: Ingress
    3. metadata:
    4. name: traefik-ingress
    5. namespace: default
    6. spec:
    7. rules:
    8. - host: traefik.nginx.io
    9. http:
    10. paths:
    11. - path: /
    12. backend:
    13. serviceName: my-nginx
    14. servicePort: 80

    Traefik Ingress Controller

    当我们处于迁移应用到kuberentes上的阶段时,可能有部分服务实例不在kubernetes上,服务的路由使用nginx配置,这时处于nginx和ingress共存的状态。参考下面的配置:

    1. apiVersion: extensions/v1beta1
    2. kind: Ingress
    3. metadata:
    4. name: td-ingress
    5. namespace: default
    6. annotations:
    7. traefik.frontend.rule.type: PathPrefixStrip
    8. kubernetes.io/ingress.class: traefik
    9. spec:
    10. rules:
    11. - host: "*.jimmysong.io"
    12. http:
    13. paths:
    14. - path: /docGenerate
    15. backend:
    16. serviceName: td-sdmk-docgenerate
    17. servicePort: 80

    注意annotation的配置:

    • traefik.frontend.rule.type: PathPrefixStrip:表示将截掉URL中的path
    • kubernetes.io/ingress.class:表示使用的ingress类型

    在nginx中增加配置:

    1. upstream docGenerate {
    2. server 172.20.0.119:80;
    3. keepalive 200;
    4. }

    172.20.0.119是我们的边缘节点的VIP,见边缘节点配置。