GCE 入口多路径通配符问题

GCE ingress multi-path wildcard issue

我已经在 GCP 中配置了我的 Kubernetes 集群,

ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: test-ingress
 annotations:
   kubernetes.io/ingress.class: "gce"
   kubernetes.io/ingress.global-static-ip-name: "ip-name"
   ingress.kubernetes.io/rewrite-target: "/"
   kubernetes.io/ingress.allow-http: "true"
spec:
  backend:
    serviceName: default-http-backend
    servicePort: 80
  rules:
  - http:
     paths:
     - path: /myService/*
       backend:
         serviceName: my-service
         servicePort: 80

app.yaml

apiVersion: extensions/v1beta1
  kind: Deployment
  metadata:
    name: my-service
    labels:
      app: my-service
  spec:
    replicas: 3
    template:
      metadata:
        labels:
          app: my-service
      spec:
        containers:
          - image: gcr.io/project_name7/my-service:6.0
            imagePullPolicy: Always
            name: my-service
            ports:
              - containerPort: 4000
            readinessProbe:
              httpGet:
                path: /healthz
                port: 4000
              periodSeconds: 1
              timeoutSeconds: 1
              successThreshold: 1
              failureThreshold: 10
  ---
  apiVersion: v1
  kind: Service
  metadata:
    name: my-service
    labels:
      k8s-app: my-service
  spec:
    type: NodePort
    ports:
      - name: my-service
        port: 80
        protocol: TCP
        targetPort: 4000
    selector:
      app: my-service

默认-backend.yaml

apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: default-http-backend
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            app: default-http-backend
        spec:
          terminationGracePeriodSeconds: 60
          containers:
          - name: default-http-backend
            # Any image is permissable as long as:
            # 1. It serves a 404 page at /
            # 2. It serves 200 on a /healthz endpoint
            image: gcr.io/google_containers/defaultbackend:1.4
            livenessProbe:
              httpGet:
                path: /healthz
                port: 8080
                scheme: HTTP
              initialDelaySeconds: 30
              timeoutSeconds: 5
            ports:
            - containerPort: 8080
            resources:
              limits:
                cpu: 10m
                memory: 20Mi
              requests:
                cpu: 10m
                memory: 20Mi
    ---
    kind: Service
    apiVersion: v1
    metadata:
      name: default-http-backend
    spec:
      selector:
        app: default-http-backend
      ports:
        - protocol: TCP
          port: 80
          targetPort: 8080
      type: NodePort

我的健康检查一切正常,负载均衡器已启动并且 运行。我也可以点击默认后端。但是当我尝试击球时,

GET http://ingress-ip/myService/api/test

我在 404 状态代码的邮递员中收到以下错误,

        <!DOCTYPE html>
    <html lang="en">
        <head>
            <meta charset="utf-8">
            <title>Error</title>
        </head>
        <body>
            <pre>Cannot GET /myService/api/test</pre>
        </body>
    </html>

但是 API 在服务中可用,当我将服务从 NodePort 切换到 LoadBalancer 时,我可以使用 LoadBalancer IP 访问 API。谁能帮我解决这个问题?如何取消通配符或如何访问我的 API?

GCE ingress 不支持 ingress.kubernetes.io/rewrite-target,因此您的应用程序 pod 正在接收 /myService/api/test 形式的路径,并因此返回 HTTP/404。