github.com/sl1pm4t/consul@v1.4.5-0.20190325224627-74c31c540f9c/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  Variables can also be provided by environmental variables:
   106  
   107  * `ARM_SUBSCRIPTION_ID` for subscription
   108  * `ARM_TENANT_ID` for tenant
   109  * `ARM_CLIENT_ID` for client
   110  * `ARM_CLIENT_SECRET` for secret access key
   111  
   112  Use these configuration parameters when using tags:
   113  
   114  - `tag_name` - the name of the tag to auto-join on.
   115  - `tag_value` - the value of the tag to auto-join on.
   116  
   117  Use these configuration parameters when using Virtual Machine Scale Sets (Consul 1.0.3 and later):
   118  
   119  - `resource_group` - the name of the resource group to filter on.
   120  - `vm_scale_set` - the name of the virtual machine scale set to filter on.
   121  
   122  When using tags the only permission needed is `Microsoft.Network/networkInterfaces`.
   123  
   124  When using Virtual Machine Scale Sets the only role action needed is `Microsoft.Compute/virtualMachineScaleSets/*/read`.
   125  
   126  ### Google Compute Engine
   127  
   128  This returns the first private IP address of all servers in the given
   129  project which have the given `tag_value`.
   130  
   131  ```sh
   132  $ consul agent -retry-join "provider=gce project_name=... tag_value=..."
   133  ```
   134  
   135  ```json
   136  {
   137      "retry_join": ["provider=gce project_name=... tag_value=..."]
   138  }
   139  ```
   140  
   141  - `provider` (required) - the name of the provider ("gce" in this case).
   142  - `tag_value` (required) - the value of the tag to auto-join on.
   143  - `project_name` (optional) - the name of the project to auto-join on. Discovered if not set.
   144  - `zone_pattern` (optional) - the list of zones can be restricted through an RE2 compatible regular expression. If omitted, servers in all zones are returned.
   145  - `credentials_file` (optional) - the credentials file for authentication. Note, if you set `-config-dir` do not store the credentials.json file in the configuration directory as it will be parsed as a config file and Consul will fail to start. See below for more information.
   146  
   147  #### Authentication & Precedence
   148  
   149  - Use credentials from `credentials_file`, if provided.
   150  - Use JSON file from `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
   151  - Use JSON file in a location known to the gcloud command-line tool.
   152      - On Windows, this is `%APPDATA%/gcloud/application_default_credentials.json`.
   153      - On other systems, `$HOME/.config/gcloud/application_default_credentials.json`.
   154  - On Google Compute Engine, use credentials from the metadata
   155      server. In this final case any provided scopes are ignored.
   156  
   157  Discovery requires a [GCE Service
   158  Account](https://cloud.google.com/compute/docs/access/service-accounts).
   159  Credentials are searched using the following paths, in order of precedence.
   160  
   161  ### IBM SoftLayer
   162  
   163  This returns the first private IP address of all servers for the given
   164  datacenter with the given `tag_value`.
   165  
   166  ```sh
   167  $ consul agent -retry-join "provider=softlayer datacenter=... tag_value=... username=... api_key=..."
   168  ```
   169  
   170  ```json
   171  {
   172      "retry_join": ["provider=softlayer datacenter=... tag_value=... username=... api_key=..."]
   173  }
   174  ```
   175  
   176  - `provider` (required) - the name of the provider ("softlayer" in this case).
   177  - <a name="sl_datacenter"></a><a href="#sl_datacenter"><code>datacenter</code></a> (required) - the name of the datacenter to auto-join in.
   178  - `tag_value` (required) - the value of the tag to auto-join on.
   179  - `username` (required) - the username to use for auth.
   180  - `api_key` (required) - the api key to use for auth.
   181  
   182  ### Aliyun (Alibaba Cloud)
   183  
   184  This returns the first private IP address of all servers for the given
   185  `region` with the given `tag_key` and `tag_value`.
   186  
   187  ```sh
   188  $ consul agent -retry-join "provider=aliyun region=... tag_key=consul tag_value=... access_key_id=... access_key_secret=..."
   189  ```
   190  
   191  ```json
   192  {
   193      "retry_join": ["provider=aliyun region=... tag_key=consul tag_value=... access_key_id=... access_key_secret=..."]
   194  }
   195  ```
   196  
   197  - `provider` (required) - the name of the provider ("aliyun" in this case).
   198  - `region` (required) - the name of the region.
   199  - `tag_key` (required) - the key of the tag to auto-join on.
   200  - `tag_value` (required) - the value of the tag to auto-join on.
   201  - `access_key_id` (required) -the access key to use for auth.
   202  - `access_key_secret` (required) - the secret key to use for auth.
   203  
   204  The required RAM permission is `ecs:DescribeInstances`.
   205  It is recommended you make a dedicated key used only for auto-joining.
   206  
   207  ### Digital Ocean
   208  
   209  This returns the first private IP address of all servers for the given
   210  `region` with the given `tag_name`.
   211  
   212  ```sh
   213  $ consul agent -retry-join "provider=digitalocean region=... tag_name=... api_token=..."
   214  ```
   215  
   216  ```json
   217  {
   218      "retry_join": ["provider=digitalocean region=... tag_name=... api_token=..."]
   219  }
   220  ```
   221  
   222  - `provider` (required) - the name of the provider ("digitalocean" in this case).
   223  - `region` (required) - the name of the region.
   224  - `tag_name` (required) - the value of the tag to auto-join on.
   225  - `api_token` (required) -the token to use for auth.
   226  
   227  ### Openstack
   228  
   229  This returns the first private IP address of all servers for the given
   230  `region` with the given `tag_key` and `tag_value`.
   231  
   232  ```sh
   233  $ consul agent -retry-join "provider=os tag_key=consul tag_value=server username=... password=... auth_url=..."
   234  ```
   235  
   236  ```json
   237  {
   238      "retry_join": ["provider=os tag_key=consul tag_value=server username=... password=... auth_url=..."]
   239  }
   240  ```
   241  
   242  - `provider` (required) - the name of the provider ("os" in this case).
   243  - `tag_key` (required) - the key of the tag to auto-join on.
   244  - `tag_value` (required) - the value of the tag to auto-join on.
   245  - `project_id` (optional) - the id of the project (tenant id).
   246  - `username` (optional) - the username to use for auth.
   247  - `password` (optional) - the password to use for auth.
   248  - `token` (optional) - the token to use for auth.
   249  - `auth_url` (optional) - the identity endpoint to use for auth.
   250  - `insecure` (optional) - indicates whether the API certificate should not be checked. Any value means `true`.
   251  
   252  The configuration can also be provided by environment variables.
   253  
   254  ### Scaleway
   255  
   256  This returns the first private IP address of all servers for the given
   257  `region` with the given `tag_name`.
   258  
   259  ```sh
   260  $ consul agent -retry-join "provider=scaleway organization=my-org tag_name=consul-server token=... region=..."
   261  ```
   262  
   263  ```json
   264  {
   265      "retry_join": ["provider=scaleway organization=my-org tag_name=consul-server token=... region=..."]
   266  }
   267  ```
   268  
   269  - `provider` (required) - the name of the provider ("scaleway" in this case).
   270  - `region` (required) - the name of the region.
   271  - `tag_name` (required) - the name of the tag to auto-join on.
   272  - `organization` (required) - the organization access key to use for auth (equal to access key).
   273  - `token` (required) - the token to use for auth.
   274  
   275  ### Joyent Triton
   276  
   277  This returns the first PrimaryIP addresses for all servers with the given `tag_key` and `tag_value`.
   278  
   279  ```sh
   280  $ 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"
   281  ```
   282  
   283  ```json
   284  {
   285      "retry_join": ["provider=triton account=testaccount url=https://us-sw-1.api.joyentcloud.com key_id=... tag_key=consul-role tag_value=server"]
   286  }
   287  ```
   288  
   289  - `provider` (required) - the name of the provider ("triton" in this case).
   290  - `account` (required) - the name of the account.
   291  - `url` (required) - the URL of the Triton api endpoint to use.
   292  - `key_id` (required) - the key id to use.
   293  - `tag_key` (optional) - the instance tag key to use.
   294  - `tag_value` (optional) - the tag value to use.
   295  
   296  
   297  ### vSphere
   298  
   299  This returns the first private IP address of all servers for the given region with the given `tag_name` and `category_name`.
   300  
   301  ```sh
   302  $ consul agent -retry-join "provider=vsphere category_name=consul-role tag_name=consul-server host=... user=... password=... insecure_ssl=[true|false]"
   303  ```
   304  
   305  ```json
   306  {
   307          "retry-join": ["provider=vsphere category_name=consul-role tag_name=consul-server host=... user=... password=... insecure_ssl=[true|false]"]
   308  }
   309  ```
   310  
   311  - `provider` (required) -   the name of the provider ("vsphere" is the provider here)
   312  - `tag_name` (required) -    The name of the tag to look up.
   313  - `category_name` (required) - The category of the tag to look up.
   314  - `host` (required) -        The host of the vSphere server to connect to.
   315  - `user` (required) -         The username to connect as.
   316  - `password` (required) -     The password of the user to connect to vSphere as.
   317  - `insecure_ssl` (optional) -  Whether or not to skip SSL certificate validation.
   318  - `timeout` (optional) -     Discovery context timeout (default: 10m)
   319  
   320  ### Packet
   321  
   322  This returns the first private IP address (or the IP addresso of `address type`) of all servers with the given `project` and `auth_token`.
   323  
   324  ```sh
   325  $ consul agent -retry-join "provider=packet auth_token=token project=uuid url=... address_type=..."
   326  ```
   327  
   328  ```json
   329  {
   330          "retry-join": ["provider=packet auth_token=token project=uuid url=... address_type=..."]
   331  }
   332  ```
   333  
   334  - `provider` (required)	-	the name of the provider ("packet" is the provider here)
   335  - `project` (required) 	- 	the UUID of packet project
   336  - `auth_token` (required) -  the authentication token for packet
   337  - `url` (optional) - 		 a REST URL for packet
   338  - `address_type` (optional) - the type of address to check for in this provider  ("private_v4", "public_v4" or "public_v6".                                   Defaults to "private_v4")
   339  
   340  
   341  ### Kubernetes (k8s)
   342  
   343  The Kubernetes provider finds the IP addresses of pods with the matching
   344  [label or field selector](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/).
   345  This is useful for non-Kubernetes agents that are joining a server cluster
   346  running within Kubernetes.
   347  
   348  The pod IP is used by default, which requires that the agent connecting can
   349  network to the pod IP. The `host_network` boolean can be set to true to use
   350  the host IP instead, but this requires the agent ports (Gossip, RPC, etc.)
   351  to be exported to the host as well.
   352  
   353  By default, no port is specified. This causes Consul to use the default
   354  gossip port (default behavior with all join requests). The pod may specify
   355  the `consul.hashicorp.com/auto-join-port` annotation to set the port. The value
   356  may be an integer or a named port.
   357  
   358  ```sh
   359  $ consul agent -retry-join "provider=k8s label_selector=\"app=consul,component=server\""
   360  ```
   361  
   362  ```json
   363  {
   364          "retry-join": ["provider=k8s label_selector=..."]
   365  }
   366  ```
   367  
   368  - `provider` (required)	-	the name of the provider ("k8s" is the provider here)
   369  - `kubeconfig` (optional) 	- 	path to the kubeconfig file. If this isn't
   370    set, then in-cluster auth will be attempted. If that fails, the default
   371    kubeconfig paths are tried (`$HOME/.kube/config`).
   372  - `namespace` (optional) -  the namespace to search for pods. If this isn't
   373    set, it defaults to all namespaces.
   374  - `label_selector` (optional) - the label selector for matching pods.
   375  - `field_selector` (optional) - the field selector for matching pods.