Docker has revolutionized software packaging and running. With Docker, software is packaged as Docker images. Applications are run in lightweight Docker containers. Multiple containers run in isolation on an underlying OS utilizing the same OS kernel. Each container has its own filesystem and networking. Containers have advantages over virtual machines in that they fully utilize the underlying OS, whereas virtual machines (VMs) package a complete OS.
Amazon Elastic Container Service (ECS) is a managed service for Docker container orchestration. The Fargate launch mode, which was introduced in Q4 2017, is an alternative to provisioning ECS instances to run Docker containers. With Fargate, no ECS servers are provisioned for a user; instead, the Fargate platform provisions ECS tasks for user access and use. Fargate is a serverless platform for ECS, making it easier to provision, manage and use ECS.
In a set of two articles we shall discuss using Toad Edge Preview 2.0.0 with PostgreSQL Database 10 on Amazon ECS Fargate. The articles have the following sections.
- Setting the Environment
- Creating an ECS Task Definition
- Creating a Service
- Obtaining Connection Parameters
- Creating a Connection in Toad Edge 2.0.0
- Creating a Table
- Comparing Schemas
Setting the Environment
Download and install the following software:
Create an Amazon Web Services (AWS) account at https://aws.amazon.com/resources/create-account/. Log in to the AWS and access the Amazon ECS service at https://aws.amazon.com/ecs. Click on Get started as shown in Figure 1 to start the ECS wizard.
Figure 1. Starting ECS Service
An ECS service consists of the following components.
- A cluster
- A service
- One or more tasks based on a task definition
Networking is provisioned with elastic network interface (ENI).
Next, we get started with creating the ECS components. We shall make use of the default cluster provisioned out-of-the-box on ECS Fargate.
Creating an ECS Task Definition
A task definition is a template for creating tasks, comprising container/s, definition/s, and resource specification (CPU and memory) for the tasks. To create a task definition select Task Definitions in ECS as shown in Figure 2.
Figure 2. Selecting Task Definitions
In Task Definitions click on Create new Task Definition as shown in Figure 3.
Figure 3. Create new Task Definition
The Create new Task Definition wizard gets launched, as shown in Figure 4. Select launch type compatibility as Fargate, as shown in Figure 4. Scroll down and click on Next step.
Figure 4. Selecting Launch type Compatibility
Next, configure task and container definitions as shown in Figure 5. Specify a Task Definition Name or select the default name. Requires Compatibilities is pre-set to Fargate because Fargate is selected in previous screen. Select Task Role as ecsTaskExecutionRole. Network Mode for Fargate launch type is awsvpc and cannot be modified.
Figure 5. Configuring Task
Select Task execution IAM role as ecsTaskExecutionRole. Next, set the task size. Select Task memory from a drop-down as shown in Figure 6.
Figure 6. Selecting Task Memory
Similarly, select a Task CPU from a drop-down. Drop-downs are provided for Task memory and Task CPU instead of fields in which a value could be specified because only a certain combinations of Task memory and Task CPU are supported. Not just any arbitrary memory and CPU may be selected/specified. The valid memory range for a selected Task CPU and the valid CPU for a selected Task memory are indicated below the memory and CPU settings, respectively, as shown in Figure 7.
Figure 7. Task Size settings
Next, create the container definitions. Click on Add container in the Container Definitions section as shown in Figure 8 to add a container definition.
Figure 8. Add container
The Add container dialog gets started, as shown in Figure 9. Specify a Container name (postgresql) and specify Docker Image as postgres, which is the official Docker image for PostgreSQL database.
Figure 9. Specifying Container name and Docker Image
Set a Soft limit for memory (128 MiB). Set Port mappings as Container port 5432, which is the PostgreSQL database listens on by default, as shown in Figure 10. With Fargate, only the container port is settable; the host port is the same as the container port by default.
Figure 10. Setting Memory Limits and Port mappings
Scroll down for Advanced container configuration, as shown in Figure 11. Specify CPU units in the Environment section. Select Essential checkbox, which makes the container essential to the running of a task. If the container faults or stops for some reason, the task is terminated. No environment variables need to be set for PostgreSQL Docker container.
Figure 11. Setting Container Environment
Click on Add as shown in Figure 12 to complete the Docker container definition.
Figure 12. Completing Docker Container Definition with Add
A container definition gets created and listed in Container Definitions section, as shown in Figure 13.
Figure 13. Container definition added
Click on Create as shown in Figure 14 to create the task definition.
Figure 14. Create
As the Launch Status in Figure 15 indicates, the task definition gets created. Click on View task definition.
Figure 15. Launch Status for Task Definition
The Task definition Builder and JSON formats are listed, as shown in Figure 16.
Figure 16. Task Definition Builder and JSON Format
The task definition gets listed in the Task Definitions table, as shown in Figure 17. To find detail about the task definition or create a new revision click on the link.
Figure 17. Task Definitions
The Container Definitions detail is shown in Figure 18 and includes the Docker image, port mappings, and logs configuration.
Figure 18. Container Definitions detail
Creating a Service
Next, we shall create a service that implements the task definition to spin up tasks consisting of Docker containers. To create the service in the default cluster, click on default as shown in Figure 19. Alternatively, to create a service in a new cluster click on Create cluster, which is shown in the Clusters table.
Figure 19. Selecting default cluster
The default cluster dialog gets started, as shown in Figure 20. Select the Services tab, which is already selected by default, and click on Create to create a new service.
Figure 20. Services>Create
The Configure service wizard gets launched, as shown in Figure 21. Select Launch type as Fargate. Select the Task Definition created earlier. Select Platform as Latest.
Figure 21. Configure service
Specify a Service name (postgres) and specify the Number of tasks (3 is shown in Figure 22) to provision. More than one task is recommended so that if one task fails the service is able to fall back on another task. Scroll down and click on Next step.
Figure 22. Specifying Number of tasks
Next, configure the service network. Select a Cluster VPC and select at least two Subnets, as shown in Figure 23.
Figure 23. Configuring Service Network
A Security group is provisioned by default. Select Auto-assign public IP to ENABLED as shown in Figure 24.
Figure 24. Selecting Auto assign Public IP
A load balancer may be configured optionally. Scroll down and click on Next step as shown in Figure 25.
Figure 25. Create Service wizard, continued
In Set Auto Scaling click on Next step with the default setting of Do not adjust the service’s desired count, as shown in figure 26.
Figure 26. Auto Scaling (Optional)
The summary Review of the service is listed, as shown in Figure 27. Click on Create Service.
Figure 27. Service Review>Create Service
As the launch status in Figure 28 indicates, the service gets created.
Figure 28. Launch Status of Service
Click on View Service as shown in Figure 29.
Figure 29. View Service
The Service is shown to have been created. The Tasks’ status is initially Pending, as shown in Figure 30. Click on Refresh button to refresh the task status.
Figure 30. Service created with Task status as pending initially
After a while the task status becomes Running, as shown in Figure 31.
Figure 31. Task Status Running
Click on the Events tab to list the service events as shown in Figure 32.
Figure 32. Service Events
The service events include the server being started, as shown in Figure 33.
Figure 33. Server started
The Clusters table lists 1 Services with 3 Running tasks, as shown in Figure 34.
Figure 34. Service with 3 running tasks
The postgres service gets listed in Services table, as shown in Figure 35.
Figure 35. Services lists the postgres service
In the first of two articles we have created an Amazon ECS task definition and service for PostgreSQL database. In the second article we shall connect with the ECS service with Toad Edge 2.0.0.