EC2 Discovery
editEC2 Discovery
editec2 discovery allows to use the ec2 APIs to perform automatic discovery (similar to multicast in non hostile multicast environments). Here is a simple sample configuration:
discovery: type: ec2
You must also set cloud.aws.region
if you are not using default AWS region. See Region for details.
The ec2 discovery is using the same credentials as the rest of the AWS services provided by this plugin (repositories
).
See Getting started with AWS for details.
The following are a list of settings (prefixed with discovery.ec2
) that can further control the discovery:
-
groups
- Either a comma separated list or array based list of (security) groups. Only instances with the provided security groups will be used in the cluster discovery. (NOTE: You could provide either group NAME or group ID.)
-
host_type
-
The type of host type to use to communicate with other instances. Can be
one of
private_ip
,public_ip
,private_dns
,public_dns
. Defaults toprivate_ip
. -
availability_zones
- Either a comma separated list or array based list of availability zones. Only instances within the provided availability zones will be used in the cluster discovery.
-
any_group
-
If set to
false
, will require all security groups to be present for the instance to be used for the discovery. Defaults totrue
. -
ping_timeout
-
How long to wait for existing EC2 nodes to reply during discovery.
Defaults to
3s
. If no unit likems
,s
orm
is specified, milliseconds are used. -
node_cache_time
-
How long the list of hosts is cached to prevent further requests to the AWS API.
Defaults to
10s
.
Binding the network host
It’s important to define network.host
as by default it’s bound to localhost
.
You can use core network host settings or ec2 specific host settings:
EC2 Network Host
editWhen the cloud-aws
plugin is installed, the following are also allowed
as valid network host settings:
EC2 Host Value | Description |
---|---|
|
The private IP address (ipv4) of the machine. |
|
The private host of the machine. |
|
The public IP address (ipv4) of the machine. |
|
The public host of the machine. |
|
equivalent to |
|
equivalent to |
|
equivalent to |
Recommended EC2 Permissions
editEC2 discovery requires making a call to the EC2 service. You’ll want to setup an IAM policy to allow this. You can create a custom policy via the IAM Management Console. It should look similar to this.
{ "Statement": [ { "Action": [ "ec2:DescribeInstances" ], "Effect": "Allow", "Resource": [ "*" ] } ], "Version": "2012-10-17" }
Filtering by Tags
editThe ec2 discovery can also filter machines to include in the cluster based on tags (and not just groups). The settings
to use include the discovery.ec2.tag.
prefix. For example, setting discovery.ec2.tag.stage
to dev
will only
filter instances with a tag key set to stage
, and a value of dev
. Several tags set will require all of those tags
to be set for the instance to be included.
One practical use for tag filtering is when an ec2 cluster contains many nodes that are not running elasticsearch. In
this case (particularly with high ping_timeout
values) there is a risk that a new node’s discovery phase will end
before it has found the cluster (which will result in it declaring itself master of a new cluster with the same name
- highly undesirable). Tagging elasticsearch ec2 nodes and then filtering by that tag will resolve this issue.
Automatic Node Attributes
editThough not dependent on actually using ec2
as discovery (but still requires the cloud aws plugin installed), the
plugin can automatically add node attributes relating to ec2 (for example, availability zone, that can be used with
the awareness allocation feature). In order to enable it, set cloud.node.auto_attributes
to true
in the settings.
Using other EC2 endpoint
editIf you are using any EC2 api compatible service, you can set the endpoint you want to use by setting
cloud.aws.ec2.endpoint
to your URL provider.