This repository contains AWS CDK code that deploys an EKS cluster as well as a kubernetes manifest to deploy a simple hello-world container into the provisioned EKS cluster.
- The pre-requisites required for using CDK can be found here: https://cdkworkshop.com/15-prerequisites.html
- Install kubectl: https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html
- Install jq: https://stedolan.github.io/jq/download/
-
Clone this repository locally.
-
Activate the Virtualenv by running the following commands:
python3 -m venv .venv source .venv/bin/activate -
Once the Virtualenv is activated, install the required dependencies.
pip install -r requirements.txt -
Set the required environment variables.
ACCOUNTis your AWS Account ID andREGIONis the AWS region that you are deploying into.export ACCOUNT=<ACCOUNT> export REGION=<REGION> -
Synthesize the CloudFormation template.
cdk synth --context ACCOUNT=$ACCOUNT --context REGION=$REGION -
Deploy the CDK Toolkit stack.
cdk bootstrap aws://$ACCOUNT/$REGION -
Deploy the stack. When prompted if you wish to deploy the changes, enter
yto deploy.cdk deploy -
When you have deployed the stack, you will see an output containing a command to update kubeconfig. Copy this command and execute it. If this command was executed successfully, you should receive a response similar to:
Updated context arn:aws:eks:<REGION>:<ACCOUNT_ID>:cluster/<CLUSTER_NAME> in ~/.kube/config -
Verify that you are now able to use kubectl by running:
kubectl get nodes -
Deploy the hello-world application into the cluster:
kubectl apply -f ./manifest.yaml -
Create a Service object to exposes the deployment:
kubectl expose deployment hello-world --type=LoadBalancer --name=load-balancer -
Get the external IP address and the port and navigate to the site to verify the service has been deployed successfully:
ADDRESS=$(kubectl get service load-balancer -o json | jq -r '.status.loadBalancer.ingress[].hostname') PORT=$(kubectl get service load-balancer -o json | jq -r '.spec.ports[].port') curl -v http://{$ADDRESS}:{$PORT}