AWS EKS Microservice - Easy Setup
In this example we use
CodePipeline, CodeBuild, and ECR to build, test, publish, and deploy a simple microservice web app to our new Kubernetes cluster.
Check out our AWS EKS Kubernetes Cluster project to see how we use CloudFormation to spin up a new EKS Kubernetes cluster.
npm install -g cim
We use CodePipeline and CodeBuild to build, test, and deploy a new image to ECR on every commit so you will need to fork this repo into your account.
parameters:
AppName: 'eks-test'
GitHubOwner: 'thestacks-io'
GitHubRepo: 'eks-microservice'
GitHubToken: '${kms.decrypt(AQICAHgiu9XuQb...mJrnw==)}'
You will need to replace the GitHubOwner
, GitHubRepo
, and GitHubToken
. Follow the steps below to encrypt your GitHubToken
.
Encrypt Secrets:
In order to protect your configuration secrets like your GitHub token we need to create a KMS key first.
${kms.decrypt(<encreted string>)}
How to Encrypt:
Create a file called encrypt.json
{
"keyId" : "<your kms key id>",
"plainText": "<your client id>",
"awsRegion": "<aws region>",
"awsProfile": "<aws profile"
}
Use this command to perform the encryption : kms-cli encrypt --file encrypt.json
Deploy stack.
cim stack-up
Once an image is built and placed in ECR we can deploy our microservice.
Record the ECRUrl
stack output parameter because we will need it in the next step.
Update the eks-deployment.yml file and replace the <ecr-url>
and <image-version>
. Both of these can be found in your ECR console. The <image-version>
is the first 8 characters of the commit hash that triggered the new image.
Now that your eks-deployment.yml file is ready we can create the Kubernetes deployment.
Create the Kubernetes deployment:
kubectl create -f eks-deployment.yml
Check the status of your pods.
kubectl get pods
Create the Kubernetes service (Routing for pods)
kubectl create -f eks-service.yml
This will create a classic load balancer you can use to access your web app. You can also use the load balancer url to create a Route53 DNS route if you wish.
Get domain. It may take several minutes before the IP address is available.
kubectl get services -o wide
kubectl delete -f eks-service.yml
kubectl delete -f eks-deployment.yml
cim stack-delete