はじめに
以下に記載がありますがShareVPCが前提でないので、Shared vpcの場合に静的IPアドレスをどう指定すべきかのメモです。
https://cloud.google.com/kubernetes-engine/docs/how-to/internal-load-balance-ingress#static_ip_addressing
結論
サブネットを指定するときに、ホストプロジェクトとホストプロジェクトのVPCのサブネットを指定する。プロキシ専用サブネットは指定できません。
この IP アドレスは、GKE クラスタと同じリージョン内のサブネットからのものである必要があります。リージョン(プロキシ専用サブネットを除く)内で使用可能なプライベート サブネットを使用できます。Ingress リソースごとに異なるサブネットからのアドレスを持つこともできます。
コマンド例
gcloud compute addresses create STATIC_IP_NAME --region asia-northeast1 --subnet projects/YOUR-HOST-PROJECT/regions/asia-northeast1/subnetworks/SUBNET-NAME
あとはマニュアル通りにingressのyamlファイルでkubernetes.io/ingress.regional-static-ip-name:にSTATIC_IP_NAMEを指定すればOKです。
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: ilb-demo-ingress
namespace: istio-system
annotations:
kubernetes.io/ingress.class: "gce-internal"
kubernetes.io/ingress.regional-static-ip-name: ilb-ip
spec:
backend:
serviceName: istio-internal-ingressgateway
servicePort: 80
Ingressに静的なIPアドレスが振られています。
$ kubectl get ingress.networking.k8s.io/ilb-demo-ingress -n istio-system
NAME CLASS HOSTS ADDRESS PORTS AGE
ilb-demo-ingress <none> * 10.180.4.17 80 45s
$ gcloud compute addresses describe ilb-ip --region asia-northeast1
address: 10.180.4.17
addressType: INTERNAL
creationTimestamp: '2021-03-30T22:14:49.922-07:00'
description: ''
id: '5684293617779850150'
kind: compute#address
--projectでhost projectを指定して静的IPアドレスを予約した場合、service projectから予約した静的IPにアクセスできないのでエラーになります。
$ kubectl describe ingress ilb-demo-ingress -n istio-system
Name: ilb-demo-ingress
Namespace: istio-system
Address:
Default backend: istio-internal-ingressgateway:80 (100.64.0.7:8080,100.64.1.6:8080,100.64.2.6:8080)
Rules:
Host Path Backends
---- ---- --------
* * istio-internal-ingressgateway:80 (100.64.0.7:8080,100.64.1.6:8080,100.64.2.6:8080)
Annotations: kubernetes.io/ingress.class: gce-internal
kubernetes.io/ingress.regional-static-ip-name: ilb-ip
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Sync 3m10s (x2 over 3m11s) loadbalancer-controller Scheduled for sync
Normal Sync 2m51s loadbalancer-controller UrlMap "k8s2-um-8p8s0x1d-istio-system-ilb-demo-ingress-ijv13fbb" created
Normal Sync 2m48s loadbalancer-controller TargetProxy "k8s2-tp-8p8s0x1d-istio-system-ilb-demo-ingress-ijv13fbb" created
Warning Sync 45s (x15 over 2m48s) loadbalancer-controller Error syncing to GCP: error running load balancer syncing routine: loadbalancer 8p8s0x1d-istio-system-ilb-demo-ingress-ijv13fbb does not exist: the given static IP name ilb-ip doesn't translate to an existing static IP.