MitchyBAwesome / container-bytes

A Set of short labs and excercises for getting hands on experience with AWS Container Services
0 stars 0 forks source link

= Container-Bytes

:toc:

A selection of short hands-on labs to help you learn how to use Amazon Container Services.

== Cost management and EC2 scaling

=== Deploy the base stack

. Run the CloudFormation template to create the AWS resources:

|=== |Region | Launch Template | N. Virginia (us-east-1) a| image::./images/deploy-to-aws.png[link=https://console.aws.amazon.com/cloudformation/home?region=us-east-1#/stacks/new?stackName=container-bytes-lab1&templateURL=https://s3.amazonaws.com/aws-microservices-deploy-options/infra.yaml] |===

. In the ECS console, create a new ECS cluster. Use the cluster creation wizard to create a new cluster composed of Spot instances:

.. The cluster should be named container-bytes-lab1. This name is referenced later in the lab, so if you name the cluster something else you will have to remember this when following later steps.

.. Select several instance types from a range of instance types. It is recommended you use smaller instance sizes rather than large ones. For example:

m4.large c4.large r4.large i3.large. + [NOTE] You may also use previous-generation families

.. Set a maximum bid price of $0.25.

.. Set the number of instances to 3.

.. Launch instances into the VPC named ECSVPC, using the private subnets.

.. Use the security group with InstanceSecurityGroup in the name.

.. For the Container Instance role, use the IAM Role with container-bytes-lab1-EC2Role in the name.

.. For the Spot Fleet request role, use the container-bytes-lab1-SpotFleetTaggingRole

. Open the CloudFormation console and select the stack that has been created. Click the Template tab and look at the User Data for the EcsSpotFleet resource in the template. More information about this script can be found on the AWS Compute blog: https://aws.amazon.com/blogs/compute/powering-your-amazon-ecs-cluster-with-amazon-ec2-spot-instances/

. Create a CloudWatch alarm called ScaleOut that will be used to scale out the Spot fleet:

.. Use the ECS metric MemoryReservation.

.. The alarm should enter the ALARM state when the value is over 20% for more than two minutes. This will require changing the monitoring period.

.. For the Statistic use the Standard metric Maximum.

.. Delete the pre-created Notification action.

. Repeat step 3 to create a new alarm called ScaleIn. Have the alarm enter an ALARM state when the metric is below 20%.

. Set up Auto Scaling for the Spot fleet. Spot fleet Auto Scaling is a property of the Spot request, so this is located in the EC2 Console Spot Requests.

.. Set Auto Scaling to scale between 3 and 10 instances.

.. Create two Auto Scaling policies, one called ScaleUp and one called ScaleDown. You may have to click the link that says Scale Spot fleet using step or simple scaling policies

.. In the ScaleUp policy, use Define Steps to add 2 instances when the MemoryReservation is between 20 and 50, and add 3 instances when the MemoryReservation is over 50.

.. In the ScaleDown policy, use Define Steps to remove 1 instance when the MemoryReservation is between 10 and 20, and remove 2 instances when the MemoryReservation is below 10.

. Create an Auto Scaling group of on-demand instances to provide long-term core capacity for the ECS cluster. If you have used Auto Scaling groups with ECS before, you can launch a CloudFormation stack to create this automatically. The CloudFormation template is called cfn-templates/Lab1-add-ondemand-asg-to-cluster.yml If you have not used Auto Scaling groups with ECS, you can follow the steps below to learn how to do this:

. You will need a copy of the AMI ID of an instance that was launched when you created the ECS cluster earlier. You can find this from the properties of any of the Spot fleet instances.

. Create a new Launch Configuration:

.. Use the AMI ID you copied in step 7.

.. Use an m4.large instance type.

.. Use the IAM Role with EC2InstanceProfile in the name.

.. Paste in the following User Data:

#!/bin/bash
echo ECS_CLUSTER=catsndogsECScluster >> /etc/ecs/ecs.config

.. Use the security group with InstanceSecurityGroup in the name.

. Create an Auto Scaling group using the Launch Configuration you just created:

.. Start with 1 instance.

.. Launch instances into the VPC named ECSVPC, using the private subnets.

.. Do not configure any scaling policies or notifications.

You should now have an ECS cluster composed of three instances from the Spot fleet request, and one instance from the on-demand Auto Scaling group.

=== ECS Service deployment and task Auto Scaling

https://github.com/MitchyBAwesome/container-bytes/issues/2[Issue #2]

=== Task bursting using AWS Fargate

https://github.com/MitchyBAwesome/container-bytes/issues/3[Issue #3]

=== The secret to secrets with Parameter Store

https://github.com/MitchyBAwesome/container-bytes/issues/4[Issue #4]

=== Finding your way, with Service Discovery

https://github.com/MitchyBAwesome/container-bytes/issues/5[Issue #5]

=== Distributed Tracing with Amazon X-Ray

https://github.com/MitchyBAwesome/container-bytes/issues/6[Issue #6]

=== Building a CICD Pipeline for AWS Fargate

https://github.com/MitchyBAwesome/container-bytes/issues/7[Issue #7]

=== Building a CICD Pipeline for AWS EKS

https://github.com/MitchyBAwesome/container-bytes/issues/7[Issue #7]

=== Building a CICD Pipeline for AWS ECS

https://github.com/MitchyBAwesome/container-bytes/issues/7[Issue #7]

=== Logging all the things with Amazon ECS

https://github.com/MitchyBAwesome/container-bytes/issues/8[Issue #8]

=== Managing the Mesh with LinkerD and ECS

https://github.com/MitchyBAwesome/container-bytes/issues/9[Issue #9]