Skip to main content

Provisioning ACK resources

By default, the Carts component in the sample application uses a DynamoDB local instance running as a pod in the EKS cluster called carts-dynamodb. In this section of the lab, we'll provision an Amazon DynamoDB cloud-based table for our application using Kubernetes custom resources and configure the Carts deployment to use this newly provisioned DynamoDB table instead of the local copy.

ACK reconciler concept

Let's examine how we can create the DynamoDB Table using a Kubernetes manifest:

~/environment/eks-workshop/modules/automation/controlplanes/ack/dynamodb/dynamodb-create.yaml
apiVersion: dynamodb.services.k8s.aws/v1alpha1
kind: Table
metadata:
name: items
namespace: carts
spec:
keySchema:
- attributeName: id
keyType: HASH
attributeDefinitions:
- attributeName: id
attributeType: "S"
- attributeName: customerId
attributeType: "S"
billingMode: PAY_PER_REQUEST
tableName: "${EKS_CLUSTER_NAME}-carts-ack"
globalSecondaryIndexes:
- indexName: idx_global_customerId
keySchema:
- attributeName: customerId
keyType: HASH
- attributeName: id
keyType: RANGE
projection:
projectionType: "ALL"

info

Keen observers will notice that the YAML specification closely resembles the API signature for DynamoDB, including familiar fields such as tableName and attributeDefinitions.

Now, let's apply these updates to the cluster:

~$kubectl kustomize ~/environment/eks-workshop/modules/automation/controlplanes/ack/dynamodb \
| envsubst | kubectl apply -f-
table.dynamodb.services.k8s.aws/items created

The ACK controllers in the cluster will respond to these new resources and provision the AWS infrastructure we've defined in the manifests. To verify that ACK has created the table, run the following command:

~$kubectl wait table.dynamodb.services.k8s.aws items -n carts --for=condition=ACK.ResourceSynced --timeout=15m
table.dynamodb.services.k8s.aws/items condition met
~$kubectl get table.dynamodb.services.k8s.aws items -n carts -ojson | yq '.status."tableStatus"'
ACTIVE

Finally, let's confirm that the table has been created using the AWS CLI:

~$aws dynamodb list-tables
 
{
    "TableNames": [
        "eks-workshop-carts-ack"
    ]
}

This output confirms that our new table has been successfully created!

By leveraging ACK, we've seamlessly provisioned a cloud-based DynamoDB table directly from our Kubernetes cluster, demonstrating the power and flexibility of this approach to managing AWS resources.