kubernetes-handbook/concepts/traefik-ingress-controller.md

1.7 KiB
Raw Blame History

Traefik Ingress Controller

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

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: traefik-ingress
  namespace: default
spec:
  rules:
  - host: traefik.nginx.io
    http:
      paths:
      - path: /
        backend:
          serviceName: my-nginx
          servicePort: 80

Traefik Ingress Controller

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

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: td-ingress
  namespace: default
  annotations:
    traefik.frontend.rule.type: PathPrefixStrip
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: "*.jimmysong.io"
    http:
      paths:
      - path: /docGenerate
        backend:
          serviceName: td-sdmk-docgenerate
          servicePort: 80

注意annotation的配置:

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

在nginx中增加配置

upstream docGenerate {
       server 172.20.0.119:80;
       keepalive 200;
    }

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

参考