Amazon Elastic Kubernetes Service (EKS) is a fully-managed Kubernetes service that makes it easier to run Kubernetes on AWS. EKS is designed to be highly available and scalable, so you can deploy and manage your containers with confidence. In this tutorial, we will go through the steps required to set up and deploy a sample application on EKS.
Before we get started, you will need the following:
To create the EKS Cluster, you will need to execute the following commands:
aws eks create-cluster --name sample-cluster --role-arn Role-ARN --resources-vpc-config subnetIds=Subnet-IDs --region Region
Here, you will need to replace the Role-ARN
, Subnet-IDs
, and Region
with the values specific to your AWS account. This command will create the EKS Cluster.
Next, you will need to create the Kubernetes config file:
apiVersion: v1 kind: Config clusters: - name: sample-cluster cluster: server: EKS-Endpoint certificate-authority-data: Certificate-Authority-Data contexts: - name: sample-context context: cluster: sample-cluster user: aws namespace: default users: - name: aws user: exec: apiVersion: client.authentication.k8s.io/v1alpha1 command: aws-iam-authenticator args: - "token" - "-i" - "Your-Cluster-Name>" current-context: sample-context
Here, you will need to replace EKS-Endpoint
, Certificate-Authority-Data
, and Your-Cluster-Name
with the values specific to your AWS account. This file will allow you to connect to and manage your EKS Cluster.
To create the worker nodes in EKS, you will need to create a CloudFormation stack using the following command:
aws cloudformation create-stack --stack-name sample-cluster-worker-nodes --template-url https://amazon-eks.s3-us-west-2.amazonaws.com/cloudformation/2018-12-10/amazon-eks-nodegroup.yaml --capabilities CAPABILITY_IAM --parameters ParameterKey=NodeGroupName,ParameterValue=sample-cluster-worker-nodes ParameterKey=NodeAutoScalingGroupMinSize,ParameterValue=1 ParameterKey=NodeAutoScalingGroupDesiredCapacity,ParameterValue=2 ParameterKey=ClusterControlPlaneSecurityGroup,ParameterValue=Security-Group-ID ParameterKey=NodeSecurityGroup,ParameterValue=Security-Group-ID ParameterKey=NodeInstanceType,ParameterValue=Instance-Type ParameterKey=NodeImageId,ParameterValue=AMI-ID ParameterKey=KeyName,ParameterValue=Key-Pair-Name ParameterKey=VpcId,ParameterValue=VPC-ID ParameterKey=Subnets,ParameterValue=Comma-Separated-Subnets-IDs --region Region
Here, you will need to replace the Security-Group-ID
, Instance-Type
, AMI-ID
, Key-Pair-Name
, VPC-ID
, Comma-Separated-Subnets-IDs
, and Region
with the values specific to your AWS account. This will launch the worker nodes and configure them to join the EKS Cluster.
We will deploy the sample application using the Kubernetes Deployment and Service manifests:
apiVersion: apps/v1 kind: Deployment metadata: name: sample-app spec: replicas: 2 selector: matchLabels: app: sample-app template: metadata: labels: app: sample-app spec: containers: - name: sample-app image: nginx ports: - containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: sample-app spec: selector: app: sample-app ports: - name: http port: 80 targetPort: 80
Save this into a file called sample-app.yaml
, and execute the command:
kubectl apply -f sample-app.yaml
This will deploy the sample application and create a LoadBalancer service, which will expose the application outside the EKS Cluster.
Amazon Elastic Kubernetes Service (EKS) is a powerful service that can make it easier to run and deploy your Kubernetes applications on AWS. By following the above steps, you should now be able to create an EKS Cluster, launch worker nodes, and deploy your sample application with ease. Enjoy the power of Kubernetes and Amazon EKS in your own projects!