Skip to content

Commit 4a03d6c

Browse files
authored
new: Added Gateway API lab (#1852)
1 parent 2be9ad9 commit 4a03d6c

32 files changed

Lines changed: 876 additions & 4 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,4 @@ devenv.local.nix
5353

5454
# direnv
5555
.direnv
56+
.kiro/

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,12 @@ pre-provision:
5656

5757
.PHONY: create-infrastructure
5858
create-infrastructure:
59+
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
5960
bash hack/create-infrastructure.sh $(environment) $(cluster)
6061

6162
.PHONY: destroy-infrastructure
6263
destroy-infrastructure:
64+
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
6365
bash hack/destroy-infrastructure.sh $(environment) $(cluster)
6466

6567
.PHONY: deploy-ide

hack/create-infrastructure.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ else
4040
echo "Auto mode cluster ${EKS_CLUSTER_AUTO_NAME} already exists"
4141
fi
4242

43-
for pid in "${pids[@]}"; do
44-
wait "$pid" || exit 1
45-
done
43+
if [ ${#pids[@]} -gt 0 ]; then
44+
for pid in "${pids[@]}"; do
45+
wait "$pid" || exit 1
46+
done
47+
fi
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Delete Gateway API resources BEFORE uninstalling the controller
6+
# so the LBC can clean up the ALB and target groups
7+
if kubectl api-resources --api-group=gateway.networking.k8s.io -o name 2>/dev/null | grep -q httproute; then
8+
kubectl delete httproute --all -A --ignore-not-found
9+
kubectl delete gateway --all -A --ignore-not-found --wait=false
10+
kubectl delete gatewayclass --all --ignore-not-found --wait=false
11+
fi
12+
13+
# Delete AWS LBC Gateway CRDs resources
14+
if kubectl api-resources --api-group=gateway.k8s.aws -o name 2>/dev/null | grep -q targetgroupconfiguration; then
15+
kubectl delete targetgroupconfiguration --all -A --ignore-not-found
16+
kubectl delete loadbalancerconfiguration --all -A --ignore-not-found
17+
kubectl delete listenerruleconfiguration --all -A --ignore-not-found
18+
fi
19+
20+
# Wait for Gateways to be fully removed (finalizers cleared by LBC)
21+
echo "Waiting for Gateway resources to be cleaned up..."
22+
timeout 120 bash -c 'while kubectl get gateway -A 2>/dev/null | grep -q .; do sleep 5; done' || true
23+
24+
# Force-remove finalizers if still stuck
25+
for gw in $(kubectl get gateway -A -o jsonpath='{range .items[*]}{.metadata.namespace}/{.metadata.name}{"\n"}{end}' 2>/dev/null); do
26+
ns=$(echo $gw | cut -d/ -f1)
27+
name=$(echo $gw | cut -d/ -f2)
28+
kubectl patch gateway $name -n $ns --type=merge -p '{"metadata":{"finalizers":[]}}' 2>/dev/null || true
29+
done
30+
kubectl delete gateway --all -A --ignore-not-found 2>/dev/null || true
31+
kubectl delete gatewayclass --all --ignore-not-found 2>/dev/null || true
32+
33+
# Now uninstall the controllers
34+
uninstall-helm-chart aws-load-balancer-controller kube-system
35+
36+
# Clean up CRDs
37+
kubectl delete -f https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/refs/heads/main/config/crd/gateway/gateway-crds.yaml --ignore-not-found 2>/dev/null || true
38+
kubectl delete -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.2.0/standard-install.yaml --ignore-not-found 2>/dev/null || true
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
resource "terraform_data" "gateway_api_crds" {
2+
provisioner "local-exec" {
3+
command = "kubectl apply --server-side=true -f https://github.com/kubernetes-sigs/gateway-api/releases/download/${var.gateway_api_version}/standard-install.yaml"
4+
}
5+
}
6+
7+
resource "terraform_data" "lbc_gateway_crds" {
8+
provisioner "local-exec" {
9+
command = "kubectl apply -f https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/refs/heads/main/config/crd/gateway/gateway-crds.yaml"
10+
}
11+
12+
depends_on = [terraform_data.gateway_api_crds]
13+
}
14+
15+
module "eks_blueprints_addons" {
16+
source = "aws-ia/eks-blueprints-addons/aws"
17+
version = "1.23.0"
18+
19+
cluster_name = var.addon_context.eks_cluster_id
20+
cluster_endpoint = var.addon_context.aws_eks_cluster_endpoint
21+
cluster_version = var.eks_cluster_version
22+
oidc_provider_arn = var.addon_context.eks_oidc_provider_arn
23+
24+
enable_aws_load_balancer_controller = true
25+
aws_load_balancer_controller = {
26+
role_name = "${var.addon_context.eks_cluster_id}-alb-controller"
27+
policy_name = "${var.addon_context.eks_cluster_id}-alb-controller"
28+
}
29+
30+
create_kubernetes_resources = false
31+
32+
observability_tag = null
33+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
output "environment_variables" {
2+
description = "Environment variables to be added to the IDE shell"
3+
value = {
4+
LBC_CHART_VERSION = var.load_balancer_controller_chart_version
5+
LBC_ROLE_ARN = module.eks_blueprints_addons.aws_load_balancer_controller.iam_role_arn
6+
}
7+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# tflint-ignore: terraform_unused_declarations
2+
variable "eks_cluster_id" {
3+
description = "EKS cluster name"
4+
type = string
5+
}
6+
7+
# tflint-ignore: terraform_unused_declarations
8+
variable "eks_cluster_version" {
9+
description = "EKS cluster version"
10+
type = string
11+
}
12+
13+
# tflint-ignore: terraform_unused_declarations
14+
variable "cluster_security_group_id" {
15+
description = "EKS cluster security group ID"
16+
type = any
17+
}
18+
19+
# tflint-ignore: terraform_unused_declarations
20+
variable "addon_context" {
21+
description = "Addon context that can be passed directly to blueprints addon modules"
22+
type = any
23+
}
24+
25+
# tflint-ignore: terraform_unused_declarations
26+
variable "tags" {
27+
description = "Tags to apply to AWS resources"
28+
type = any
29+
}
30+
31+
# tflint-ignore: terraform_unused_declarations
32+
variable "resources_precreated" {
33+
description = "Have expensive resources been created already"
34+
type = bool
35+
}
36+
37+
variable "load_balancer_controller_chart_version" {
38+
description = "The chart version of aws-load-balancer-controller to use"
39+
type = string
40+
# renovate-helm: depName=aws-load-balancer-controller
41+
default = "3.3.0"
42+
}
43+
44+
# tflint-ignore: terraform_unused_declarations
45+
variable "inbound_cidrs" {
46+
description = "CIDR range to allowlist for inbound traffic"
47+
type = string
48+
}
49+
50+
variable "gateway_api_version" {
51+
description = "The version of gateway-api CRDs to install"
52+
type = string
53+
default = "v1.2.0"
54+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: ui-v2
5+
namespace: ui
6+
labels:
7+
app.kubernetes.io/name: ui
8+
app.kubernetes.io/version: v2
9+
app.kubernetes.io/component: service
10+
app.kubernetes.io/created-by: eks-workshop
11+
spec:
12+
replicas: 1
13+
selector:
14+
matchLabels:
15+
app.kubernetes.io/name: ui
16+
app.kubernetes.io/version: v2
17+
template:
18+
metadata:
19+
labels:
20+
app.kubernetes.io/name: ui
21+
app.kubernetes.io/version: v2
22+
spec:
23+
containers:
24+
- name: ui
25+
image: public.ecr.aws/aws-containers/retail-store-sample-ui:1.2.1
26+
ports:
27+
- containerPort: 8080
28+
protocol: TCP
29+
env:
30+
- name: RETAIL_UI_THEME
31+
value: "orange"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: ui-route
5+
namespace: ui
6+
spec:
7+
parentRefs:
8+
- name: retail-store-gateway
9+
namespace: ui
10+
rules:
11+
- matches:
12+
- path:
13+
type: PathPrefix
14+
value: /
15+
backendRefs:
16+
- name: ui
17+
port: 80
18+
weight: 0
19+
- name: ui-v2
20+
port: 8080
21+
weight: 100
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: gateway.networking.k8s.io/v1
2+
kind: HTTPRoute
3+
metadata:
4+
name: ui-route
5+
namespace: ui
6+
spec:
7+
parentRefs:
8+
- name: retail-store-gateway
9+
namespace: ui
10+
rules:
11+
- matches:
12+
- path:
13+
type: PathPrefix
14+
value: /
15+
backendRefs:
16+
- name: ui
17+
port: 80
18+
weight: 50
19+
- name: ui-v2
20+
port: 8080
21+
weight: 50

0 commit comments

Comments
 (0)