Want to run your Docker container on Kubernetes in AWS without crying into your keyboard? This guide walks through creating an EKS cluster with eksctl then deploying a Docker image with kubectl. You will configure AWS credentials, build and push images to ECR or another registry, apply a deployment manifest, expose the app, and clean up the cloud mess when you are done. Keywords you should feel guilty about using are EKS Kubernetes Docker eksctl kubectl AWS ECR k8s deployment manifest container deployment.
Install these tools on your workstation and make sure your AWS profile has EKS permissions. If you try to skip this step a heroic cascade of error messages will be your reward.
eksctl is the fastest route to a managed EKS cluster. It provisions the control plane and a managed node group on your behalf. Keep your patience and a reasonable node size while testing.
eksctl create cluster --name demo-cluster --region us-west-2 --nodes 2
Wait for the command to finish. When it does your kubeconfig will be updated and kubectl will talk to the new cluster.
Because it hides the boilerplate and creates VPC networking node groups and IAM roles in one command. Yes it does a lot so watch the output and check the AWS console if you want to feel powerful.
Build a container locally then push to a registry that your cluster can access. Amazon ECR is convenient for EKS but Docker Hub or any private registry will do.
docker build -t myapp latest .
docker tag myapp latest 123456789012.dkr.ecr.us-west-2.amazonaws.com/myapp latest
# Authenticate to ECR and push
aws ecr get-login-password | docker login --username AWS --password-stdin 123456789012.dkr.ecr.us-west-2.amazonaws.com
docker push 123456789012.dkr.ecr.us-west-2.amazonaws.com/myapp latest
Replace the account id and region with your values. Yes the tag syntax looks odd here but follow the pattern your registry expects.
Write a small deployment YAML that points to your pushed image. This is the deployment manifest that tells k8s to run your container.
apiVersion apps/v1
kind Deployment
metadata:
name myapp
spec:
replicas 2
selector:
matchLabels:
app myapp
template:
metadata:
labels:
app myapp
spec:
containers:
- name myapp
image 123456789012.dkr.ecr.us-west-2.amazonaws.com/myapp latest
ports:
- containerPort 8080
Apply the manifest with kubectl.
kubectl apply -f deployment.yaml
The cluster will create pods and pull the image from your registry. Use kubectl get pods to watch the status.
Use a LoadBalancer service for a quick external IP or NodePort for a network nerd challenge.
kubectl expose deployment myapp --type LoadBalancer --port 80 --target-port 8080
kubectl get svc
kubectl get pods
When the service has an external endpoint hit it with curl or your browser. If pods stay in ImagePullBackOff double check registry auth and image names.
When you are done delete the cluster and any ECR repos you created. eksctl makes deletion easy and dramatic.
eksctl delete cluster --name demo-cluster
Pro tip use small test node groups to save money and shame. If something breaks the logs with kubectl logs and kubectl describe are your best friends. Now go deploy something and try not to break production on your first commit.
I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!
This is a dedicated watch page for a single video.