|
| 1 | +# Using the AWS Gateway API Controller |
| 2 | + |
| 3 | +The first part of this section provides an example of setting up of service-to-service communications on a single cluster. |
| 4 | +The second section extends that example by creating another inventory service on a second cluster on a different VPC, and spreading traffic to that service across the two clusters and VPCs. |
| 5 | +Both clusters are created using `eksctl`, with both clusters created from the same account by the same cluster admin. |
| 6 | + |
| 7 | +## Set up single-cluster/VPC service-to-service communications |
| 8 | + |
| 9 | +This example creates a single cluster in a single VPC, then configures two routes (rates and inventory) and three services (parking, review, and inventory-1). The following figure illustrates this setup: |
| 10 | + |
| 11 | + |
| 12 | + |
| 13 | +**Steps** |
| 14 | + |
| 15 | + **Set up Service-to-Service communications** |
| 16 | + |
| 17 | +1. Create the Kubernetes Gateway `my-hotel`: |
| 18 | + ```bash |
| 19 | + kubectl apply -f examples/my-hotel-gateway.yaml |
| 20 | + ``` |
| 21 | +1. Verify that `my-hotel` gateway is created (this could take about five minutes): |
| 22 | + ```bash |
| 23 | + kubectl get gateway |
| 24 | + ``` |
| 25 | + ``` |
| 26 | + NAME CLASS ADDRESS READY AGE |
| 27 | + my-hotel aws-lattice 7d12h |
| 28 | + ``` |
| 29 | +1. Once the gateway is created, find the VPC Lattice service network: |
| 30 | + ```bash |
| 31 | + kubectl get gateway my-hotel -o yaml |
| 32 | + ``` |
| 33 | + ``` |
| 34 | + apiVersion: gateway.networking.k8s.io/v1alpha2 |
| 35 | + kind: Gateway |
| 36 | + ... |
| 37 | + status: |
| 38 | + conditions: |
| 39 | + message: 'aws-gateway-arn: arn:aws:vpc-lattice:us-west-2:694065802095:servicenetwork/sn-0ab6bb70055929edd' |
| 40 | + reason: Reconciled |
| 41 | + status: "True" |
| 42 | + ``` |
| 43 | +1. Create the Kubernetes HTTPRoute rates for the parking service, review service, and HTTPRoute rate: |
| 44 | + ```bash |
| 45 | + kubectl apply -f examples/parking.yaml |
| 46 | + kubectl apply -f examples/review.yaml |
| 47 | + kubectl apply -f examples/rate-route-path.yaml |
| 48 | + ``` |
| 49 | +1. Create the Kubernetes HTTPRoute inventory (this could take about five minutes): |
| 50 | + ```bash |
| 51 | + kubectl apply -f examples/inventory-ver1.yaml |
| 52 | + kubectl apply -f examples/inventory-route.yaml |
| 53 | + ``` |
| 54 | +1. Find out HTTPRoute's DNS name from HTTPRoute status: |
| 55 | + ```bash |
| 56 | + kubectl get httproute |
| 57 | + ``` |
| 58 | + ``` |
| 59 | + NAME HOSTNAMES AGE |
| 60 | + inventory 51s |
| 61 | + rates 6m11s |
| 62 | + ``` |
| 63 | +1. List the route’s yaml file to see the DNS address (highlighted here on the `message` line): |
| 64 | + |
| 65 | + ```bash |
| 66 | + kubectl get httproute inventory -o yaml |
| 67 | + ``` |
| 68 | + |
| 69 | + ``` |
| 70 | + apiVersion: gateway.networking.k8s.io/v1alpha2 |
| 71 | + kind: HTTPRoute |
| 72 | + metadata: |
| 73 | + annotations: |
| 74 | + kubectl.kubernetes.io/last-applied-configuration: | |
| 75 | + {"apiVersion":"gateway.networking.k8s.io/v1alpha2","kind":"HTTPRoute","metadata":{"annotations":{},"name":"inventory","namespace":"default"}... }}]}]}} |
| 76 | + ... |
| 77 | + status: |
| 78 | + parents: |
| 79 | + - conditions: |
| 80 | + - lastTransitionTime: "2022-11-22T02:29:22Z" |
| 81 | + message: 'DNS Name: <b><i>inventory-default-0f326944c3d681c0d.7d67968.vpc-lattice-svcs.us-west-2.on.aws</i></b>' |
| 82 | + reason: Reconciled |
| 83 | + status: "True" |
| 84 | + type: httproute |
| 85 | + controllerName: application-networking.k8s.aws/gateway-api-controller |
| 86 | + parentRef: |
| 87 | + group: gateway.networking.k8s.io |
| 88 | + kind: Gateway |
| 89 | + name: my-hotel |
| 90 | + ... |
| 91 | + ``` |
| 92 | + |
| 93 | + ```bash |
| 94 | + kubectl get httproute rates inventory -o yaml |
| 95 | + ``` |
| 96 | + |
| 97 | +**Check service connectivity** |
| 98 | + |
| 99 | +1. Check Service-Inventory Pod access for Service-Rates/parking or Service-Rates/review by execing into the pod, then curling each service. |
| 100 | + ```bash |
| 101 | + kubectl get pod |
| 102 | + ``` |
| 103 | + ``` |
| 104 | + NAME READY STATUS RESTARTS AGE |
| 105 | + inventory-ver1-7bb6989d9d-2p2hk 1/1 Running 0 7d13h |
| 106 | + inventory-ver1-7bb6989d9d-464rk 1/1 Running 0 7d13h |
| 107 | + parking-6cdcd5b4b4-bbzvt 1/1 Running 0 103m |
| 108 | + parking-6cdcd5b4b4-g8dkb 1/1 Running 0 103m |
| 109 | + review-5888566ff6-2plsj 1/1 Running 0 101m |
| 110 | + review-5888566ff6-89fqk 1/1 Running 0 101m |
| 111 | + ``` |
| 112 | +1. Exec into an inventory pod to check connectivity to parking and review services: |
| 113 | + ```bash |
| 114 | + kubectl exec -ti inventory-ver1-7bb6989d9d-2p2hk sh |
| 115 | + ``` |
| 116 | +1. From inside of the inventory pod, use `curl` to connect to the parking service (using the DNS Name from the previous `kubectl get httproute` command): |
| 117 | + ```bash |
| 118 | + curl rates-00422586e3362607e.7d67968.vpc-service-network-svcs.us-west-2.amazonaws.com/parking |
| 119 | + ``` |
| 120 | + ``` |
| 121 | + Requesting to Pod(parking-6cdcd5b4b4-g8dkb): parking handler pod |
| 122 | + ``` |
| 123 | +1. From inside of the pod, use `curl` to connect to the review service: |
| 124 | + ```bash |
| 125 | + curl rates-00422586e3362607e.7d67968.vpc-service-network-svcs.us-west-2.amazonaws.com/review |
| 126 | + ``` |
| 127 | + ``` |
| 128 | + Requesting to Pod(review-5888566ff6-89fqk): review handler pod |
| 129 | + ``` |
| 130 | +1. Exit the pod: |
| 131 | + ```bash |
| 132 | + exit |
| 133 | + ``` |
| 134 | +1. Exec into a parking pod to check connectivity to the inventory-ver1 service: |
| 135 | + ```bash |
| 136 | + kubectl exec -ti parking-6cdcd5b4b4-bbzvt sh |
| 137 | + ``` |
| 138 | +1. From inside of the parking pod, use `curl` to connect to the inventory-ver1 service: |
| 139 | + ```bash |
| 140 | + curl inventory-00422586e3362607e.7d67968.vpc-service-network-svcs.us-west-2.amazonaws.com |
| 141 | + ``` |
| 142 | + ``` |
| 143 | + Requesting to Pod(inventory-ver1-7bb6989d9d-2p2hk): inventory-ver1 handler pod |
| 144 | + ``` |
| 145 | +## Set up multi-cluster/multi-VPC service-to-service communications |
| 146 | + |
| 147 | +This sections builds on the previous section by migrating a Kubernetes service (HTTPRoute inventory) from one Kubernetes cluster to a different Kubernetes cluster. |
| 148 | +For example, it will: |
| 149 | + |
| 150 | +* Migrate the Kubernetes inventory service from a Kubernetes v1.21 cluster to a Kubernetes v1.23 cluster in a different VPC. |
| 151 | +* Scale up the Kubernetes inventory service to run it in another cluster (and another VPC) in addition to the current cluster. |
| 152 | + |
| 153 | +The following figure illustrates this: |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | +**Steps** |
| 158 | + |
| 159 | + **Set up inventory on a second cluster** |
| 160 | + |
| 161 | +1. Create a second cluster (using the same instructions used to create the first). |
| 162 | + |
| 163 | +1. Ensure you're using the second cluster profile. |
| 164 | + ```bash |
| 165 | + kubectl config get-contexts |
| 166 | + ``` |
| 167 | + If your profile is set to the first cluster, switch your credentials to use the second cluster: |
| 168 | + ```bash |
| 169 | + kubectl config use-context <yourcluster2info> |
| 170 | + ``` |
| 171 | +1. Create a Kubernetes inventory-ver2 service in the second cluster: |
| 172 | + ```bash |
| 173 | + kubectl apply -f examples/inventory-ver2.yaml |
| 174 | + ``` |
| 175 | +1. Export this Kubernetes inventory-ver2 from the second cluster, so that it can be referenced by HTTPRoute in the other cluster: |
| 176 | + ```bash |
| 177 | + kubectl apply -f examples/inventory-ver2-export.yaml |
| 178 | + ``` |
| 179 | + **Switch back to the first cluster** |
| 180 | + |
| 181 | +1. Switch credentials back to the first cluster |
| 182 | + ```bash |
| 183 | + kubectl config use-context <yourcluster1info> |
| 184 | + ``` |
| 185 | +1. Import the Kubernetes inventory-ver2 into first cluster: |
| 186 | + ```bash |
| 187 | + kubectl apply -f examples/inventory-ver2-import.yaml |
| 188 | + ``` |
| 189 | +1. Update the HTTPRoute inventory to route 10% traffic to the first cluster and 90% traffic to the second cluster: |
| 190 | + ```bash |
| 191 | + kubectl apply -f examples/inventory-route-bluegreen.yaml |
| 192 | + ``` |
| 193 | +1. Check the Service-Rates/parking pod access to Service-Inventory by execing into the parking pod: |
| 194 | + ```bash |
| 195 | + kubectl exec -ti parking-6cdcd5b4b4-bbzvt sh |
| 196 | + ``` |
| 197 | +1. From inside of the pod, use `curl` to connect to the inventory service: |
| 198 | + |
| 199 | + ```bash |
| 200 | + for ((i=1;i<=30;i++)); do curl "inventory-default-0f89d8ff5e98400d0.7d67968.vpc-lattice-svcs.us-west-2.on.aws"; done |
| 201 | + ``` |
| 202 | + ``` |
| 203 | + Requsting to Pod(inventory-ver2-6dc74b45d8-rlnlt): Inventory-ver2 handler pod <----> in 2nd cluster |
| 204 | + Requsting to Pod(inventory-ver2-6dc74b45d8-rlnlt): Inventory-ver2 handler pod |
| 205 | + Requsting to Pod(inventory-ver2-6dc74b45d8-rlnlt): Inventory-ver2 handler pod |
| 206 | + Requsting to Pod(inventory-ver2-6dc74b45d8-rlnlt): Inventory-ver2 handler pod |
| 207 | + Requsting to Pod(inventory-ver2-6dc74b45d8-95rsr): Inventory-ver1 handler pod <----> in 1st cluster |
| 208 | + Requsting to Pod(inventory-ver2-6dc74b45d8-rlnlt): Inventory-ver2 handler pod |
| 209 | + Requsting to Pod(inventory-ver2-6dc74b45d8-95rsr): Inventory-ver2 handler pod |
| 210 | + Requsting to Pod(inventory-ver2-6dc74b45d8-95rsr): Inventory-ver2 handler pod |
| 211 | + Requsting to Pod(inventory-ver1-74fc59977-wg8br): Inventory-ver1 handler pod.... |
| 212 | + ``` |
| 213 | + You can see that the traffic is distributed between *inventory-ver1* and *inventory-ver2* as expected. |
0 commit comments