ECS Flashcards

1
Q

ECS clusters

A

are logical grouping of EC2 instances

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

the EC2 instances we’re going to launch will run

A

ECS agents = just a Docker container on each EC2 instance.

they will register our EC2 instance with the ECS cluster

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

The EC2 instances are a little bit special

A

they don’t run the plain Amazon Linux 2 AMI.

They run the special ECS AMI

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

tasks definitions

A

metadata in JSON form to tell ECS how to run a Docker Container

image name, the port binding for the container and the host, memory and CPU that are required, the environment variables, networking informationetc

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

tasks and roles (exam)

A

the task can have an IAM role

If a task cannot do anything, it cannot pull an image
from the ECR, it cannot talk to S3 or whatever,

if a container can’t do this, well it’s because it’s missing a task role so we could assign a role

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

ECS services

A
  1. help define how many tasks should be run and how
  2. they ensure that the number of tasks desired is running across our fleet of EC2 instances
  3. can be linked to LB
  4. are created inside the ECS cluster
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Replica type of ECS services

A

tries to run as many tasks as possible

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

Daemon type of ECS services

A

tries to run only one task on each ECS instance in the cluster

(for monitoring and gathering metrics for ex.)

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

you can run several identical containers using (exam)

A

dynamic port forwarding

you roll out as many containers as you want and each of them has a dynamically assigned port (host port is left empty, 0 means random). To the outside they are available on 80, and Load Balancer will distribute requests across them

DNS name of Load Balancer is then used as entry point

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

EC2 Instance Profile

A

we have an EC2 Instance and it is running the ECS Agent. That’s what makes this EC2 Instance part of ECS. To make it work, we need to attach an
EC2 Instance Profile (IAM role = ECS instance role).

ECS agent will use that role to make API calls to the ECS service to register the instance, for example, with their ECS cluster, to send the container logs of any task rerun to CloudWatch Logs and also will be used to pull images from ECR

ECS agent has integration with ECS Service, CloudWatch Logs, and the ECR Service through the EC2 Instance profile.

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

on your EC2 Instances, you can run some tasks that may interact with other it via services and so each task needs

A

ECS Task Role (IAM role). This will allow each task to have a specific role with the minimum permissions.

for example, we will create an ECS Task Role A that we will attach to the Task A, and this task role may allow us to write to an Amazon S3 Bucket.

you want to use different task roles for different ECS Services and tasks that you run.

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

And where do you define the task role?

A

you define them in the task definition.

in the IAM console you can search for ECS and see all ECS related roles. You can also create a new role –> scroll to ECS and select it –> select use case, for ex., access to S3

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

Which ECS config must you enable in /etc/ecs/ecs.config to allow your ECS tasks to endorse IAM roles?

A

ECS_ENABLE_TASK_IAM_ROLE

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

You are looking to push Docker images into ECR with your AWS CodePipeline and CodeBuild. The last step fails with an authorization issue. What is the issue?

A

Any permissions issues against ECR is most likely due to IAM policies

double check your IAM permissions for CodeBuild service

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

You are looking to run multiple instances of the same application on the same EC2 instance and expose it with a load balancer. The application is available as a Docker container. You should use

A

Application load balancer + ECS

Uses the dynamic port feature

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

You are running a web application on ECS, the Docker image is stored on ECR, and trying to launch two containers of the same type on EC2. The first container starts, but the second one doesn’t. You have checked and there’s enough CPU and RAM available on the EC2 instance. What’s the problem?

A

the host port is defined in the task definition

To enable random host port, set host port = 0 (or empty), which allows multiple containers of the same type to launch on the same instance

17
Q

You have started an EC2 instance and it’s not registered with the ECS cluster. What could be the reason

A
  1. the ECS agent not running
  2. AMI used isn’t AWS ECS AMI
  3. EC2 instance is missing IAM permissions

can not be the reason

security groups on EC2 instance are misconfigured
security groups do not matter when an instance registers with the ECS service

18
Q

Which commands must be used to pull an image from ECR? (CLI v1)

A

$(aws ecr get-login –no-include-email –region eu-west-I)

docker pull $ECR_IMAGE_URL

19
Q

You would like to run 4 ECS services on your ECS cluster, which need access to various services. What is the best practice?

A

create 4 ECS task roles and attach them to the relevant ECS task definition

20
Q

Which task cluster placement is the MOST cost-efficient?

A

binpack

21
Q

when you create a task of type EC2 and you have a cluster, you must figure out where to place the task based on the available memory, CPU and ports on your target EC2 instances. If the ECS service has a new container, a new task that it wants to place on your EC2 instances, it needs to figure out where to place it. Whenever a service scales in, the ECS service needs to determine which ECS task to terminate

A

you can define a task placement strategy and task placement constraints. This is only working for when you use ECS launched on EC2 instances. Not for Fargate because for Fargate, AWS figures out for you where to start the container and you don’t manage any backend instances

when ECS places tasks, it will use the following

  1. identify instances that satisfy the CPU, memory and port requirements in the task definition.
  2. look at the task placement constraints
  3. try to identify the instance that satisfies best the task placement strategy.
