Skip to content

Create an EKS Cluster, VPC and Worker Nodes in AWS using CloudFormation.

Notifications You must be signed in to change notification settings

halflogic/aws-eks-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS EKS Demo

This demo will be using CoudFormation (CFN) templates to create the EKS Cluster, Worker Nodes, VPC, Subnets and other network resources.

NOTE: EKS Cluster and NAT Gateways are charged per hour after being provisioned. To avoid unexpected charges in your AWS account, remember to delete the stacks you created once you are done.

Estimated cost for EKS Cluster, 2 NAT Gateways and 2 Worker nodes (t3.micro):
(Excluding EBS volume and data transfer costs)

Provisioned Cost Per Hour
EKS Cluster $0.10
NAT Gateway $0.045 x 2
Worker Node (t3.micro) $0.0104 x 2
Total (estimate) $0.21

Create VPC for EKS Cluster

Create VPC using CloudFormation
https://docs.aws.amazon.com/eks/latest/userguide/create-public-private-vpc.html

CloudFormation template with public and private subnets:
https://amazon-eks.s3.us-west-2.amazonaws.com/cloudformation/2020-06-10/amazon-eks-vpc-private-subnets.yaml

You may use the CloudFormation template above as a guide and modify according to your requirements.

For this demo, the VPC CIDR and Subnets were modified to use the following:

VPC CIDR: 172.29.0.0/16
Public Subnets: 172.29.1.0/24, 172.29.2.0/24
Private Subnets: 172.29.3.0/24, 172.29.4.0/24

Other network resources such as Internet GW, NAT GW, Route Tables and SecurityGroup for the control plane will be created as well.

CFN Template: cfn-vpc-pub-pri.yaml

  1. Open CloudFormation and Create stack
  2. Choose template to upload and continue
  3. Enter Stack name: eks-demo-vpc
  4. Configure stack options: leave defaults and continue
  5. Review and create stack

Your stack will have a status of "CREATE_COMPLETE" after all resources have been provisioned.

Review the stack by clicking on the Resources and Ouputs tabs.

You will need the SecurityGroupId and SubnetIds to create the EKS Cluster.

Create EKS Cluster

Creating an Amazon EKS cluster (general guide)
https://docs.aws.amazon.com/eks/latest/userguide/create-cluster.html

Create EKS Cluster using CloudFormation
https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eks-cluster.html

Some requirements that you may need to create in advance:

CFN Template: cfn-eks-cluster.yaml

  1. Open CloudFormation and Create stack
  2. Choose template to upload and continue
  3. Enter Stack name: eks-cluster
  4. Configure stack options: leave defaults and continue
  5. Review and create stack

Cluster status will show "Active" once provisioned. Then you may proceed creating the worker nodes.

Create EKS Worker Nodes

This demo will be using Self-managed nodes. For more information on Worker Nodes, see: https://docs.aws.amazon.com/eks/latest/userguide/worker.html

Launching Amazon EKS Linux worker nodes (self-managed)
https://docs.aws.amazon.com/eks/latest/userguide/launch-workers.html#self-managed-nodes

You may use this CloudFormation template as a guide and modify according to your requirements:
https://amazon-eks.s3.us-west-2.amazonaws.com/cloudformation/2020-06-10/amazon-eks-nodegroup.yaml

CFN Template: cfn-eks-worker-nodes.yaml

  1. Open CloudFormation and Create stack
  2. Choose template to upload and continue
  3. Enter Stack name: eks-worker-nodes
  4. Configure stack options: leave defaults and continue
  5. Review and create stack

Review the Outputs tab and take note of the NodeInstanceRole, this will be needed to allow the worker nodes to join the cluster.

Join Worker Nodes to the EKS Cluster

Launch a bastion host following security best practices. Install the necessary tools and configure access to the cluster.

At this point you should be able to run kubectl commands in your cluster.

[ec2-user@ip-172-29-1-176 .kube]$ kubectl get svc
NAME         TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   ClusterIP   10.100.0.1   <none>        443/TCP   163m

[ec2-user@ip-172-29-1-176 .kube]$ kubectl get nodes
NAME                           STATUS   ROLES    AGE   VERSION
ip-172-29-3-40.ec2.internal    Ready    <none>   46m   v1.16.8-eks-e16311
ip-172-29-4-218.ec2.internal   Ready    <none>   46m   v1.16.8-eks-e16311

[ec2-user@ip-172-29-1-176 .kube]$ kubectl get pods --all-namespaces
NAMESPACE     NAME                       READY   STATUS    RESTARTS   AGE
kube-system   aws-node-29rht             1/1     Running   0          46m
kube-system   aws-node-lt7qd             1/1     Running   0          46m
kube-system   coredns-55c5fcd78f-t9rdl   1/1     Running   0          164m
kube-system   coredns-55c5fcd78f-txlxr   1/1     Running   0          164m
kube-system   kube-proxy-nfthl           1/1     Running   0          46m
kube-system   kube-proxy-wdgjw           1/1     Running   0          46m

Congratulations! You now have a working Kubernetes cluster and start deploying applications.

Cleanup

Open CloudFormation > Stacks:

Delete each of the stack you have created in the following order:

  1. eks-worker-nodes
  2. eks-cluster
  3. eks-demo-vpc

Delete the bastion host ec2 instance.


Scaling Considerations

About

Create an EKS Cluster, VPC and Worker Nodes in AWS using CloudFormation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages