Displaying present location in the site.

We Tried the Automatic Configuration of an HA Cluster Based on VIP Control by Using CloudFormation (Windows/Linux)

EXPRESSCLUSTER Official Blog

June 23rd, 2021

Introduction

AWS CloudFormation (hereinafter called CloudFormation) is a service for automating the configuration of AWS resources.
Using CloudFormation allows you to collectively create, update, and delete various types of AWS resources such as VPC or EC2.

This time, we tried HA cluster configuration in AWS partially automated with CloudFormation.


And besides, cooperating with Ainsible enables the automation of the installation of EXPRESSCLUSTER and the setting of HA clusters.
For more information, refer to the previously introduced popupArticle.

  • * EXPRESSCLUSTER is a brand name for overseas sales while CLUSTERPRO is that for the sales in Japan.

Contents

1. What is CloudFormation?

CloudFormation is the service for automating the configuration of AWS resources (e.g. VPC, EC2).

AWS resources can be created by manipulating a lot of screens and input forms in the management console. However, this requires manual operation each time, causing increased work time and misconfiguration.

With CloudFormation, simply uploading blueprints called templates allows you to configure AWS resources.
CloudFormation, while it requires the creation of templates and its maintenance, enables different environments to be configured in a programmable manner, more speedily and accurately than manual operation, thus minimizing work costs and mistakes.

Such a programmable approach, called IaC (Infrastructure as Code), has recently been emerging in the infrastructure field.

In this section, the terms used for CloudFormation are briefly explained.

Templates

A CloudFormation template is a JSON or YAML formatted text file.
CloudFormation uses these templates as blueprints for creating your AWS resources.
In a template, you can describe AWS resource information, such as the instance type and the AMI ID, which CloudFormation uses to create AWS resources.

Stacks

AWS resources created with CloudFormation are managed as a single unit called a stack.
Creating, updating, and deleting stacks enables a collection of resources to be created, updated, and deleted.
You can work with stacks by using the management console or AWS CLI.

Parameters

Using parameters enable you to input any values in your template each time you create or update a stack.

You can specify Type(DataType), Default, MaxValue, MinValue, or other data in your template as properties for advanced settings.

[Reference]
popupParameters

2. HA Cluster Configureation

In this article, we configure an HA Cluster based on VIP control in the AWS environment in the N. Virginia region.
The following diagram shows the HA cluster configuration:

env_ideal

Of the resources shown in the diagram above, only those automatically configured by using CloudFormation is shown as below:

env_actual

The following, which are not indicated in the figures above, are also automatically configured in this article:

Route Tables

  • Routes for each type of instances (client for operation, active server, and standby server) to communicate with each other.
  • Routes to a NAT instance necessary for the active server and the standby server to access the Internet.
  • Routes to a virtual IP address to be set for AWS virtual IP resources.

Security Groups

  • Client for operation
  • Setting for permitting a remote desktop access via the Internet
  • Active server and standby server
  • Setting for permitting an access from a client for operation
  • Setting for permitting EXPRESSCLUSTER to communicate between the active server and the standby server

The settings above correspond to "HA Cluster Configuration Guide for Amazon Web Services" -> "Constructing an HA cluster based on VIP control" -> "Configuring the VPC Environment".
For security groups, those given above are examples. Set security groups according to your company's policies or others as appropriate.

[Reference]
popupDocumentation - Setup Guides
  • Windows >Cloud > Amazon Web Services

3. HA Cluster Configureation Procedure

With CloudFormation templates, the procedure of configuring HA cluster based on VIP control, as explained above, is described.

3.1 Obtaining a Template

Download the template file (expresscluster_2node_vip.yaml) from the link below:

  • * As this template file is assumed to be used in the N. Virginia region, it is recommended that the following procedures be performed in the N. Virginia region.
  • * This template file is for use with Windows and Linux. If another OS is intended, specify the corresponding parameters in the AMI when creating a stack.

3.2 Creating a Stack

Create a stack with the downloaded template file.

  • * The screens below are as of the date when this article was written and may be different from those as of now.

