Cote not working with AWS Autoscalling instances.
Aaqib925 opened this issue · 3 comments
We were using cote with our microservices, each of the service is running on a seperate instance. For the cote discovery we are using AWS elastic cache redis cluster and it works as expected for the single microservice instance. After that we applied the AWS Autoscalling group to the EC2, which scales based on the usage. The issue happens when one service is autoscalled to a new EC2 instance using the same redis cluster, but the cote connection crashes.
The behaviour we want is when one of the service is autoscalled to a new EC2 instance, but using the same redis cluster for discovery, corrurently listens to the events triggered for the cote and only one of them respond at a time.
Below is the screenshot when our EC2 Autoscales to a new one and services start to run. Also feel free to advice over the architecture design for the microservices autoscalling running in parallel over a single control tower source of truth like redis.
I am also facing the issue and trying to figure it out for the last 10 days @dashersw
I`m working with cote js in AWS Kubernetes cluster already for a year or even more. It works like a charm even with AWS Lambdas. But ti reach it I had to dance with drums a lot. The solution helps me is prelaunch special script which evaluates discovery host name before actual node scrip is running with command
node -r setDiscoveryHostname index.js
`const { networkInterfaces } = require('os');
const network = networkInterfaces();
function getExternalIPv4() {
const results = Object.create(null); // Or just '{}', an empty object
for (const name of Object.keys(network)) {
for (const net of network[ name ]) {
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
if (net.family === 'IPv4' && !net.internal) {
if (!results[ name ]) {
results[ name ] = [];
}
results[ name ].push(net.address);
}
}
}
const [ myIp ] = Object.values(results)[ 0 ];
return myIp;
}
process.env.DISCOVERY_HOSTNAME = network.getExternalIPv4();`
As a service discovery I`m using Redis as well
Just make it worked with AWS Autoscalling group and codedeploy by adding DISCOVERY_HOSTNAME
in the .env
file.
You can use this script in after_install.sh
to add var in the .env file during the after_install hook for codedeploy
var=$(curl ifconfig.me)
echo >> .env
echo DISCOVERY_HOSTNAME=$var >> .env