Create an Amazon EKS cluster and deploy Docker containers
Amazon Elastic Kubernetes Service isn't hard to use, but you wouldn't know that from reading the vendor documentation.
This EKS tutorial aims to demystify AWS' managed Kubernetes service and show developers and admins just how easy it is to deploy a Docker container.
There are no long YAML files and no superfluous commands or status checks -- just nine commands that will do everything from creating an EKS cluster to exposing a deployment on a publicly accessible port.
How to create an EKS cluster
The following nine commands create an EKS cluster in AWS and deploy a Tomcat-hosted microservice built with React and Spring Boot.
The first command creates the cluster:
aws eks update-kubeconfig --region us-east-1 --name dad-jokes-dev-cluster
The next two commands deploy the container and expose it on port 80 at a publicly accessible URL:
kubectl create deployment dad-jokes-deployment --image=cameronmcnz/dad-jokes
kubectl expose deployment dad-jokes-deployment --name=dad-jokes-service --type=LoadBalancer --port=80 --target-port=80
The next four commands are annotations required for the AWS-based load balancer to understand which resources it must manage:
kubectl annotate service/dad-jokes-service service.beta.kubernetes.io/aws-load-balancer-type="external" --overwrite
kubectl annotate service/dad-jokes-service service.beta.kubernetes.io/aws-load-balancer-scheme="internet-facing" --overwrite
kubectl annotate service/dad-jokes-service service.beta.kubernetes.io/aws-load-balancer-backend-protocol="http" --overwrite
kubectl annotate service/dad-jokes-service service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout="60" --overwrite
How to access an EKS service
Finally, restart the deployment and retrieve the public URL generated by AWS to access the application:
kubectl rollout restart deployment dad-jokes-app
kubectl get svc dad-jokes-service
And that's it. If you run these nine commands and substitute in your container of choice, you'll have a fast, effective EKS deployment -- without writing a single line of YAML.
Cameron McKenzie has been a Java EE software engineer for 20 years. His current specialties include Agile development; DevOps; Spring; and container-based technologies such as Docker, Swarm and Kubernetes.