22
Q

binpack task placement strategy

A

will place tasks based on the least available amount of CPU or memory to help you minimize the number of instances in use.

it’s going to try to fill up that EC2 instance all the way with containers and then when it can’t put any more containers on that one EC2 instance, it’s going to place EC2 containers on another EC2 instance.

brings the most cost saving because it will minimize the number of EC2 instances in use and try to maximize the utilization of one EC2 instance at a time.

23
Q

random task placement strategy

A

places the tasks randomly.

we have two EC2 instance and tasks are being added,
then they will just be placed randomly and there is no logic to it.

24
Q

spread task placement strategy

A

spread is based on the specified value. (instance id
or ECS availability zones and so on.)

we have three EC2 instances and they are in three different availability zones. And we configure spread on AZ. That means that the task will be spread evenly
across AZs.
So my first task may be on AZ-A then AZ-B then AZ-C.

maximizes the high availability of our ECS service
by spreading the tasks on the EC2 instances.

25
Q

task placements strategies can be mixed together.

A

we can have a spread on availability zone and then a spread on instance id. Or we can have a spread on availability zone and then a binpack on memory.

26
Q

distinctInstance task placement constraint

A

each task should be placed on a different container instance. So you will never have two tasks on the same instance.

27
Q

memberOf task placement constraint

A

we want to place task on instances that satisfy an expression that can be defined using the Cluster Query Language

we want to say that the instance type must be of type t2. And so what we are saying here is that all these tasks should be placed only on t2 instances.

28
Q

in /etc/ecs/ecs.config you need to configure the following

A

ECS_CLUSTER = MyCluster
ECS_ENGINE_AUTH_DATA={}
ECS_AVAILABLE_LOGGING_DRIVERS=[]
ECS_ENABLE_TASK_IAM_ROLE=true

29
Q

ECS_ENGINE_AUTH_DATA in /etc/ecs/ecs.config

A

Example values: dockercfg | docker

The dockercfg format uses the authentication information stored in the configuration file that is created when you run the docker login command. You can create this file by running docker login on your local system and entering your registry user name, password, and email address. You can also log in to a container instance and run the command there. Depending on your Docker version, this file is saved as either ~/.dockercfg or ~/.docker/config.json.

The docker format uses a JSON representation of the registry server that the agent should authenticate with. It also includes the authentication parameters required by that registry (such as user name, password, and the email address for that account).

(DockerHub for ex.)

30
Q

ECS_AVAILABLE_LOGGING_DRIVERS

A

Example values: [“awslogs”,”fluentd”,”gelf”,”json-file”,”journald”,”splunk”,”logentries”,”syslog”]

for ex., if you to use CloudWatch logging

The logging drivers available on the container instance. The Amazon ECS container agent running on a container instance must register the logging drivers available on that instance with the ECS_AVAILABLE_LOGGING_DRIVERS environment variable before containers placed on that instance can use log configuration options for those drivers in tasks.

31
Q

ECS_ENABLE_TASK_IAM_ROLE

A

Whether IAM roles for tasks should be enabled on the container instance for task containers with the bridge or default network modes.

32
Q

service auto scaling

A

CPU and RAM are tracked as metrics in CloudWatch at the ECS service level
we can define a service auto scaling based on these CloudWatch metrics.

  1. target tracking
  2. step scaling
  3. scheduled scaling

if you set up a Fargate ECS service with service auto scaling, it is going to be serverless, and so the service
can scale on its own, and we don’t need to worry about the infrastructure that it relies on,

33
Q

service auto scaling - target tracking

A

you want to target a specific average of a CloudWatch metric, for example you wanna say “CPU transition should be at 60% across my ECS service.”

34
Q

service auto scaling - step scaling

A

scale based on CloudWatch alarms (s. auto scaling policies)

35
Q

scheduled scaling

A

to scale based on predictable changes. (s. auto scaling policies)

36
Q

the service scaling at the task level is not equal to the EC2 auto scaling at the instance level!!!

A

if you scale up or down your ECS service, that doesn’t mean that your EC2 auto scaling group at the instance level will scale up or down.

37
Q

Cluster Capacity Provider

A

is used in association with a cluster to determine the infrastructure that a task runs on

  1. for ECS and Fargate, the Fargate and Fargate_Spot capacity providers are added automatically, and this will provision for us the Fargate infrastructure, even though we don’t really see it
  2. for ECS on EC2 we can associate the capacity provider with an auto scaling group. Auto scaling group can automatically add EC2 instances when needed.
38
Q

Cluster Capacity Provider - how it works

A

when you run a task or a service, you define a capacity provider strategy, to prioritize in which provider to run.

We have two EC2 instances, and they’re packed
with ECS tasks, and the average CPU utilization is less than 30%, but your EC2 instances have no more capacity, and they’re full, so we’re going to create a new task, and if that task is assigned to a Cluster Capacity Provider, the Capacity Provider will automatically launch a new ECS instance, a new EC2 instance running on the ECS. And it will put the task there as well.