Reputation: 717
I'm working on a project where the nodes are heavily dependent on static networking as it's kind of a static cluster. Here it goes, there are 3 nodes in the cluster and are in auto-scaling but max count is 3 as the application running on top of them doesn't have the ability to scale automatically. Have created three Elastic IPs and keeping a track/maintaining it programatically. Likewise, for the ENIs wanted to have some mapping created to EIP (manual is also fine) only once. So that once any new node comes up, it attaches to it's EIP by the program I wrote and as EIP is mapped to ENI, it will automatically attach to it.
I understand that Elastic IP is just a floating public IP which remains constant and ENI is a network interface for the EC2.
Just curious if there is something out there which can make this work, which will reduce my pain of updating R53 everytime a new node joins the cluster.
Thanks in advance.
Upvotes: 0
Views: 243
Reputation: 60074
If your cluster is depended on IP, then you can do the manual steps using cloud-init.
Pass the Elastic IP as an input which needs to be associated with current isntance, associate the IP with a new instance and update route53 record.
Here is an example script that can help
#!/bin/bash
# find assoication using IP
function getAssociationIdByAddress() {
if [ ! -z $1 ]; then
local association_id=$(aws --output text --query "Addresses[0].AssociationId" ec2 describe-addresses --public-ip $1)
echo $association_id
else
echo "-1"
fi
}
# deassociate from old instance
function disassociateAddressByAssociationId() {
echo "Disassociating $1"
aws ec2 disassociate-address --association-id $1
}
# assoicate address with new instance
function associateAddress() {
my_instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)
aws ec2 associate-address --instance-id $my_instance_id --public-ip $1
}
Assigning Public IP, disassociating from current instance, if already allocated
echo "Assigning Public IP"
public_ip=55.X.X.X
echo "Getting Association Id $public_ip"
association_id=$(getAssociationIdByAddress $public_ip)
if [ "None" = $association_id ] || [ "-1" = $association_id ] ; then
echo "Not Associated"
else
echo "Association Id:" $association_id
disassociateAddressByAssociationId $association_id
fi
associateAddress $public_ip
For adding or updating record from user data you can check aws-cli add or update DNS record
Upvotes: 1
Reputation: 68715
Relying on IP is not the best design as you are already facing the challenges associated to it. You should switch to hostnames, which are static in nature. You can configure and publish hostnames, which can remain the same but the mapped IP behind the scenes can change.
Yes you can utilize Route 53 in AWS to add A records for domain name to IP address mapping.
Upvotes: 0