GKE使用内部IP的Ingress

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

GKE Ingress Using Internal IP

问题

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

  1. 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.

编辑后,错误信息如下:

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

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

ingress.yaml

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. labels:
  5. app: gke-app
  6. name: event-ingress
  7. namespace: gke-app
  8. spec:
  9. ingressClassName: "gce-internal"
  10. defaultBackend:
  11. service:
  12. name: gke-svc
  13. port:
  14. number: 8003
  15. rules:
  16. - host: event.staginggke.my.id
  17. http:
  18. paths:
  19. - path: "/"
  20. pathType: Prefix
  21. backend:
  22. service:
  23. name: gke-svc
  24. port:
  25. number: 8003

svc.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: gke-svc
  5. namespace: gke-app
  6. annotations:
  7. cloud.google.com/neg: '{"ingress": true}'
  8. networking.gke.io/load-balancer-type: "Internal"
  9. labels:
  10. app: gke-app
  11. spec:
  12. sessionAffinity: ClientIP
  13. selector:
  14. app: gke-app
  15. ports:
  16. - port: 8003 # Port output
  17. targetPort: 8000 # Container port
  18. protocol: TCP
  19. name: http
  20. nodePort: 30473 # Node Port Static
  21. type: LoadBalancer
  22. loadBalancerIP: 10.184.0.12
  23. 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

  1. 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

  1. 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

  1. apiVersion: networking.k8s.io/v1
  2. kind: Ingress
  3. metadata:
  4. labels:
  5. app: gke-app
  6. name: event-ingress
  7. namespace: gke-app
  8. spec:
  9. ingressClassName: "gce-internal"
  10. defaultBackend:
  11. service:
  12. name: gke-svc
  13. port:
  14. number: 8003
  15. rules:
  16. - host: event.staginggke.my.id
  17. http:
  18. paths:
  19. - path: "/"
  20. pathType: Prefix
  21. backend:
  22. service:
  23. name: gke-svc
  24. port:
  25. number: 8003

svc.yaml

  1. apiVersion: v1
  2. kind: Service
  3. metadata:
  4. name: gke-svc
  5. namespace: gke-app
  6. annotations:
  7. cloud.google.com/neg: '{"ingress": true}'
  8. networking.gke.io/load-balancer-type: "Internal"
  9. labels:
  10. app: gke-app
  11. spec:
  12. sessionAffinity: ClientIP
  13. selector:
  14. app: gke-app
  15. ports:
  16. - port: 8003 # Port output
  17. targetPort: 8000 # Container port
  18. protocol: TCP
  19. name: http
  20. nodePort: 30473 # Node Port Static
  21. type: LoadBalancer
  22. loadBalancerIP: 10.184.0.12
  23. 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:

确定