PathPrefixStrip不能按预期重定向到后端

时间:2018-11-24 11:34:08

标签: kubernetes traefik traefik-ingress

问题

最近,我决定从Swarm迁移到Kubernetes,并一直在尝试配置Traefik以将我的请求路由到基于Path的预期后端服务。

在阅读了文档和其他一些主题之后,即使在StackOverflow上,我也得出结论,到达那里的正确选择是使用 PathPrefixStrip ,例如:

  

如果后端侦听根路径(/),但应在特定前缀上可路由,请使用* Strip匹配器。例如,PathPrefixStrip:/ products可以匹配/ products,也可以匹配/ products / shoes和/ products / shirts。由于路径是在转发之前剥离的,因此您的后端应该在/上侦听。

但是显然,我仍然缺少一些东西。

您期望看到什么?

objectB = { birthdate: 'mybirthdate', school: 'myschool', age: 'myage' } 的请求在http://192.168.1.230/blog

上重定向到后端服务“无论它在哪里”

您看到了什么?

相反,我得到/ 404'shttp://192.168.1.230/blog或其他任何东西。

版本 我尝试了Traefik 1.7和Kubernetes v1.12.2

配置文件

traefik-internal.yaml

http://192.168.1.230

traefik-internal.toml

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: traefik-ingress-controller
  namespace: kube-system
  labels:
    k8s-app: traefik-ingress-lb
spec:
  replicas: 1
  selector:
    matchLabels:
      k8s-app: traefik-ingress-lb
  template:
    metadata:
      labels:
        k8s-app: traefik-ingress-lb
        name: traefik-ingress-lb
    spec:
      serviceAccountName: traefik-ingress-controller
      terminationGracePeriodSeconds: 60
      containers:
      - image: traefik
        name: traefik-ingress-lb
        imagePullPolicy: IfNotPresent
        ports:
         - name: http
           containerPort: 80
         - name: https
           containerPort: 443
         - name: admin
           containerPort: 8080
        args:
        - --configfile=/etc/traefik/traefik.toml
        livenessProbe:
          httpGet:
            path: /ping
            port: 80
          initialDelaySeconds: 3
          periodSeconds: 3
          timeoutSeconds: 1
        volumeMounts:
        - name: config
          mountPath: /etc/traefik/traefik.toml
      volumes:
      - name: config
        hostPath:
          path: /nas/home-stack/3-traefik/traefik-internal.toml
          type: File
      affinity:
        podAntiAffinity:
          preferredDuringSchedulingIgnoredDuringExecution:
          - weight: 100
            podAffinityTerm:
              labelSelector:
                matchExpressions:
                - key: role
                  operator: In
                  values:
                  - boss
              topologyKey: kubernetes.io/hostname
---
apiVersion: v1
kind: Service
metadata:
  name: traefik-ingress-service
  namespace: kube-system
  labels:
    k8s-app: traefik-ingress-lb
spec:
  selector:
    k8s-app: traefik-ingress-lb
  externalTrafficPolicy: Local
  ports:
    - protocol: TCP
      port: 80
      name: web
    - protocol: TCP
      port: 443
      name: https
    - protocol: TCP
      port: 8080
      name: admin
  type: LoadBalancer
  loadBalancerIP: 192.168.1.230

ghost.yaml

defaultEntryPoints = ["http","https"]
debug = false
logLevel = "INFO"

# Do not verify backend certificates (use https backends)
InsecureSkipVerify = true

[entryPoints]
  [entryPoints.http]
  address = ":80"
  compress = true
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[api]
  [api.statistics]
    recentErrors = 10
    debug = true

[kubernetes]
  labelselector = "traffic-type=internal"

[metrics]
  [metrics.prometheus]
  buckets=[0.1,0.3,1.2,5.0]
  entryPoint = "traefik"

[ping]
entryPoint = "http"

请注意 ghost.yaml ,如果我将服务作为apiVersion: extensions/v1beta1 kind: Deployment metadata: name: blog-controller labels: app: blog k8s-app: traefik-ingress-lb spec: replicas: 1 strategy: type: RollingUpdate selector: matchLabels: app: blog k8s-app: traefik-ingress-lb template: metadata: labels: k8s-app: traefik-ingress-lb app: blog spec: containers: - name: ghost image: allandequeiroz/ghost-the-shell:arm imagePullPolicy: IfNotPresent ports: - containerPort: 2368 volumeMounts: - name: ghost-database mountPath: /var/www/ghost/content/data - name: ghost-configuration mountPath: /var/www/ghost/config.production.json restartPolicy: Always volumes: - name: ghost-database hostPath: path: /nas/ghost - name: ghost-configuration hostPath: path: /nas/home-stack/6-ghost/conf/config.production.json type: File --- apiVersion: v1 kind: Service metadata: name: blog spec: selector: k8s-app: traefik-ingress-lb app: blog ports: - port: 80 targetPort: 2368 type: NodePort # type: LoadBalancer # loadBalancerIP: 192.168.1.232 --- apiVersion: extensions/v1beta1 kind: Ingress metadata: name: blog labels: traffic-type: internal annotations: kubernetes.io/ingress.class: traefik traefik.frontend.rule.type: PathPrefixStrip spec: rules: - host: allandequeiroz.com http: paths: - path: /blog backend: serviceName: blog servicePort: 80 应用,我可以直接指向LoadBalanderIP击中幽灵,但是我想拆分内部和外部服务,并使用内部(192.168.1.230)和外部(192.168.1.230)负载均衡器通过浴来访问它们。

谢谢你们,对不起,如果我错过了一些东西,问了一个假的问题。

0 个答案:

没有答案
相关问题