github.com/Aestek/consul@v1.2.4-0.20190309222502-b2c31e33971a/website/source/docs/agent/cloud-auto-join.html.md (about) 1 --- 2 layout: "docs" 3 page_title: "Cloud Auto-join" 4 sidebar_current: "docs-agent-cloud-auto-join" 5 description: |- 6 Consul supports automatic cluster joining using cloud metadata on various providers. 7 --- 8 9 # Cloud Auto-joining 10 11 As of Consul 0.9.1, `retry-join` accepts a unified interface using the 12 [go-discover](https://github.com/hashicorp/go-discover) library for doing 13 automatic cluster joining using cloud metadata. To use retry-join with a 14 supported cloud provider, specify the configuration on the command line or 15 configuration file as a `key=value key=value ...` string. 16 17 In Consul 0.9.1-0.9.3 the values need to be URL encoded but for most 18 practical purposes you need to replace spaces with `+` signs. 19 20 As of Consul 1.0 the values are taken literally and must not be URL 21 encoded. If the values contain spaces, equals, backslashes or double quotes then 22 they need to be double quoted and the usual escaping rules apply. 23 24 ```sh 25 $ consul agent -retry-join 'provider=my-cloud config=val config2="some other val" ...' 26 ``` 27 28 or via a configuration file: 29 30 ```json 31 { 32 "retry_join": ["provider=my-cloud config=val config2=\"some other val\" ..."] 33 } 34 ``` 35 36 The cloud provider-specific configurations are detailed below. This can be 37 combined with static IP or DNS addresses or even multiple configurations 38 for different providers. 39 40 In order to use discovery behind a proxy, you will need to set 41 `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY` environment variables per 42 [Golang `net/http` library](https://golang.org/pkg/net/http/#ProxyFromEnvironment). 43 44 The following sections give the options specific to each supported cloud 45 provider. 46 47 ### Amazon EC2 48 49 This returns the first private IP address of all servers in the given 50 region which have the given `tag_key` and `tag_value`. 51 52 ```sh 53 $ consul agent -retry-join "provider=aws tag_key=... tag_value=..." 54 ``` 55 56 ```json 57 { 58 "retry_join": ["provider=aws tag_key=... tag_value=..."] 59 } 60 ``` 61 62 - `provider` (required) - the name of the provider ("aws" in this case). 63 - `tag_key` (required) - the key of the tag to auto-join on. 64 - `tag_value` (required) - the value of the tag to auto-join on. 65 - `region` (optional) - the AWS region to authenticate in. 66 - `addr_type` (optional) - the type of address to discover: `private_v4`, `public_v4`, `public_v6`. Default is `private_v4`. (>= 1.0) 67 - `access_key_id` (optional) - the AWS access key for authentication (see below for more information about authenticating). 68 - `secret_access_key` (optional) - the AWS secret access key for authentication (see below for more information about authenticating). 69 70 #### Authentication & Precedence 71 72 - Static credentials `access_key_id=... secret_access_key=...` 73 - Environment variables (`AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`) 74 - Shared credentials file (`~/.aws/credentials` or the path specified by `AWS_SHARED_CREDENTIALS_FILE`) 75 - ECS task role metadata (container-specific). 76 - EC2 instance role metadata. 77 78 The only required IAM permission is `ec2:DescribeInstances`, and it is 79 recommended that you make a dedicated key used only for auto-joining. If the 80 region is omitted it will be discovered through the local instance's [EC2 81 metadata 82 endpoint](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-identity-documents.html). 83 84 ### Microsoft Azure 85 86 This returns the first private IP address of all servers in the given region 87 which have the given `tag_key` and `tag_value` in the tenant and subscription, or in 88 the given `resource_group` of a `vm_scale_set` for Virtual Machine Scale Sets. 89 90 ```sh 91 $ consul agent -retry-join "provider=azure tag_name=... tag_value=... tenant_id=... client_id=... subscription_id=... secret_access_key=..." 92 ``` 93 94 ```json 95 { 96 "retry_join": ["provider=azure tag_name=... tag_value=... tenant_id=... client_id=... subscription_id=... secret_access_key=..."] 97 } 98 ``` 99 100 - `provider` (required) - the name of the provider ("azure" in this case). 101 - `tenant_id` (required) - the tenant to join machines in. 102 - `client_id` (required) - the client to authenticate with. 103 - `secret_access_key` (required) - the secret client key. **NOTE** This value often may have an equals sign in it's value, especially if generated from the Azure Portal, so is important to wrap in single quotes eg. `secret_acccess_key='fpOfcHQJAQBczjAxiVpeyLmX1M0M0KPBST+GU2GvEN4='` 104 105 Use these configuration parameters when using tags: 106 107 - `tag_name` - the name of the tag to auto-join on. 108 - `tag_value` - the value of the tag to auto-join on. 109 110 Use these configuration parameters when using Virtual Machine Scale Sets (Consul 1.0.3 and later): 111 112 - `resource_group` - the name of the resource group to filter on. 113 - `vm_scale_set` - the name of the virtual machine scale set to filter on. 114 115 When using tags the only permission needed is `Microsoft.Network/networkInterfaces`. 116 117 When using Virtual Machine Scale Sets the only role action needed is `Microsoft.Compute/virtualMachineScaleSets/*/read`. 118 119 ### Google Compute Engine 120 121 This returns the first private IP address of all servers in the given 122 project which have the given `tag_value`. 123 124 ```sh 125 $ consul agent -retry-join "provider=gce project_name=... tag_value=..." 126 ``` 127 128 ```json 129 { 130 "retry_join": ["provider=gce project_name=... tag_value=..."] 131 } 132 ``` 133 134 - `provider` (required) - the name of the provider ("gce" in this case). 135 - `tag_value` (required) - the value of the tag to auto-join on. 136 - `project_name` (optional) - the name of the project to auto-join on. Discovered if not set. 137 - `zone_pattern` (optional) - the list of zones can be restricted through an RE2 compatible regular expression. If omitted, servers in all zones are returned. 138 - `credentials_file` (optional) - the credentials file for authentication. See below for more information. 139 140 #### Authentication & Precedence 141 142 - Use credentials from `credentials_file`, if provided. 143 - Use JSON file from `GOOGLE_APPLICATION_CREDENTIALS` environment variable. 144 - Use JSON file in a location known to the gcloud command-line tool. 145 - On Windows, this is `%APPDATA%/gcloud/application_default_credentials.json`. 146 - On other systems, `$HOME/.config/gcloud/application_default_credentials.json`. 147 - On Google Compute Engine, use credentials from the metadata 148 server. In this final case any provided scopes are ignored. 149 150 Discovery requires a [GCE Service 151 Account](https://cloud.google.com/compute/docs/access/service-accounts). 152 Credentials are searched using the following paths, in order of precedence. 153 154 ### IBM SoftLayer 155 156 This returns the first private IP address of all servers for the given 157 datacenter with the given `tag_value`. 158 159 ```sh 160 $ consul agent -retry-join "provider=softlayer datacenter=... tag_value=... username=... api_key=..." 161 ``` 162 163 ```json 164 { 165 "retry_join": ["provider=softlayer datacenter=... tag_value=... username=... api_key=..."] 166 } 167 ``` 168 169 - `provider` (required) - the name of the provider ("softlayer" in this case). 170 - <a name="sl_datacenter"></a><a href="#sl_datacenter"><code>datacenter</code></a> (required) - the name of the datacenter to auto-join in. 171 - `tag_value` (required) - the value of the tag to auto-join on. 172 - `username` (required) - the username to use for auth. 173 - `api_key` (required) - the api key to use for auth. 174 175 ### Aliyun (Alibaba Cloud) 176 177 This returns the first private IP address of all servers for the given 178 `region` with the given `tag_key` and `tag_value`. 179 180 ```sh 181 $ consul agent -retry-join "provider=aliyun region=... tag_key=consul tag_value=... access_key_id=... access_key_secret=..." 182 ``` 183 184 ```json 185 { 186 "retry_join": ["provider=aliyun region=... tag_key=consul tag_value=... access_key_id=... access_key_secret=..."] 187 } 188 ``` 189 190 - `provider` (required) - the name of the provider ("aliyun" in this case). 191 - `region` (required) - the name of the region. 192 - `tag_key` (required) - the key of the tag to auto-join on. 193 - `tag_value` (required) - the value of the tag to auto-join on. 194 - `access_key_id` (required) -the access key to use for auth. 195 - `access_key_secret` (required) - the secret key to use for auth. 196 197 The required RAM permission is `ecs:DescribeInstances`. 198 It is recommended you make a dedicated key used only for auto-joining. 199 200 ### Digital Ocean 201 202 This returns the first private IP address of all servers for the given 203 `region` with the given `tag_name`. 204 205 ```sh 206 $ consul agent -retry-join "provider=digitalocean region=... tag_name=... api_token=..." 207 ``` 208 209 ```json 210 { 211 "retry_join": ["provider=digitalocean region=... tag_name=... api_token=..."] 212 } 213 ``` 214 215 - `provider` (required) - the name of the provider ("digitalocean" in this case). 216 - `region` (required) - the name of the region. 217 - `tag_name` (required) - the value of the tag to auto-join on. 218 - `api_token` (required) -the token to use for auth. 219 220 ### Openstack 221 222 This returns the first private IP address of all servers for the given 223 `region` with the given `tag_key` and `tag_value`. 224 225 ```sh 226 $ consul agent -retry-join "provider=os tag_key=consul tag_value=server username=... password=... auth_url=..." 227 ``` 228 229 ```json 230 { 231 "retry_join": ["provider=os tag_key=consul tag_value=server username=... password=... auth_url=..."] 232 } 233 ``` 234 235 - `provider` (required) - the name of the provider ("os" in this case). 236 - `tag_key` (required) - the key of the tag to auto-join on. 237 - `tag_value` (required) - the value of the tag to auto-join on. 238 - `project_id` (optional) - the id of the project (tenant id). 239 - `username` (optional) - the username to use for auth. 240 - `password` (optional) - the password to use for auth. 241 - `token` (optional) - the token to use for auth. 242 - `auth_url` (optional) - the identity endpoint to use for auth. 243 - `insecure` (optional) - indicates whether the API certificate should not be checked. Any value means `true`. 244 245 The configuration can also be provided by environment variables. 246 247 ### Scaleway 248 249 This returns the first private IP address of all servers for the given 250 `region` with the given `tag_name`. 251 252 ```sh 253 $ consul agent -retry-join "provider=scaleway organization=my-org tag_name=consul-server token=... region=..." 254 ``` 255 256 ```json 257 { 258 "retry_join": ["provider=scaleway organization=my-org tag_name=consul-server token=... region=..."] 259 } 260 ``` 261 262 - `provider` (required) - the name of the provider ("scaleway" in this case). 263 - `region` (required) - the name of the region. 264 - `tag_name` (required) - the name of the tag to auto-join on. 265 - `organization` (required) - the organization access key to use for auth (equal to access key). 266 - `token` (required) - the token to use for auth. 267 268 ### Joyent Triton 269 270 This returns the first PrimaryIP addresses for all servers with the given `tag_key` and `tag_value`. 271 272 ```sh 273 $ consul agent -retry-join "provider=triton account=testaccount url=https://us-sw-1.api.joyentcloud.com key_id=... tag_key=consul-role tag_value=server" 274 ``` 275 276 ```json 277 { 278 "retry_join": ["provider=triton account=testaccount url=https://us-sw-1.api.joyentcloud.com key_id=... tag_key=consul-role tag_value=server"] 279 } 280 ``` 281 282 - `provider` (required) - the name of the provider ("triton" in this case). 283 - `account` (required) - the name of the account. 284 - `url` (required) - the URL of the Triton api endpoint to use. 285 - `key_id` (required) - the key id to use. 286 - `tag_key` (optional) - the instance tag key to use. 287 - `tag_value` (optional) - the tag value to use. 288 289 290 ### vSphere 291 292 This returns the first private IP address of all servers for the given region with the given `tag_name` and `category_name`. 293 294 ```sh 295 $ consul agent -retry-join "provider=vsphere category_name=consul-role tag_name=consul-server host=... user=... password=... insecure_ssl=[true|false]" 296 ``` 297 298 ```json 299 { 300 "retry-join": ["provider=vsphere category_name=consul-role tag_name=consul-server host=... user=... password=... insecure_ssl=[true|false]"] 301 } 302 ``` 303 304 - `provider` (required) - the name of the provider ("vsphere" is the provider here) 305 - `tag_name` (required) - The name of the tag to look up. 306 - `category_name` (required) - The category of the tag to look up. 307 - `host` (required) - The host of the vSphere server to connect to. 308 - `user` (required) - The username to connect as. 309 - `password` (required) - The password of the user to connect to vSphere as. 310 - `insecure_ssl` (optional) - Whether or not to skip SSL certificate validation. 311 - `timeout` (optional) - Discovery context timeout (default: 10m) 312 313 ### Packet 314 315 This returns the first private IP address (or the IP addresso of `address type`) of all servers with the given `project` and `auth_token`. 316 317 ```sh 318 $ consul agent -retry-join "provider=packet auth_token=token project=uuid url=... address_type=..." 319 ``` 320 321 ```json 322 { 323 "retry-join": ["provider=packet auth_token=token project=uuid url=... address_type=..."] 324 } 325 ``` 326 327 - `provider` (required) - the name of the provider ("packet" is the provider here) 328 - `project` (required) - the UUID of packet project 329 - `auth_token` (required) - the authentication token for packet 330 - `url` (optional) - a REST URL for packet 331 - `address_type` (optional) - the type of address to check for in this provider ("private_v4", "public_v4" or "public_v6". Defaults to "private_v4") 332 333 334 ### Kubernetes (k8s) 335 336 The Kubernetes provider finds the IP addresses of pods with the matching 337 [label or field selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/). 338 This is useful for non-Kubernetes agents that are joining a server cluster 339 running within Kubernetes. 340 341 The pod IP is used by default, which requires that the agent connecting can 342 network to the pod IP. The `host_network` boolean can be set to true to use 343 the host IP instead, but this requires the agent ports (Gossip, RPC, etc.) 344 to be exported to the host as well. 345 346 By default, no port is specified. This causes Consul to use the default 347 gossip port (default behavior with all join requests). The pod may specify 348 the `consul.hashicorp.com/auto-join-port` annotation to set the port. The value 349 may be an integer or a named port. 350 351 ```sh 352 $ consul agent -retry-join "provider=k8s label_selector=\"app=consul,component=server\"" 353 ``` 354 355 ```json 356 { 357 "retry-join": ["provider=k8s label_selector=..."] 358 } 359 ``` 360 361 - `provider` (required) - the name of the provider ("k8s" is the provider here) 362 - `kubeconfig` (optional) - path to the kubeconfig file. If this isn't 363 set, then in-cluster auth will be attempted. If that fails, the default 364 kubeconfig paths are tried (`$HOME/.kube/config`). 365 - `namespace` (optional) - the namespace to search for pods. If this isn't 366 set, it defaults to all namespaces. 367 - `label_selector` (optional) - the label selector for matching pods. 368 - `field_selector` (optional) - the field selector for matching pods.