1. Display CloudFormation in the management console.

2. Select With new resources (standard) from the Create stack button.

3. The Step 1 Specify template screen appears.

In Specify template, select Upload a template file for Template source, and then upload the template file, which was downloaded in "3.1 Obtaining a template", from the Choose file button.

After uploading, click the Next button to continue.

4. The Step 2 Specify stack details screen appears.

Enter the name of a stack and its parameters.

The parameters to be set are as follows, which should be changed as needed:

Parameter Description
AmiIdServer1 An AMI ID for an instance which activates on EC2 as the active server.
* Select the AMI which can be used with your OS.
AmiIdServer2 An AMI ID for an instance which activates on EC2 as the standby server.
* Select the AMI which can be used with your OS.
* Normally, the same AMI ID as that for the active server is set.
AmiIdServerClient An AMI ID for an instance which activates on EC2 as a client for operation.
* Specify the AMI for Windows.
(This template file is assumed for use with Windows.)
IPAddressClientComputers An IP address of a machine connected to a client for operation via RDP, in CIDR notation.
E.g., 10.0.0.10/32, 10.0.0.0/24.
InstanceTypeServer1 An instance type for the active server.
InstanceTypeServer2 An instance type for the standby server.
InstanceTypeServerClient An instance type for a client for operation.
KeyPairName A name for a key pair used for logging in to each EC2 instance.
NameSuffix A suffix included in a name tag (i.e., a retrieval tag) given to each AWS resource.
OSType An OS (Windows or Linux) used for the active server and the standby server.

After inputting the parameters, click the Next button to continue.



5. The Step 3 Configure stack options screen appears.

Click the Next button at the bottom of the screen to continue.

6. The last step, the Step 4 Review screen is displayed.

Check if each of the setting values is correct.

Place a checkmark in the checkbox asking permission on IAM resources, then click the Create stack button to continue.

7. Now the stack starts to be created.

You can view the stack creation status in the management console as below:

If the status shows CREATE_COMPLETE as below, the creation of the stack is completed:

3.3 Troubleshooting

You may come across an error showing Not authorized for images: [ami-XXXXXXXXXXXXXXXXX] as below:

This may be due to no AMI ID. Search for an existing AMI ID and specify it.

You can search your AMI in the EC2 instance creation screen as below:

3.4 Server Configuration and HA Cluster Configuration

After the creation of the stack is completed, log in to the client for operation to configure an HA cluster and check its operation.
For information on the subsequent procedures, see the following guide:

[Reference]
popupDocumentation - Setup Guides
  • Windows > Cloud > Amazon Web Services

Some of the data such as an IP address, VIP address, VPC ID, and ENI ID, to be used for configuring an HA cluster, can be confirmed from the Outputs tab in the management screen.

4. After Creating Stacks

The following are some considerations after creating a stack.

Updating resources after creating stacks

When you need to make changes (e.g. addition, updates, and deletion) to AWS resources created using a stack, Modify the template file and Re-upload are recommended instead of making direct operation on the management console.

This is because, CloudFormation controls AWS resources, which was created by using stacks, only by manipulating those stacks. Making any changes on the management console produces inconsistencies between the current status and its updates, which can cause an error.

For example, after creating a stack, Stack-A, if a new resource, Resource-A associated with the Stack-A is added on the management console, the deletion of the Stack-A may fail, showing DELETE_FAILED.

Deleting stacks

You can delete a stack in the CloudFormation management screen:

The DELETE_COMPLETE status indicates that the deletion of the stack is completed.
If the status shows DELETE_FAILED, check more details in the management screen to take a necessary action.

Conclusion

We have partially automated the configuration of an HA cluster with CloudFormation.

This time, only the creation of AWS resources has been automated, which could be completed in a shorter time than that with conventional manual operation.
Automatic configuration with CloudFormation can save time and effort, and reduce mistakes, caused by manual operation, even if its template needs to be created and maintained.

If you consider introducing the configuration described in this article, you can perform a validation with the popuptrial module of EXPRESSCLUSTER. Please do not hesitate to contact us if you have any questions.