Files
nomad/website/content/docs/deploy/clusters/connect-nodes.mdx
Aimee Ukasick 53b083b8c5 Docs: Nomad IA (#26063)
* Move commands from docs to its own root-level directory

* temporarily use modified dev-portal branch with nomad ia changes

* explicitly clone nomad ia exp branch

* retrigger build, fixed dev-portal broken build

* architecture, concepts and get started individual pages

* fix get started section destinations

* reference section

* update repo comment in website-build.sh to show branch

* docs nav file update capitalization

* update capitalization to force deploy

* remove nomad-vs-kubernetes dir; move content to what is nomad pg

* job section

* Nomad operations category, deploy section

* operations category, govern section

* operations - manage

* operations/scale; concepts scheduling fix

* networking

* monitor

* secure section

* remote auth-methods folder and move up pages to sso; linkcheck

* Fix install2deploy redirects

* fix architecture redirects

* Job section: Add missing section index pages

* Add section index pages so breadcrumbs build correctly

* concepts/index fix front matter indentation

* move task driver plugin config to new deploy section

* Finish adding full URL to tutorials links in nav

* change SSO to Authentication in nav and file system

* Docs NomadIA: Move tutorials into NomadIA branch (#26132)

* Move governance and policy from tutorials to docs

* Move tutorials content to job-declare section

* run jobs section

* stateful workloads

* advanced job scheduling

* deploy section

* manage section

* monitor section

* secure/acl and secure/authorization

* fix example that contains an unseal key in real format

* remove images from sso-vault

* secure/traffic

* secure/workload-identities

* vault-acl change unseal key and root token in command output sample

* remove lines from sample output

* fix front matter

* move nomad pack tutorials to tools

* search/replace /nomad/tutorials links

* update acl overview with content from deleted architecture/acl

* fix spelling mistake

* linkcheck - fix broken links

* fix link to Nomad variables tutorial

* fix link to Prometheus tutorial

* move who uses Nomad to use cases page; move spec/config shortcuts

add dividers

* Move Consul out of Integrations; move namespaces to govern

* move integrations/vault to secure/vault; delete integrations

* move ref arch to docs; rename Deploy Nomad back to Install Nomad

* address feedback

* linkcheck fixes

* Fixed raw_exec redirect

* add info from /nomad/tutorials/manage-jobs/jobs

* update page content with newer tutorial

* link updates for architecture sub-folders

* Add redirects for removed section index pages. Fix links.

* fix broken links from linkcheck

* Revert to use dev-portal main branch instead of nomadIA branch

* build workaround: add intro-nav-data.json with single entry

* fix content-check error

* add intro directory to get around Vercel build error

* workound for emtpry directory

* remove mdx from /intro/ to fix content-check and git snafu

* Add intro index.mdx so Vercel build should work

---------

Co-authored-by: Tu Nguyen <im2nguyen@gmail.com>
2025-07-08 19:24:52 -05:00

227 lines
7.8 KiB
Plaintext

---
layout: docs
page_title: Connect nodes into a cluster
description: |-
Connect nodes together to create a Nomad cluster manually
or automatically with cloud auto-join on AWS, Azure, and GCP.
---
# Connect nodes into a cluster
In order to create a Nomad cluster out of individual nodes, you need to
introduce them to one another. There are several ways to perform this:
- Manually
- Cloud Auto-Join
- Consul
This tutorial describes each method and provides configuration snippets, which
you can use as starting points for your own configuration.
## Manual clustering
Manually bootstrapping a Nomad cluster does not rely on additional tooling, but
does require operator participation in the cluster formation process. When
bootstrapping, Nomad servers and clients must be started and informed with the
address of at least one Nomad server.
As you can tell, this creates a chicken-and-egg problem where one server must
first be fully bootstrapped and configured before the remaining servers and
clients can join the cluster. This requirement can add additional provisioning
time as well as ordered dependencies during provisioning.
First, you need to bootstrap a single Nomad server and capture its IP address.
Place this address in the configuration once you have that nodes IP address.
For Nomad servers, this configuration may look something like this:
```hcl
server {
enabled = true
bootstrap_expect = 3
# This is the IP address of the first server provisioned
server_join {
retry_join = ["<known-address>:4648"]
}
}
```
Alternatively, you can supply a server's address after the servers have all been
started by running the [`server join` command] on the servers individually to
cluster the servers. All servers can join one other server, and then rely on the
gossip protocol to discover the rest.
```shell-session
$ nomad server join <known-address>
```
For Nomad clients, the configuration may look something like:
```hcl
client {
enabled = true
server_join {
retry_join = ["<known-address>:4647"]
}
}
```
The client node's server list can be updated at run time using the
[`node config` command].
```shell-session
$ nomad node config -update-servers <IP>:4647
```
The port corresponds to the RPC port. If no port is specified with the IP
address, the default RPC port of `4647` is assumed.
As servers are added or removed from the cluster, this information is pushed to
the client. This means only one server must be specified because, after initial
contact, the full set of servers in the client's region are shared with the
client.
## Join nodes using cloud auto-join
As of Nomad 0.8.4, [`retry_join`] accepts a unified interface using the
[go-discover] library for doing automatic cluster joining using cloud metadata.
To use retry-join with a supported cloud provider, specify the configuration on
the command line or configuration file as a `key=value key=value ...` string.
Values are taken literally and must not be URL encoded. If the values contain
spaces, backslashes or double quotes they need to be double quoted and the usual
escaping rules apply.
```json
{
"retry_join": ["provider=my-cloud config=val config2=\"some other val\" ..."]
}
```
Consult the [cloud provider-specific configurations] in the cloud-autojoin
documentation. This can be combined with static IP or DNS addresses or even
multiple configurations for different providers. In order to use discovery
behind a proxy, you will need to set `HTTP_PROXY`, `HTTPS_PROXY` and `NO_PROXY`
environment variables per [Golang `net/http` library].
## Use Consul to automatically cluster nodes
To automatically bootstrap a Nomad cluster, Nomad can leverage another HashiCorp
open source tool, [Consul]. Bootstrapping Nomad is easiest against an existing
Consul cluster. The Nomad servers and clients will become informed of each
other's existence when the Consul agent is installed and configured on each
host. As an added benefit, integrating Consul with Nomad provides service and
health check registration for applications which later run under Nomad.
Consul models infrastructures as datacenters and multiple Consul datacenters can
be connected over the WAN so that clients can discover nodes in other
datacenters. Since Nomad regions can encapsulate many datacenters, you should be
running a Consul cluster in every Nomad region and connecting them over the
WAN. Refer to the Consul tutorial for both [bootstrapping] a single
datacenter and [connecting multiple Consul clusters over the WAN].
If a Consul agent is installed on the host prior to Nomad starting, the Nomad
agent will register with Consul and discover other nodes.
For servers, you must inform the cluster how many servers you expect to have.
This is required to form the initial quorum, since Nomad is unaware of how many
peers to expect. For example, to form a region with three Nomad servers, you
would use the following Nomad configuration file:
```hcl
# /etc/nomad.d/server.hcl
# data_dir tends to be environment specific.
data_dir = "/opt/nomad/data"
server {
enabled = true
bootstrap_expect = 3
}
```
This configuration would be saved to disk and then run:
```shell-session
$ nomad agent -config=/etc/nomad.d/server.hcl
```
A similar configuration is available for Nomad clients:
```hcl
# /etc/nomad.d/client.hcl
datacenter = "dc1"
# data_dir tends to be environment specific.
data_dir = "/opt/nomad/data"
client {
enabled = true
}
```
The agent is started in a similar manner:
```shell-session
$ sudo nomad agent -config=/etc/nomad.d/client.hcl
```
Nomad clients should always run as root (or with `sudo`). The above
configurations include no IP or DNS addresses between the clients and
servers. This is because Nomad detected the existence of Consul and utilized
service discovery to form the cluster.
### Consul auto-join internals
~> This section discusses the internals of the Consul and Nomad integration at a
very high level. Reading is only recommended for those curious to the
implementation.
As discussed in the previous section, Nomad merges multiple configuration files
together, so the `-config` may be specified more than once:
```shell-session
$ nomad agent -config=base.hcl -config=server.hcl
```
In addition to merging configuration on the command line, Nomad also maintains
its own internal configurations (called "default configs") which include reasonable
base defaults. One of those default configurations includes a "consul" block,
which specifies reasonable defaults for connecting to and integrating with Consul. In
essence, this configuration file resembles the following:
```hcl
# You do not need to add this to your configuration file. This is an example
# that is part of Nomad's internal default configuration for Consul integration.
consul {
# The address to the Consul agent.
address = "127.0.0.1:8500"
# The service name to register the server and client with Consul.
server_service_name = "nomad"
client_service_name = "nomad-client"
# Enables automatically registering the services.
auto_advertise = true
# Enabling the server and client to bootstrap using Consul.
server_auto_join = true
client_auto_join = true
}
```
Refer to the [`consul` stanza] documentation for the complete set of configuration
options.
[`consul` stanza]: /nomad/docs/configuration/consul
[`node config` command]: /nomad/commands/node/config
[`retry_join`]: /nomad/docs/configuration/server_join#retry_join
[`server join` command]: /nomad/commands/server/join
[bootstrapping]: /consul/docs/deploy/server/vm/bootstrap
[cloud provider-specific configurations]: /nomad/docs/configuration/server_join#cloud-auto-join
[connecting multiple consul clusters over the wan]: /consul/docs/east-west/wan-federation
[consul]: /consul/
[go-discover]: https://github.com/hashicorp/go-discover
[golang `net/http` library]: https://golang.org/pkg/net/http/#ProxyFromEnvironment