Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add pattern for Amazon VPC Lattice #1846

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dae1487
add vpc lattice pattern
Dec 14, 2023
f29f3a4
Add vpc lattice pattern
Dec 14, 2023
fe703c9
feat: Add pattern for Amazon VPC Lattice
Dec 14, 2023
ba79c8c
Merge branch 'main' into feature/add-vpc-lattice-pattern
valentinwidmer Dec 14, 2023
be99939
Add version constraint for null provider
Dec 14, 2023
15a4f6c
Small bugfixes and improvements
Dec 19, 2023
f65e7c7
Fix typo
Dec 19, 2023
aacc342
Merge branch 'main' into feature/add-vpc-lattice-pattern
valentinwidmer Dec 19, 2023
3d73dfc
Remove unused data source
Dec 19, 2023
39b20d5
Replace waiting condition and remove unused code blocks
Dec 21, 2023
4038685
Converted response image into code
Dec 21, 2023
d556fa0
Fix format issue
Dec 21, 2023
2de06d6
Add missing dependency
Dec 22, 2023
fc1bd85
chore(deps): Bump github/codeql-action from 3.22.11 to 3.22.12 (#1850)
dependabot[bot] Dec 22, 2023
be46054
chore(deps): Bump actions/dependency-review-action from 3.1.4 to 3.1.…
dependabot[bot] Jan 5, 2024
71e838e
chore(deps): Bump github/codeql-action from 3.22.12 to 3.23.0 (#1855)
dependabot[bot] Jan 9, 2024
fb7305b
chore(deps): Bump actions/upload-artifact from 4.0.0 to 4.1.0 (#1857)
dependabot[bot] Jan 15, 2024
cbd827c
fix: Change image path in blue/green pattern (#1856)
allamand Jan 15, 2024
6486035
Minor fixes and improvements
Jan 16, 2024
90deace
Re-run pre-commit hooks
Jan 16, 2024
afb29ae
using external-dns to create DNS records
allamand Jan 15, 2024
a6a4c42
Re-run pre-commit
Jan 16, 2024
fe90f4f
Update diagram for readme.md
Jan 16, 2024
4aa9701
Refactor folder structure to accomodate multiple patterns
Jan 19, 2024
5a4594f
Update gateway api controller to v1.0.3
Jan 22, 2024
87cfe64
Merge branch 'main' into feature/add-vpc-lattice-pattern
allamand Jan 22, 2024
62f879c
Rename subfolder and split TF resources into seperate files
Jan 23, 2024
081d611
Fix formatting issues
Jan 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/patterns/vpc-lattice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Amazon VPC Lattice
---

{%
include-markdown "../../patterns/vpc-lattice/README.md"
%}
14 changes: 14 additions & 0 deletions patterns/vpc-lattice/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Amazon VPC Lattice

This folder contains use case-driven patterns covering different aspects of the Amazon VPC Lattice service.

## Use cases

- [Simple Client to Server Communication](./client-server-communication/)

This pattern describes how to expose a simple API within an Amazon EKS cluster deployed in VPC A to a client application hosted in VPC B through Amazon VPC Lattice.

## Supporting resources

- [Documentation](https://docs.aws.amazon.com/vpc-lattice/latest/ug/what-is-vpc-lattice.html)
- [AWS Gateway API Controller](https://www.gateway-api-controller.eks.aws.dev/)
39 changes: 39 additions & 0 deletions patterns/vpc-lattice/client-server-communication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Amazon VPC Lattice - Simple Client to Server Communication

This pattern demonstrates how to expose an EKS cluster hosted application to an internal consumer through Amazon VPC Lattice.

## Scenario

With this soluton we showcase how to configure Amazon VPC Lattice using the AWS Gateway API Controller in order to manage Amazon VPC Lattice resources through native K8S Gateway API objects. This pattern deploys two distinct VPCs with a client application running in one of them and a server application in the other. The server application is deployed inside an EKS cluster and made exposed to the client application through Amazon VPC Lattice which establishes connectivity between the two applications. Further we demonstrate how to configure a custom domain name for the exposed service using Amazon Route53 and the external-dns project.

![diagram](assets/diagram.png)


## Deploy

See [here](https://aws-ia.github.io/terraform-aws-eks-blueprints/getting-started/#prerequisites) for the prerequisites and steps to deploy this pattern.

## Validate

In order to test the connectivty between the client and server, please follow the steps outlined below:

1. Login to the management console of your AWS account and navigate to the EC2 service
2. Select your the EC2 Instance with the name **client**, click **Connect**, choose **Session Manager** and click **Connect**
3. Within the console test the connecvity to the server application by entering the following command:

```sh
$ curl -i http://server.example.com
HTTP/1.1 200 OK
date: Thu, 14 Dec 2023 08:29:39 GMT
content-length: 54
content-type: text/plain; charset=utf-8

Requesting to Pod(server-6f487b9bcd-5qm4v): server pod

```

## Destroy

{%
include-markdown "../../../docs/_partials/destroy.md"
%}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v2
name: demo-application
description: A Helm chart to deploy the demo-application
type: application
version: 1.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: server
labels:
app: server
spec:
replicas: 2
selector:
matchLabels:
app: server
template:
metadata:
labels:
app: server
spec:
containers:
- name: server
image: public.ecr.aws/x2j8p8w7/http-server:latest
env:
- name: PodName
value: "server pod"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: gateway.networking.k8s.io/v1beta1
kind: GatewayClass
metadata:
name: amazon-vpc-lattice
spec:
controllerName: application-networking.k8s.aws/gateway-api-controller
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: gateway.networking.k8s.io/v1beta1
kind: Gateway
metadata:
name: my-services
namespace: apps
spec:
gatewayClassName: amazon-vpc-lattice
listeners:
- name: http
protocol: HTTP
port: 80
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: server
namespace: apps
spec:
hostnames:
- server.example.com
parentRefs:
- name: my-services
sectionName: http
rules:
- backendRefs:
- name: server
kind: Service
port: 8090
matches:
- path:
type: PathPrefix
value: /
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: server
spec:
selector:
app: server
ports:
- protocol: TCP
port: 8090
targetPort: 8090
102 changes: 102 additions & 0 deletions patterns/vpc-lattice/client-server-communication/client.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
################################################################################
# Client application (with private access over SSM Systems Manager)
################################################################################

module "client" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "5.5.0"

name = "client"

instance_type = "t2.micro"
subnet_id = module.client_vpc.private_subnets[0]
create_iam_instance_profile = true
iam_role_description = "IAM role for client"
iam_role_policies = {
AmazonSSMManagedInstanceCore = "arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore"
}
vpc_security_group_ids = [module.client_sg.security_group_id]

tags = local.tags
}

module "vpc_endpoints" {
source = "terraform-aws-modules/vpc/aws//modules/vpc-endpoints"
version = "~> 5.0"

vpc_id = module.client_vpc.vpc_id

endpoints = { for service in toset(["ssm", "ssmmessages", "ec2messages"]) :
replace(service, ".", "_") =>
{
service = service
subnet_ids = module.client_vpc.private_subnets
private_dns_enabled = true
tags = { Name = "${local.name}-${service}" }
}
}

security_group_ids = [module.endpoint_sg.security_group_id]

tags = local.tags
}

module "client_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 5.0"

name = "client"
description = "Security Group for EC2 Instance Egress"

vpc_id = module.client_vpc.vpc_id

egress_with_cidr_blocks = [
{
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = "0.0.0.0/0"

},
]

tags = local.tags
}

module "endpoint_sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 5.0"

name = "ssm-endpoint"
description = "Security Group for EC2 Instance Egress"

vpc_id = module.client_vpc.vpc_id

ingress_with_cidr_blocks = [for subnet in module.client_vpc.private_subnets_cidr_blocks :
{
from_port = 443
to_port = 443
protocol = "TCP"
cidr_blocks = subnet
}
]

tags = local.tags
}

################################################################################
# Client VPC
################################################################################

module "client_vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.4"

name = local.name
cidr = local.client_vpc_cidr

azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.client_vpc_cidr, 4, k)]

tags = local.tags
}
Loading