
API 版本控制策略的 4 個最佳實踐
帶有 K8s Gateway API 演示設置的多集群、多云網關
在主集群和遠程集群上部署helloworld-service :
kubectl -f 應用 helloworld-service.yaml --context=eks-cluster
kubectl -f 應用 helloworld-service.yaml --context=gke-cluster
1
將helloworld-deployment-v1 部署到主集群/EKS,將helloworld-deployment-v2 部署到遠程集群/GKE:
kubectl -f 應用 helloworld-deployment-v1.yaml --context=eks-cluster
kubectl -f 應用 helloworld-deployment-v2.yaml --context=gke-cluster
在兩個集群中 部署echoserver-service ,并僅在遠程集群中 部署 echoserver-deployment :
kubectl -f 應用 echoserver-service.yaml --context=eks-cluster
kubectl -f 應用 echoserver-service.yaml --context=gke-cluster
kubectl -f 應用 echoserver-deployment.yaml --context=gke-cluster
請注意,要實現此功能,需要在兩個集群中部署服務資源。這就是為什么我將其部署echoserver-service
在主集群/EKS 中,盡管部署僅在遠程集群/GKE 中。
現在,讓我們驗證主集群和輔助集群中的部署:
kubectl 獲取 svc -n demo --context=eks-cluster
kubectl 獲取 pods -n demo --context=eks-cluster
kubectl 獲取 svc -n demo --context=gke-cluster
kubectl 獲取 pods -n demo --context=gke-cluster
主集群中有helloworld-v1
pod 正在運行,而遠程集群中有helloworld-v2
和echoserver
pod 均成功運行:
在主/EKS集群中應用網關資源:
kubectl apply -f gateway-api-gateway.yaml --context=eks-cluster
Gateway使用Istio作為控制器,部署在istio-ingress
命名空間中。
在應用程序的主集群中部署HTTPRoutehelloworld
,監聽路徑/hello:
kubectl apply -f helloworld-httproute.yaml --context=eks-cluster
現在,讓我們通過 curlhelloworld
應用程序來驗證多集群通信;但首先,我們需要獲取網關 IP:
kubectl 獲取 svc -n istio-ingress --context=eks-cluster
驗證多集群通信:
curl yours ip/hello
您可以看到該請求分別由部署在主集群和輔集群中的helloworld-v1
和提供服務。helloworld-v2
現在,讓我們在主集群中部署echoserver 的 HTTPRoute,它監聽/ :
kubectl apply -f echoserver-httproute.yaml --context=eks-cluster
驗證網關是否能夠訪問echoserver
部署在遠程集群:
網關能夠echoserver
成功從部署在遠程集群的服務器收到響應。演示到此結束。
原文鏈接:https://dzone.com/articles/multicluster-gateways-with-kubernetes-gateway-api