GCE入口多路径通配符问题

时间:2018-08-21 04:22:20

标签: kubernetes google-cloud-platform google-kubernetes-engine kubernetes-ingress

我已在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

default-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?

1 个答案:

答案 0 :(得分:2)

GCE入口不支持sudo /etc/init.d/postgresql start,因此您的应用程序容器正在接收格式为ingress.kubernetes.io/rewrite-target的路径,并因此而返回HTTP / 404。