GCP의 대표적인 Serverless 제품은 Cloud Functions, Cloud Run, App Engine이 있습니다.
이 Serverless 제품을 사용 시 보안 등의 이유로 Outbound IP를 고정 IP로 사용해야할 필요가 있을 수 있습니다.
Serverless VPC Access Connector를 사용하여 이러한 Serverless 제품들의 IP를 고정할 수 있습니다.
※ App Engine Flexible, Cloud Run for Anthos 환경에서는 지원되지 않습니다.
위 아키텍쳐를 구성하는 방법은 아래와 같습니다.
1. Serverless VPC Access Connector 리소스를 위한 Subnet을 생성합니다.
- gcloud compute networks subnets create SUBNET_NAME \
--range=RANGE --network=NETWORK_NAME --region=REGION
2. Serverless VPC Access Connector를 생성합니다.
- gcloud compute networks vpc-access connectors create CONNECTOR_NAME \
--region=REGION \
--subnet-project=PROJECT_ID \
--subnet=SUBNET_NAME
3. Cloud NAT를 생성합니다.
- gcloud compute routers create ROUTER_NAME \
--network=NETWORK_NAME \
--region=REGION
고정 IP 주소를 예약합니다.
- gcloud compute addresses create ORIGIN_IP_NAME --region=REGION
위 고정 IP 주소를 사용하여 Router 생성 및 NAT G/W를 구성합니다.
- gcloud compute routers nats create NAT_NAME \
--router=ROUTER_NAME \
--region=REGION \
--nat-custom-subnet-ip-ranges=SUBNET_NAME \
--nat-external-ip-pool=ORIGIN_IP_NAME
4. 이제 각 서버리스 제품에서 이그레스 트래픽을 위에 생성한 Serverless VPC Access Connector 를 통해 라우팅 하도록 변경합니다.
Serverless VPC Access Connector의 가격정책에 대해서는 해당 문서를 참고하시기 바랍니다.