Deployment Guide on AWS
This document explains how to deploy ScalarDB GraphQL servers on the Amazon EKS environment.
We will deploy multiple GraphQL servers to an EKS cluster with an AWS Load Balancer Controller, which manages an internal AWS Application Load Balancer. The AWS Application Load Balancer handles HTTP cookie-based session affinity. When we deploy multiple GraphQL servers, session affinity is required to handle transactions properly. This is because GraphQL servers keep the transactions in memory, so GraphQL queries that use continued transactions must be routed to the same server that started the transaction.
What we create
In this guide, we will create the following components.
- A VPC with NAT gateway
- An EKS cluster with a Kubernetes node group
- A managed database service
- A bastion instance with a public IP
- An internal ALB for load balancing HTTP requests using the AWS Load Balancer Controller.
Step 1. Configure an EKS cluster
Please follow steps 1 to 3 in the Deploy ScalarDL on AWS guide to set up a VPC, subnets, a bastion host, a database, an EKS cluster, and a node group.
Note: That guide instructs to add a label to the node group with a key agentpool
and a value scalardlpool
. However, since we will deploy GraphQL servers, not ScalarDL, we should change the label. For example, the node group can be labeled with a key agentpool
and a value scalardbgraphqlpool
. The label can be used to select nodes when deploying ScalarDB GraphQL servers.
In this document, a placeholder cluster name <your-cluster-name>
will be used in command examples. Please change it to your cluster name.
Step 2. Load Database Schema
We need to load a database schema to the database before starting ScalarDB GraphQL.
Here is an example for DynamoDB. For other databases and more detailed instructions, please refer to the ScalarDB Schema Loader.
-
Create a
database.properties
configuration file for DynamoDBscalar.db.contact_points=<AWS region>
scalar.db.username=<AWS access key ID>
scalar.db.password=<AWS secret access Key>
scalar.db.storage=dynamo -
Create a
schema.json
file. Please refer to the sample in the ScalarDB Schema Loader document. -
Load the schema to the database with ScalarDB Schema Loader
docker run --rm -v $PWD/schema.json:/schema.json \
-v $PWD/database.properties:/database.properties \
ghcr.io/scalar-labs/scalardb-schema-loader:3.5.2 \
-c /database.properties -f /schema.json --coordinator
Step 3. Install eksctl
Log in to the bastion host and install the eksctl
command by following the official documents.
We also need to install AWS CLI and configure AWS API credentials.
Step 4. Install the AWS Load Balancer Controller add-on to EKS
The AWS Load Balancer Controller is a controller to manage AWS Elastic Load Balancers for a Kubernetes cluster.
We use it to create an AWS Application Load Balancer (ALB) in front of multiple GraphQL servers in the cluster. When we create a Kubernetes Ingress resource in the cluster, the controller provisions an ALB according to it.
In this section, we will install the controller according to the official installation documents below.
- Installing the AWS Load Balancer Controller add-on - Amazon EKS
- Installation Guide - AWS Load Balancer Controller
Set up IAM Permissions
We need to set up IAM permissions before installing the AWS Load Balancer Controller so that the controller running on the worker nodes can manage ALBs on AWS.
-
Create IAM OpenID Connect (OIDC) provider
eksctl utils associate-iam-oidc-provider --cluster <your-cluster-name> --approve
In the AWS Management Console, we can see an IAM Identity provider has been created.
-
Download the IAM policy document for the AWS Load Balancer Controller
curl -o iam-policy.json https://raw.githubusercontent.com/kubernetes-sigs/aws-load-balancer-controller/v2.4.1/docs/install/iam_policy.json
-
Create an IAM policy named
AWSLoadBalancerControllerIAMPolicy
aws iam create-policy \
--policy-name AWSLoadBalancerControllerIAMPolicy \
--policy-document file://iam-policy.jsonPlease take note of the policy ARN created with the command, as we will specify it in the next step.
In the AWS Management Console, we can see an IAM Policy has been created.
-
Create an IAM role and ServiceAccount for the AWS Load Balancer controller
eksctl create iamserviceaccount \
--cluster=<your-cluster-name> \
--namespace=kube-system \
--name=aws-load-balancer-controller \
--attach-policy-arn=arn:aws:iam::<AWS account ID>:policy/AWSLoadBalancerControllerIAMPolicy \
--override-existing-serviceaccounts \
--approvePlease specify the policy ARN from the previous step as the
--attach-policy-arn
option.To check if the IAM service account has been created, run:
eksctl get iamserviceaccount --cluster=<your-cluster-name>
NAMESPACE NAME ROLE ARN
kube-system aws-load-balancer-controller arn:aws:iam::***:role/******In the AWS Management Console, we can see an IAM Role has been created and the policy is attached to it.
Add AWS Load Balancer Controller to Cluster
Now we can install the AWS Load Balancer Controller with Helm.
-
Add the EKS chart repo to helm
helm repo add eks https://aws.github.io/eks-charts
-
Install the helm chart
We need to specify both of the chart values
serviceAccount.create=false
andserviceAccount.name=aws-load-balancer-controller
since we have already created a service account namedaws-load-balancer-controller
in the previous section.helm install aws-load-balancer-controller \
eks/aws-load-balancer-controller -n kube-system \
--set clusterName=<your-cluster-name> \
--set serviceAccount.create=false \
--set serviceAccount.name=aws-load-balancer-controllerNote: If upgrading the chart using
helm upgrade
instead ofhelm install
, the TargetGroupBinding CRDs must be installed manually before running the previous command.kubectl apply -k "github.com/aws/eks-charts/stable/aws-load-balancer-controller//crds?ref=master"
-
Verify that the controller is installed
kubectl get deployment -n kube-system aws-load-balancer-controller
NAME READY UP-TO-DATE AVAILABLE AGE
aws-load-balancer-controller 2/2 2 2 11s