Ingress ã®é²åç Gateway API ã解説ãã Part 1 (ã·ã³ã°ã«ã¯ã©ã¹ã¿ç·¨)
2022 å¹´ 4 æ 27 æ¥ è¿½è¨:
2022 å¹´ 3 ææ«ã« GKE 㧠Gateway API ã® v1alpha2 ãå©ç¨å¯è½ã«ãªãã¾ãããããã«ä¼´ãæ¬è¨äºã®å 容ã v1alpha2 ãåæã¨ãããã®ã«æ´æ°ãã¦ãã¾ããéè¦
2022 å¹´ 4 æ 27 æ¥æç¹ã®æ¢ç¥ã®åé¡ã¨ãã¦ãå ã v1alpha1 CRDsãã¤ã³ã¹ãã¼ã«ãå©ç¨ãã¦ããã¯ã©ã¹ã¿ã« v1alpha2 CRDs ãã¤ã³ã¹ãã¼ã«ããå ´åãæ°è¦è¨å®ãå¯è½ã«ãªãã¾ã§æ大 1 é±éç¨åº¦ãæããå ´åãããã¾ããå ã v1alpha1 ã使ã£ã¦ããã¯ã©ã¹ã¿ã¨ã¯å¥ã®ã¯ã©ã¹ã¿ãç¨æã㦠v1alpha2 ã試ãã¦é ããã¨ãæ¨å¥¨ãã¾ãã
Kubernetes / GKE ãã¡ã³ã®çæ§ãããã«ã¡ã¯ãGoogle Cloud ã® Kazuu (ããã¼) ã§ãã
ãã¦ã2021 å¹´ã«ä¸çªè©±é¡ã«æãã£ã GKE ã®ã¢ãããã¼ãã¨è¨ãã°ãGKE Autopilot ã®ç»å ´ã§ãããããã²ã¨ã¤ç§ãé¸ã¶ãªã Gateway API ã Preview ã§ãµãã¼ãããããã¨ï¼ã§ãã
æ¬è¨äºã§ã¯ Gateway API ã®æ¦è¦ã¨GKE ã§ã®ä½¿ãæ¹ã®è§£èª¬ãè¡ãã¾ãã
ããã§ã¯é²ãã¦ããã¾ãããï¼
TL; DR
- Gateway API 㯠Ingress (L7 LB 㧠K8s service ãå ¬é) ã®é²åçã¨å¼ã¹ããã®ã§ããããå¤ãã®ã¦ã¼ã¹ã±ã¼ã¹ããµãã¼ããã¾ãã
- å®éã«ä¸ã§åã LB 㯠GKE ã® Ingress ã¨å¤ããã External / Internal HTTP(S) load balancing ã§ãããGKE ã® Ingress ã§ã¯ä½¿ããªãã£ãæ©è½ã使ãã¾ãã
- ã¾ã ã¾ã é²åã¯ç¶ãã¾ãã2022 å¹´ã«ä¹ããæå¾ ï¼
1. Gateway API æ¦è¦
Gateway API ã¨ã¯ K8s ãµã¼ãã¹ãå¤é¨å ¬éããããã«ç¨ããããæ°ãã API ãªã½ã¼ã¹ã§ããSIG-Network community ãä¸å¿ã«éçºãè¡ãããç¾å¨ãGKE å«ãã¦è¤æ°ã®å®è£ ãåå¨ãã¦ã¾ãã
å¾æ¥ãããããã®æã® API ãªã½ã¼ã¹ã¨ãã¦ã¯ãIngress / Service (type: LoadBalancer, type: NodePort) ãªã©ãããã¾ããä¸å³ã®ãªã¬ã³ã¸è²ã§å²ã£ãç®æã§ããã
ç¹ã« Ingress 㯠L7 LB ãæ§æããéã«ä½¿ããã¾ããã以ä¸ã®ãããªèª²é¡ãããã¾ããã
- è¤æ° namespace (K8s å
ã®è«ççãªããã³ã) éã§å
±æã§ããªã
ãã¤ã¯ããµã¼ãã¹æ¯ã« namespace ãå²ãå½ã¦ã¦éç¨ããå ´åã«ã代表ã㦠1 ã¤ã® Ingress (L7LB ã¨ãã® VIP) ãæãããæ§æãåããªãã - ãµãã¼ããã LB ã®æ©è½ãéå®ç
ä¾ãã°ãExternal / Internal HTTP(S) LB ãæ㤠Header based routing ãªã©ã¯ GKE ã® Ingress çµç±ã§ã¯è¨å®ã§ããªãã - ã¢ããªéçºè
ã«åªãããªã
1 ã¤ã® Ingress ã¨ãããªã½ã¼ã¹ã§ããããã³ã«ãIP ã¢ãã¬ã¹ããã¼ãçªå·ãTLS 証ææ¸ãã URL ãã¹ã«ã¼ãã£ã³ã°ã¾ã§ãã«ãã¼ããã¦ãããã¤ã³ãã©ç¥èã®ãªã人ãéç¨ããã®ã¯è²ã ãªæå³ã§è¾ãã
ãããã£ã課é¡ã解決ãããããGateway API ãéçºããã¾ãããå°ã2022 å¹´ 4æ 27 æ¥ç¾å¨ Gateway API ã®ãã¼ã¸ã§ã³ã¯ v1alpha2 ãææ°ã§ãã
ã²ã¨ãã« Gateway API ã¨è¨ã£ã¦ãåä¸ã®ãªã½ã¼ã¹ããã訳ã§ã¯ããã¾ããã以ä¸ã®ãããªè¤æ°ã® ãªã½ã¼ã¹ããæ§æããã¾ãã
- GatewayClass
- Gateway
- HTTPRoute
- TCPRoute
- TLSRoute
- UDPRoute
2. Gateway API ã®ä¸»ãªãªã½ã¼ã¹
ãã®ç« ã§ã¯ãç¾å¨ãGKE ã§ã¯ãµãã¼ããã¦ãã GatewayClass / Gateway / HTTPRoute ã«ã¤ãã¦èª¬æãã¾ãã
- GatewayClass
GatewayClass ã¯å®éã«ãã©ãã£ãã¯ã転éãã LB ã Proxy ãå®ç¾©ãããªã½ã¼ã¹ã§ããåºæ¬çã« Infrastructure provider (GKE ãªã Google) ãäºåå®ç¾©ãã¦ãããã®ã§ããèãæ¹ã¨ãã¦ã¯ PersistentVolume ã«ããã StorageClass ã¨ä¼¼ã¦ããã¨æãã¾ãã - Gateway
Gateway 㯠GatewayClass ãåç §ãã¤ã¤ãListener (ãããã³ã«ããã¼ãçªå·ãTLSè¨å®ç) ã IP ã¢ãã¬ã¹ çãå®ç¾©ãããªã½ã¼ã¹ã§ãã - HTTPRoute
HTTPRoute ã¯äºãå®ç¾©ããã Gateway ãåç §ãã¤ã¤ãåä¿¡ãã HTTP ãã©ãã£ãã¯ã®ã«ã¼ãã£ã³ã°è¨å®ãè¡ããªã½ã¼ã¹ã§ããä¾ãã°ãHTTP ã® URL path ã Request header ã® value ãå ã«è»¢éå ã®æå®ãããã転éå æ¯ã« Weight ãæå®ã㦠Traffic split ãè¡ããã¨ãå¯è½ã§ããHTTPRoute ãæå®ãã転éå 㯠K8s ã® Service ã¨ãªãã¾ãã
ä¸è¨ 3 ã¤ã®ãªã½ã¼ã¹ã®ç¸é¢ãå³ã«ããã¨ä»¥ä¸ã®ããã«ãªãã¾ãã
ã¾ããnamespace é㧠1 ã¤ã® Gateway ãå ±æãããã¨ãå¯è½ã«ãªã£ã¦ãã¾ããIngress ã§ã¯ 1 ã¤ã®ãªã½ã¼ã¹ã§è¡¨ç¾ãã¦ãããã¨ãããã㦠3 ã¤ã«åãããã¨ã«ãã£ã¦ãã¤ã³ãã©æ å½è ã¨ã¢ããªéçºè ã®é¢å¿äºããªã½ã¼ã¹ã¬ãã«ã§ç¶ºéºã«åãããã¨ãåºæ¥ã¦ãã¾ãããã®ããã« Ingress ã§èª²é¡ã¨ãªã£ã¦ããç¹ã解決ãã¦ãã¾ãã
ããã§ã¯ Gateway API ã¨ä»ã® K8s ãªã½ã¼ã¹ã¨ã®é¢ä¿ã¯ã©ããªãã®ã§ããããï¼Ingress ã Service ãåç §ãã¦ããããã«ãGateway API ã§ã¯ HTTPRoute ã Service ãåç §ãã¾ãã
3. GKE ã«ããã Gateway API
2022 å¹´ 4æ 27 æ¥ç¾å¨ãGKE ã§ã¯ Gateway API ã® v1alpha1 åã³ v1alpha2ããµãã¼ããã¦ãã¾ããv1alpha1 㨠v1alpha2 ã§ã¯ API scheme ã«å¤§ããªéãããããããä»ããå©ç¨ããå ´åã¯ãã Beta ã«è¿ã v1alpha2 ãæ¨å¥¨ãã¾ããå©ç¨å¯è½ãª Gateway Class ã¯ä»¥ä¸ã® 4 ã¤ã¨ãªããGKE Standard / Autopilot ã©ã¡ãã§ãå©ç¨å¯è½ã§ãããã£ã¨è©³ããæ¯è¼ã¯ãã¡ãã
Gateway API 㨠LB ã®Configuration ã®ç¸é¢ã¯ä»¥ä¸ã®ããã«ãªã£ã¦ãã¾ãã
Ingress ã«ãã¦ããGateway API ã«ãã¦ã External HTTP(S) LB (L7 XLB) 㨠Internal HTTP(S) LB (L7 ILB) ã® Configuration ãæ½è±¡åãã¦ãããªã½ã¼ã¹ã§ãããã¨ãåããã¨æãã¾ãã
4. 主ãªåææ¡ä»¶ã¨å¶ç´
- GKE ã®ãã¼ã¸ã§ã³ã¯ 1.20 以éã§å©ç¨å¯è½ã§ãã
- VPC Native ã¯ã©ã¹ã¿ã®ã¿ã§å©ç¨å¯è½ã§ãã
- Gateway API ã§å®ç¾©ããã¦ããå ¨ã¦ã®æ©è½ã使ããããã§ã¯ããã¾ããã詳ãã㯠ãã¡ããã確èªãã ããã
- Istio ã Anthos Service Mesh(ASM) ãã¤ã³ã¹ãã¼ã«ããã¯ã©ã¹ã¿ã®å ´åãGateway ãªã½ã¼ã¹ã®ååã Conflict ãããããkubectl get gateway ãå®è¡ããå ´åã« Istio / ASM ã® Gateway ãªã½ã¼ã¹ãåå¾åºæ¥ãªãå¯è½æ§ãããã¾ãããã®å ´åã¯ãã¡ãã®ã¯ã¼ã¯ã¢ã©ã¦ã³ãã使ã£ã¦ãã ããã
- FrontendConfig ã¯å©ç¨ä¸å¯ã§ãã
- BackendConfig 㯠Single-cluster Gateway (gke-l7-rilb && gke-l7-gxlb)ã§ã¯å©ç¨å¯è½ã§ãããMulti-cluster Gateway (gke-l7-rilb-mc && gke-l7-gxlb-mc)ã§ã¯å©ç¨ä¸å¯ã§ãã
- kind: ManagedCertificate ã使ã GKE ãéãã¦ä½æãã SSL証ææ¸ã¯ãµãã¼ãããã¾ããããäºãæåã§ä½æãã Google ã®ããã¼ã¸ã SSL 証ææ¸ã¯å©ç¨å¯è½ã§ãã
ããã§ã¯ããããå®éã« GKE ã® Gateway API (v1alpha2)ã触ããªãã使ãæ¹ã®ç¢ºèªããã¦ããã¾ãï¼
5. åæºå
ã¯ããã« Gateway API ã® CRDs ã GKE ã¯ã©ã¹ã¿ã«ã¤ã³ã¹ãã¼ã«ããGateway API 㧠Gateway Class / Gateway / HTTPRoute ãªã©ã®ãªã½ã¼ã¹ã使ããããã«ãã¾ããå ¬å¼æé ã«å¾ããv1alpha2 åã³ v1alpha1 ã® CRDs ã両æ¹ã¤ã³ã¹ãã¼ã«ãã¾ããå°ãªãã¨ã 2022 å¹´4 æ 27 æ¥æç¹ã§ã¯ v1alpha2 ã ãã¤ã³ã¹ãã¼ã«ãã¦ã GatewayClass ãå©ç¨å¯è½ã«ãªãã¾ããã
# v1alpha2 ã® CRDs ãã¤ã³ã¹ãã¼ã«
⯠kubectl apply -k "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v0.4.2"
customresourcedefinition.apiextensions.k8s.io/gatewayclasses.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/gateways.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/httproutes.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/referencepolicies.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/tcproutes.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/tlsroutes.gateway.networking.k8s.io created
customresourcedefinition.apiextensions.k8s.io/udproutes.gateway.networking.k8s.io created# v1alpha1 ã® CRDs ãã¤ã³ã¹ãã¼ã«
⯠kubectl apply -k "github.com/kubernetes-sigs/gateway-api/config/crd?ref=v0.3.0"
customresourcedefinition.apiextensions.k8s.io/backendpolicies.networking.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/gatewayclasses.networking.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/gateways.networking.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/httproutes.networking.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/tcproutes.networking.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/tlsroutes.networking.x-k8s.io created
customresourcedefinition.apiextensions.k8s.io/udproutes.networking.x-k8s.io created
ã覧ã®ããã« Gateway API é¢é£ã® CRDs ãç¡äºã¤ã³ã¹ãã¼ã«åºæ¥ã¾ããã
ã§ã¯ãGateway Class ã確èªåºæ¥ãã試ãã¦ã¿ã¾ãããã(CRDs ã®ã¤ã³ã¹ãã¼ã«ããæ°åç¨åº¦æããã¾ã)
⯠kubectl get gatewayclass
NAME CONTROLLER AGE
gke-l7-gxlb networking.gke.io/gateway 2m26s
gke-l7-rilb networking.gke.io/gateway 2m27s
External Gateway (gke-l7-gxlb)㨠Internal Gateway (gke-l7-rilb)ã® 2 ã¤ã確èªåºæ¥ã¾ããããããæ®ãã® 2 ã¤ã¯ï¼ã¨æãããããã¾ããããããã¯å¥ã®æé ã§æå¹åãã¾ãã
ãã¹ãç¨ã¢ããªããããã¤ãã¾ãããã¹ãç¨ã¢ããªã¯ Pod ã®ãã¹ãåãç°å¢å¤æ°ã«ä»è¾¼ãã ä»»æã®ãã¼ã¸ã§ã³åãè¿ããããããã®ã§ããHTTPRoute ã使ã£ãã«ã¼ãã£ã³ã°ã®æ¤è¨¼ãè¡ããããä»å㯠v1, v2, v3 㨠3 ã¤ã®ãã¼ã¸ã§ã³ã«åãã¦ãããã¤ãè¡ãã¾ããã
⯠git clone [email protected]:kazshinohara/gateway-demo.git
⯠cd gateway-demo/external-gateway
⯠kubectl apply -f test-app.yaml
deployment.apps/whereami-v1 created
service/whereami-v1 created
deployment.apps/whereami-v2 created
service/whereami-v2 created
deployment.apps/whereami-v3 created
service/whereami-v3 created
ããã§æºåå®äºã§ãã
6. External Gateway ã試ã
ã¯ããã«ãããã¼ã¸ã SSL 証ææ¸ãä½æãã¾ãã
ä»å㯠x-gw.gcpx.org ã¨ãããã¡ã¤ã³ãã¼ã ã使ãã¾ãã
⯠gcloud compute ssl-certificates create x-gw-cert \
--domains=x-gw.gcpx.org \
--global
Created [https://www.googleapis.com/compute/v1/projects/kzs-sandbox/global/sslCertificates/x-gw-cert].
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
x-gw-cert MANAGED 2021-12-15T00:41:52.385-08:00 PROVISIONING
x-gw.gcpx.org: PROVISIONING
ç¶ãã¦ãIP Address ã®äºç´ããã¾ãã
⯠gcloud compute addresses create x-gw-ip --global
Created [https://www.googleapis.com/compute/v1/projects/kzs-sandbox/global/addresses/x-gw-ip].⯠gcloud compute addresses list
NAME ADDRESS/RANGE TYPE PURPOSE NETWORK REGION SUBNET STATUS
x-gw-ip X.X.X.X EXTERNAL RESERVED
DNS ãµã¼ãã¼ã« A ã¬ã³ã¼ãã®ç»é²ãè¡ãã¾ããç§ã¯å人ã§å©ç¨ãã¦ãã Google Domains ã® DNS ãµã¼ãã¼ã使ãã¾ãããä»ã 㨠Cloud Domains ã使ãã®ãè¯ãããã§ãã
Gateway ã®ãããã§ã¹ãã以ä¸ã®éãä½æãã¾ãã
å
ç¨ä½æãã SSL 証ææ¸ âx-gw-certâ ã¨äºç´ãã IP Address âx-gw-ipâ ã®ååãæå®ãã¾ãã
ä½æãã Gateway ã®ãããã§ã¹ãã GKE ã¯ã©ã¹ã¿ã«é©ç¨ãã¾ãã
⯠kubectl apply -f ./v1alpha2/x-gateway.yaml
gateway.gateway.networking.k8s.io/external-gateway created
DNS ã®ç»é²ã¨ Gateway ã®ä½æ (LB çã«ã¯ Forwarding Rule 㨠Target Proxy ã®ä½æ) ãããã°ããããã¨ã証ææ¸ã®ã¹ãã¼ã¿ã¹ã ACTIVE ã«ãªãã¾ãã
⯠gcloud compute ssl-certificates list
NAME TYPE CREATION_TIMESTAMP EXPIRE_TIME MANAGED_STATUS
x-gw-cert MANAGED 2021-12-15T00:41:52.385-08:00 2022-03-15T01:08:14.000-07:00 ACTIVE
x-gw.gcpx.org: ACTIVE
HTTPRoute ãä½æãã¾ããä»åã¯ä»¥ä¸ã®ãããªã«ã¼ãã£ã³ã°è¨å®ãè¡ãã¾ããã
- ããã©ã«ãã®è»¢éå
ã v1 service ã«ã
(ä¸ã®ã¹ããããã® 11 è¡ç®) - Request header ã« env:v2 ãå®å
¨ä¸è´ã§ããå ´å㯠v2 service ã«
(å 14 è¡ç®) - URL path ã« /version ã¨åæ¹ä¸è´ãããå ´å㯠v3 service ã«
(å 22 è¡ç®)
ä½æãã HTTPRoute ã®ãããã§ã¹ãã GKE ã¯ã©ã¹ã¿ã«é©ç¨ãã¾ãã
⯠kubectl apply -f ./v1alpha2/x-gw-httproute.yaml
httproute.gateway.networking.k8s.io/external-httproute created
åä½ç¢ºèªããã¾ãã
## ä½ãæå®ããã«ã¼ããã¹ã«ã¢ã¯ã»ã¹ãv1 ãµã¼ãã¹ããã¬ã¹ãã³ã¹
⯠curl -s https://x-gw.gcpx.org/\?param\=version | jq
{
"version": "v1"
}## Header ã env:v2 ã«æå®ãã¦ã¢ã¯ã»ã¹ãv2 ãµã¼ãã¹ããã¬ã¹ãã³ã¹
⯠curl -s https://x-gw.gcpx.org/\?param\=version -H "env:v2" | jq
{
"version": "v2"
}## /version ã«ã¢ã¯ã»ã¹ãv3 ãµã¼ãã¹ããã¬ã¹ãã³ã¹
⯠curl -s https://x-gw.gcpx.org/version | jq
{
"version": "v3"
}
GKE ã®Ingress ã ã¨ãURL path based routing ãããµãã¼ãããã¦ãã¾ããã§ããããGateway API ãéã㦠Header based routing ãå©ç¨åºæ¥ããã¨ã確èªåºæ¥ã¾ããã
念ã®çº LB å´ã®è¨å®ãã©ããªã£ã¦ããã®ãè¦ã¦ã¿ã¾ããããã¾ã㯠URL Map ã®ååãä½ææ¸ã¿ã® Gateway ã® annotations ãã確èªãã¾ãã
⯠kubectl describe gateway.gateway.networking.k8s.io external-gatewayName: external-gateway
Namespace: default
Labels: <none>
Annotations:
networking.gke.io/url-maps: gkegw-0qzb-default-external-gateway-u025eh5h3t4i
URL Map ã®è¨å®ãè¦ã¦ã¿ã¾ãã
⯠gcloud compute url-maps describe gkegw-0qzb-default-external-gateway-u025eh5h3t4i
hostRules:
- hosts:
- x-gw.gcpx.org
pathMatcher: hostoox1lmf8v2hvq9zh1adzzj1if6xzgm3j
id: '7528610436486766703'
kind: compute#urlMap
name: gkegw-0qzb-default-external-gateway-u025eh5h3t4i
pathMatchers:
- defaultService: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/global/backendServices/gkegw-0qzb-kube-system-gw-serve404-80-7cq0brelgzex
name: hostoox1lmf8v2hvq9zh1adzzj1if6xzgm3j
routeRules:
- matchRules:
- prefixMatch: /version
priority: 1
service: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/global/backendServices/gkegw-0qzb-default-whereami-v3-8080-az4u6tjafqbt
- matchRules:
- headerMatches:
- exactMatch: v2
headerName: env
prefixMatch: /
priority: 2
service: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/global/backendServices/gkegw-0qzb-default-whereami-v2-8080-muarp2l4si2h
- matchRules:
- prefixMatch: /
priority: 3
service: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/global/backendServices/gkegw-0qzb-default-whereami-v1-8080-dk75hnz2o0hz
selfLink: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/global/urlMaps/gkegw-0qzb-default-external-gateway-u025eh5h3t4i
matchRules ãè¤æ°è¨å®ããã¦ãããpriority å¤ãããããä»ä¸ããã¦ãã¾ããURL path ãæå®ããã«ã¼ã«ã Request header ãæå®ããã«ã¼ã«ãããåªå
ããã¦ãããã¨ããããã¾ãã
ãã®ãããªã«ã¼ãé¸æã®ä»æ§ã®è©³ç´°ã«ã¤ãã¦ã¯ãã¡ãã確èªãã¦ã¿ãã ããã
7. Internal Gateway ã試ã
注æ:
Internal HTTP(S) LB ãå©ç¨ããå ´åãäºããProxy-only subnets (LBã®å®æ ã¨ãã¦åã Proxy ãå©ç¨)ãç¨æãã¦ããå¿ è¦ãããã¾ãã詳ããã¯ãã¡ããã確èªãã ããã以ä¸ã®æé 㯠Proxy-only subnets ã GKE ã¯ã©ã¹ã¿ãåå¨ãã VPC ã® Region ã«ä½ææ¸ã¿ã§ãããã¨ãåæã¨ãªãã¾ãã
ã¯ããã« Internal Gateway ã§ä½¿ã IP Address ãäºç´ãã¾ããä»å㯠GKE ã® Node ãæå±ãã subnet ããæãåºãã¾ãã
⯠gcloud compute addresses create i-gw-ip \
--region asia-northeast1 \
--subnet subnet-05 \
--project kzs-sandbox
Created [https://www.googleapis.com/compute/v1/projects/kzs-sandbox/regions/asia-northeast1/addresses/i-gw-ip].⯠gcloud compute addresses describe i-gw-ip --region asia-northeast1
address: 192.168.5.34
addressType: INTERNAL
Gateway ã®ãããã§ã¹ãã以ä¸ã®éãä½æãã¾ããåã®ã¹ãããã§ä½æãã IP Address ã®ååãæå®ãã¦ããã¾ãã
ä½æãã Gateway ã®ãããã§ã¹ãã GKE ã¯ã©ã¹ã¿ã«é©ç¨ãã¾ãã
⯠cd ../internal-gateway
⯠kubectl apply -f ./v1alpha2/i-gateway.yaml
gateway.networking.x-k8s.io/internal-gateway created
HTTPRoute ã®ãããã§ã¹ããä½æãã¾ããã¾ã㯠External Gateway ã¨åæ§ã®ã«ã¼ãã£ã³ã°è¨å®ãè¡ãã¾ããã(hostname ã¯å¤ãã¦ãã¾ãã)
ä½æãã HTTPRoute ã®ãããã§ã¹ãã GKE ã¯ã©ã¹ã¿ã«é©ç¨ãã¾ãã
⯠kubectl apply -f ./v1alpha2/i-gw-httproute.yaml
httproute.gateway.networking.k8s.io/internal-httproute created
GCE ã®ã¤ã³ã¹ã¿ã³ã¹ããåä½ç¢ºèªããã¾ãã
## ä½ãæå®ããã«ã¼ããã¹ã«ã¢ã¯ã»ã¹ãv1 ãµã¼ãã¹ããã¬ã¹ãã³ã¹
⯠curl -s -H "Host:i-gw.gcpx.org" http://192.168.5.34/\?param\=version | jq
{
"version": "v1"
}## Header ã env:v2 ã«æå®ãã¦ã¢ã¯ã»ã¹ãv2 ãµã¼ãã¹ããã¬ã¹ãã³ã¹
⯠curl -s -H "Host:i-gw.gcpx.org" -H "env:v2" http://192.168.5.34/\?param\=version | jq
{
"version": "v2"
}## /version ã«ã¢ã¯ã»ã¹ãv3 ãµã¼ãã¹ããã¬ã¹ãã³ã¹
⯠curl -s -H "Host:i-gw.gcpx.org" http://192.168.5.34/version | jq
{
"version": "v3"
}
Internal Gateway (æ£ç¢ºã«ã¯ Internal HTTP(S) LB) 㯠Traffic split ããµãã¼ããã¦ãã¾ãã試ãã¦ã¿ã¾ããããTraffic split ãè¨å®ãã HTTPRoute ã®ãããã§ã¹ããä½æãã¾ããv1 ã« 40%, v2 ã« 30%, v3 ã« 30% ã®å²åã§è»¢éããããã«ãã¾ãã
念ã®çºãåã®ã¹ãããã§ä½¿ã£ã HTTPRoute ãæ¶ãã¦ãæ°ãã«ä½æãããããã§ã¹ãã GKE ã¯ã©ã¹ã¿ã«é©ç¨ãã¾ãããã
⯠kubectl delete-f ./v1alpha2/i-gw-httproute.yaml
httproute.networking.x-k8s.io "internal-httproute" deleted⯠kubectl apply -f ./v1alpha2/i-gw-httproute-split.yaml
httproute.networking.x-k8s.io/internal-httproute-split created
åä½ç¢ºèªãè¡ãã¾ããããããæå¾ å¤éãã®å²å㧠Traffic split ããã¦ãã¾ãã
⯠while true; do curl -s -H "Host:i-gw.gcpx.org" http://192.168.5.34/version | jq ; sleep 1 ; done
{
"version": "v1"
}
{
"version": "v2"
}
{
"version": "v3"
}
{
"version": "v1"
}
{
"version": "v3"
}
{
"version": "v1"
}
LB ã®è¨å®ã¯ä»¥ä¸ã®ããã« HTTPRoute ã§æå®ããå²å㧠weight ãè¨å®ããã¦ãã¾ãã
## é·ãã®ã§ä¸é¨å²æ
⯠gcloud compute url-maps describe gkegw-0qzb-default-internal-gateway-mfrrz1j0tex3 --region asia-northeast1
routeRules:
- matchRules:
- prefixMatch: /
priority: 1
routeAction:
weightedBackendServices:
- backendService: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/regions/asia-northeast1/backendServices/gkegw-0qzb-default-whereami-v1-8080-dk75hnz2o0hz
weight: 40
- backendService: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/regions/asia-northeast1/backendServices/gkegw-0qzb-default-whereami-v2-8080-muarp2l4si2h
weight: 30
- backendService: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/regions/asia-northeast1/backendServices/gkegw-0qzb-default-whereami-v3-8080-az4u6tjafqbt
weight: 30
region: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/regions/asia-northeast1
æå¾ã« requestHeaderModifier ã試ãã¾ãããã㯠Request header ã®è¿½å ãåé¤ãä¸æ¸ãã LB ã§è¡ãè¨å®ã§ãããã¡ãã External Gateway ã§ã¯å©ç¨ã§ãã¾ããããã¡ãã GKE ã® Ingress ã§ãå©ç¨åºæ¥ã¾ããã
試ããå
容ã¨ãã¦ã¯ä»¥ä¸ã®éãã§ãã
- âenv:v2â header ãæã¤ãªã¯ã¨ã¹ããã âmy-headerâ header ãåé¤ãã¾ãã
(ä¸ã®ã¹ããããã® 22 è¡ç®) - âenv:v2â header ãæã¤ãªã¯ã¨ã¹ãã« âmy-header:helloâ ã追å ãã¾ãã
( å 24 è¡ç®)
Header ã® Value ã® rewrite ãè¡ãã¤ã¡ã¼ã¸ã§ãã
念ã®çºãåã®ã¹ãããã§ä½¿ã£ã HTTPRoute ãæ¶ãã¦ã
æ°ãã«ä½æãããããã§ã¹ãã GKE ã¯ã©ã¹ã¿ã«é©ç¨ãã¾ãããã
⯠kubectl delete -f ./v1alpha2/i-gw-httproute-split.yaml
httproute.networking.x-k8s.io "internal-httproute-split" deleted⯠kubectl apply -f ./v1alpha2/i-gw-httproute-rewrite.yaml
httproute.networking.x-k8s.io/internal-httproute-header-rewrite created
ããã§ã¯è©¦ãã¦ã¿ã¾ãããã
ãã®ãã¹ãç¨ã¢ããªã¯ /headers/HEADER_NAME ã«ã¢ã¯ã»ã¹ãããã¨ã§ãHEADER_NAME ã§æå®ãã Request header ã® value ãè¿ãã¦ããã¾ãã
ä¾ãã°ã
⯠curl -s -H "Host:i-gw.gcpx.org" http://192.168.5.34/headers/User-Agent
curl/7.68.0
ããã§ã¯å®éã«è©¦ãã¦ã¿ã¾ãã
Request header ã«ã¯ âmy-header:konnichiwaâ ãã»ãããã¾ãã
⯠curl -s -H "Host:i-gw.gcpx.org" -H "env:v2" -H "my-header:konnichiwa" http://192.168.5.34/headers/my-header
hello
æå¾ ã©ãããâkonnichiwaâ ã âhelloâ ã«æ¸ãæãã£ã¦ãããã¨ã確èªã§ãã¾ããã
LB ã®è¨å®ã§ãããããã§ã¹ãã§è¨å®ããéããRequest header ã®è¿½å ã¨åé¤ã LB ã«ãè¨å®ããã¦ãããã¨ãåããã¾ãã
⯠gcloud compute url-maps describe gkegw-0qzb-default-internal-gateway-mfrrz1j0tex3 --region asia-northeast1routeRules:
- headerAction:
requestHeadersToAdd:
- headerName: my-header
headerValue: hello
requestHeadersToRemove:
- my-header
matchRules:
- headerMatches:
- exactMatch: v2
headerName: env
prefixMatch: /
priority: 1
routeAction:
weightedBackendServices:
- backendService: https://www.googleapis.com/compute/v1/projects/kzs-sandbox/regions/asia-northeast1/backendServices/gkegw-0qzb-default-whereami-v2-8080-muarp2l4si2h
weight: 1
8. ã¾ã¨ã
å¦ä½ã§ããããããï¼
Gateway API ã®ç»å ´ã«ãããGKE ã® Ingress ã§ã¯å®ç¾åºæ¥ãªãã£ããHeader based routing ã Traffic split, Request header ã®æ¸ãæããªã©ãå¯è½ã«ãªããããå¹ åºãã¦ã¼ã¹ã±ã¼ã¹ã§ãå©ç¨é ããããã«ãªãã¾ããã
ã¾ããã¤ã³ãã©æ å½è ãã¢ããªéçºè ã®çããã®é¢å¿äºã«åããã¦ãªã½ã¼ã¹ãåå²ãããã¨ã«ãããããã¾ã§ä»¥ä¸ã«çããã®éç¨ç¾å ´ã«é©å¿ããããããªã£ãã®ã§ã¯ãªãã§ããããã
çããããæé許ãã°æ¯é触ã£ã¦ã¿ã¦ãã ããï¼
ãã£ã¼ãããã¯ããå¾
ã¡ãã¦ãã¾ãã
å°ãä»åã«ãã¼åºæ¥ãªãã£ã External multi-cluster gateway 㨠Internal multi-cluster gateway ã¯å¾æ¥ãè¨äºãæ¸ãã¾ãã®ã§ã楽ãã¿ã«ï¼
2022 å¹´ 1 æ 5 æ¥è¿½è¨:
Multi-cluster Gateway ã®è§£èª¬è¨äºãæ¸ãã¾ãããæ¯éã覧ãã ããã