如何让Traefik兼容Microk8s

How to make Traefik compatible with Microk8s

我在 Minikube 上有一个工作设置,使用 Traefik 作为入口控制器。我尝试在 Microk8s 上使用该设置,但 Traefik 无法工作,虽然我可以看到 Traefik 仪表板,它说一切正常,但每次我尝试使用入口 url 时,我都会遇到超时,但如果我使用端点 IP该服务的一部分(我可以在 traefik 仪表板中看到)我可以访问该服务,但不能完全访问。我可以访问 IP/service1 但我无法访问它的任何子 URL,IP/service1/sub-service1 不工作。

我也试过 microk8s.enable ingress 但它为我创建了一个 nginx 入口,然后我禁用了它,因为我想使用 traefik。

我是否需要更改我的配置以使其与 Microk8s 兼容?如果是怎么办?

我必须提到我有两个入口文件:

我的 yaml 文件:

traefik-ui.yaml:

---
apiVersion: v1
kind: Service
metadata:
  name: traefik-web-ui
  namespace: kube-system
spec:
  selector:
    k8s-app: traefik-ingress-lb
  ports:
  - name: web
    port: 80
    targetPort: 8080
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: traefik-web-ui
  namespace: kube-system
spec:
  rules:
  - host: traefik-ui.minikube
    http:
      paths:
      - path: /
        backend:
          serviceName: traefik-web-ui
          servicePort: web

wws-ingress.yaml:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: wws
  annotations:
    kubernetes.io/ingress.class: "traefik"
    traefik.frontend.rule.type: PathPrefixStrip
    traefik.frontend.passHostHeader: "true"
    traefik.backend.loadbalancer.sticky: "true"
    #traefik.ingress.kubernetes.io/rule-type: ReplacePathRegex
    traefik.wss.protocol: http
    traefik.wss.protocol: https
spec:
  rules:
  - host: streambridge.local
    http:
      paths:
      - path: /streambridge
        backend:
          serviceName: streambridge
          servicePort: 9999
      - path: /dashboard
        backend:
          serviceName: dashboard
          servicePort: 9009
      - path: /gateway
        backend:
          serviceName: gateway
          servicePort: 8080
      - path: /rdb
        backend:
          serviceName: rethinkdb
          servicePort: 8085

Minikube 命令(这没有问题):

kubectl apply -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-rbac.yaml
kubectl apply -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-ds.yaml

kubectl apply -f traefik-ui.yaml
kubectl apply -f wws-ingress.yaml

我在 Microk8s 中尝试过:

microk8s.kubectl apply -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-rbac.yaml
microk8s.kubectl apply -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-ds.yaml
microk8s.kubectl apply -f traefik-ui.yaml
microk8s.kubectl apply -f wws-ingress.yaml

在另一台机器上测试我的设置并看到它在那儿工作后,我发现我的机器出了点问题,在我的两个同事的帮助下花了很多时间并尝试了一切之后我们发现问题与我机器中的 iptable 有关,我们按照此处所述解决了它:https://github.com/ubuntu/microk8s/issues/72