GKE使用内部IP的Ingress

huangapple go评论78阅读模式
英文:

GKE Ingress Using Internal IP

问题

我有一个使用golang的GKE服务应用程序。我希望该应用程序只能通过相同的VPC访问(因为它将使用Kong公开到公共域)。但是,每次我在GKE内部创建ALB Ingress时,都会返回如下错误:

Error syncing to GCP: error running load balancer syncing routine: loadbalancer ad8b7iw3-gke-app-event-ingress-n1p8mv91 does not exist: googleapi: Error 400: Invalid value for field 'resource.target': 'https://www.googleapis.com/compute/v1/projects/gke-project/regions/asia-southeast2/targetHttpProxies/k8s2-tp-ad8b7iw3-gke-app-event-ingress-n1p8mv91'. An active proxy-only subnetwork is required in the same region and VPC as the forwarding rule. 

编辑后,错误信息如下:

Missing one or more resources. If resource creation takes longer than expected, you might have an invalid configuration. 

我已经创建了svc和ingress的YAML文件来处理这个问题:

ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app: gke-app
  name: event-ingress
  namespace: gke-app
spec:
  ingressClassName: "gce-internal"
  defaultBackend:
    service:
      name: gke-svc
      port:
        number: 8003
  rules:
    - host: event.staginggke.my.id
      http:
        paths:
          - path: "/"
            pathType: Prefix
            backend:
              service:
                name: gke-svc
                port:
                  number: 8003

svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: gke-svc
  namespace: gke-app
  annotations:
    cloud.google.com/neg: '{"ingress": true}'
    networking.gke.io/load-balancer-type: "Internal"
  labels:
    app: gke-app
spec:
  sessionAffinity: ClientIP
  selector:
    app: gke-app
  ports:
    - port: 8003 # Port output
      targetPort: 8000 # Container port
      protocol: TCP
      name: http
      nodePort: 30473 # Node Port Static
  type: LoadBalancer
  loadBalancerIP: 10.184.0.12
  externalTrafficPolicy: Cluster

谢谢你的帮助! GKE使用内部IP的Ingress

英文:

I have a GKE service app using golang. I want to make the app only accessible with same vpc (because it will exposed using kong to public domain). But everytime i make the internal alb ingress inside GKE, it returns an error like this

Error syncing to GCP: error running load balancer syncing routine: loadbalancer ad8b7iw3-gke-app-event-ingress-n1p8mv91 does not exist: googleapi: Error 400: Invalid value for field 'resource.target': 'https://www.googleapis.com/compute/v1/projects/gke-project/regions/asia-southeast2/targetHttpProxies/k8s2-tp-ad8b7iw3-gke-app-event-ingress-n1p8mv91'. An active proxy-only subnetwork is required in the same region and VPC as the forwarding rule. 

EDITED
For now the error return like this

Missing one or more resources. If resource creation takes longer than expected, you might have an invalid configuration. 

i have make svc and ingress yaml file to handle this:

ingress.yaml

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  labels:
    app: gke-app
  name: event-ingress
  namespace: gke-app
spec:
  ingressClassName: "gce-internal"
  defaultBackend:
    service:
      name: gke-svc
      port:
        number: 8003
  rules:
    - host: event.staginggke.my.id
      http:
        paths:
          - path: "/"
            pathType: Prefix
            backend:
              service:
                name: gke-svc
                port:
                  number: 8003

svc.yaml

apiVersion: v1
kind: Service
metadata:
  name: gke-svc
  namespace: gke-app
  annotations:
    cloud.google.com/neg: '{"ingress": true}'
    networking.gke.io/load-balancer-type: "Internal"
  labels:
    app: gke-app
spec:
  sessionAffinity: ClientIP
  selector:
    app: gke-app
  ports:
    - port: 8003 # Port output
      targetPort: 8000 # Container port
      protocol: TCP
      name: http
      nodePort: 30473 # Node Port Static
  type: LoadBalancer
  loadBalancerIP: 10.184.0.12
  externalTrafficPolicy: Cluster

Thank you for helping!!! GKE使用内部IP的Ingress

答案1

得分: 0

您缺少一个仅代理的子网。您需要在与您的GKE集群相同的VPC/Subnet中创建一个子网。

https://cloud.google.com/load-balancing/docs/l7-internal/setting-up-l7-internal#configure-a-network

英文:

You are missing a proxy-only subnet. You need to create one in the same VPC/Subnet your GKE cluster is on

https://cloud.google.com/load-balancing/docs/l7-internal/setting-up-l7-internal#configure-a-network

huangapple
  • 本文由 发表于 2023年8月9日 12:17:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76864545.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定