ECS Flashcards

1
Q

ECS summary

ECS use to?

What types and explain each, three total

A

ECS used to run Docker

  1. ECS Classic: Run EC2 and run containers too
  2. Fargate: ECS serverless , share resources, no more ec2 provisioning.
  3. EKS: Managed Kubernetes by AWS
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
ECS CLASSIC:
what it uses
what configuration is needed, where?
What program is required?
how is it organized?
A

ECS classic uses EC2 instances to run Containers.

These containers coordinate through an agent called
ECS AGENT

Configuration of ECS happens via the file
/ETC/ECS/ECS.CONFIG with the cluster name

Multiple containers of same type requirements:
A. DONT SPECIFY HOST PORT JUST USE CONTAINER PORT

B. NEED TO USE ALB WITH DYNAMIC PORT MAPPING

C. EC2 SECURITY GROUP MUST ALLOW TRAFFIC FROM ALB ON ALL PORTS

**specify container port, the host port will be random, ALB will need to direct traffic out on all ports. Coming in the Dynamic port forwarding will need to route traffic between random ports to containers. **

ECS task IAM roles, will need to be created for each service ECS needs to access. For multiple services by different tasks we will need to create additional roles, best practice is a role for each type of task.

NOTE: securiity groups are assigned to instance level NOT task level

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

CONTAINER PORT - PortMapping

Dynamic port forwarding

A

Dynamic Port Forwarding (SOCKS) Dynamic Port Forwarding allows a communication not on a single port, but across a range of ports.

PortMapping
PDF
Port mappings allow containers to access ports on the host container instance to send or receive traffic. Port mappings are specified as part of the container definition.

If you are using containers in a task with the awsvpc or host network mode, exposed ports should be specified using containerPort. The hostPort can be left blank or it must be the same value as the containerPort.

After a task reaches the RUNNING status, manual and automatic host and container port assignments are visible in the networkBindings section of DescribeTasks API responses.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

ECR

A

Store Docket Images in AWS ECR
Tightly integrated with IAM

AWS CLI V1
$(aws ecr get-login –noinclude-email –region eu-west-1)
aws ecr get-login : Generates docker login command

execute output of ECR GET-LOGIN command

AWS CLI V2
1. aws ecr get-login-password –region eu-west-1

  1. docker login –username AWS –password-stdin…
    * 123456789.dkr.ecr.eu-west-1.amazonaws.com *(url)

**This version pipes section 1 into section 2. Get-login-password {1} command is used to access the docker login command [2}. **

PUSH AND PULL:

Docker Push: FULL URL INCLUDING ECR REPOSITORY
Docker pull: FULL URL INCLUDING ECR REPOSITORY

If EC2 cannot pull or push, CHECK IAM PERMISSIONS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

FARGATE

A

NO Ec2 Instances
AWS provisions and assigns a ELASTIC IP address

You will provision and specify
VCPU
MEMORY
-containers can share them

IAM: For docker tasks you will need to specify IAM roles for each type of interaction to AWS services. Roles should be least priv model so create multiple roles for separate differing tasks.

TO INCREASE, INCREASE TASK NUMBER. no EC2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ECS TASK DEFINITION

A
Metadata: JSON: Tells ECS how to run docker container. 
INFORMATION:
Image name
Port binding for container and host
Memory and CPU
Environment variables etc. 
PARAMETERS ARE ALSO

“placementstrategy”
Binpack
Random
Spread

task placement constraint:
DistinctInstance
Memberof

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

ECS SERVICE

A

Define how many tasks to run and how they should run. COORDINATION BETWEEN TASKS IN SAME CLUSTERS

Linked via
NLB ALB ELB
Ensure that tasks are running across EC2 Fleet.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

ECS cloudwatch

A

ECS integration Cloudwatch LOGS
Setup logging at TASK DEFINITION level
Each container has separate log stream
EC2 instance profile needs correct IAM permissions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

EC2 instance profile

A

Each Ec2 Agent, is attached to an EC2 instance. They launch the Containers

“EC2 Instance profiles” act on EC2 level, this is used by ECS agent to use this role to:

  1. Make api calls to ECS service
  2. Pull Docker images from ECR
  3. Send logs to Cloudwatch Logs
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

EC2 instance profile

A

Each Ec2 Agent, is attached to an EC2 instance. They launch the Containers
IAM PERMISSION BELOW:
“EC2 Instance profiles” act on EC2 level, this is used by ECS agent to use this role to:
1. Make api calls to ECS service
2. Pull Docker images from ECR
3. Send logs to Cloudwatch Logs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Task placement:

A

ONLY FOR ECS and EC2, NOT FARGATE
ECS service must determine how to place items baesd on CPU/ MEMORY/ Available Ports

scaling needs a decider for which to add onto, or where to terminate.

to help with this we define:
TASK PLACEMENT STRATEGY
TASK PLACEMENT CONSTRAINTS

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

TASK PLACEMENT STRATEGY

Best effort strategy to place items.

A

Best effort strategy

  1. ID instance that satisfy CPU/memory/port requirements in task definition (where it can go)
  2. identify task placement constraint
  3. identify instances that satisfy task placement strategy*
  4. select a placement
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
Task definition parameters:
*task placement strategy*
Binpack
Random
Spread

“placementstrategy”
Binpack
Random
Spread

A
1. Binpack, 
pack instances with as many containers as possible until full
[
JSON
"placementstrategy"
Field: Memory
Type: Binpack
]
*this max memory until getting another instance
-----------------------------------
2. Random,
choose whatever randomly
[
JSON
"placementstrategy"
Type: random
]
*no logic
------------------------------------
3. Spread,
evenly distribute
[
JSON
"placementstrategy"

Field: attribute: Availabilityzone
Type: random
]
*Spread according to field listed, in this case its availability zone

====================
CAN BE MIXED!!!!

[
JSON
“placementstrategy”

Field: Memory
Type: Binpack

Field:instanceID
type:random
]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Task definition parameters:
ECS task placement constraint:
DistinctInstance
Memberof

A

DistinctInstance: Each task on different container instance
Memberof: places task on instances that satisfy an expression

"placementConstraints": [
 {
    "type":distinctinstance"
 }
]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

ECS auto scaling

A

CPU and RAM tracked in Cloudwatch at ECS service level

Target tracking: keep average metric
Step: scale based on alarms
scheduled: based on predictable changes

ECS service scaling (TASK level)
Ec2 (Instance level)
Fargate (serverless)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

ECS Cluster Capacity Provider

A

You want to scale ECS and Ec2 server scaling at SAME time

  • *Capacity provider** is used with cluster to determine infrastructure tasks run on.
    1. ECS/Fargate: Fargate and Fargate spot is used automatically
    2. For ECS on Ec2: Need to associate this CAPACITY PROVIDER with an Auto scaling group! automatically add ec2 instances when needed

*When run task / service define a
Capacity provider strategy determines when to put new instances on separate new instances whether ec2 or fargate.

Provider ECS or Fargate:
A: ECS, launches a new EC2 instances and puts task inside. this is launched to specified ASG

B: Fargate, launches task in fargate serverless instead.