From 4d16e394560c64f2aa9a26f2b18d4b31009f86fc Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Tue, 2 Nov 2021 11:49:28 +0100 Subject: [PATCH] Make a Consul+Nomad cluster --- configuration.nix | 48 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/configuration.nix b/configuration.nix index f25efc7..6dcf30e 100644 --- a/configuration.nix +++ b/configuration.nix @@ -2,8 +2,11 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, ... }: +{ config, pkgs, ... } @ args: +# Configuration local for this cluster node (hostname, IP, etc) +let node_config = import ./node.nix args; +in { imports = [ # Include the results of the hardware scan. @@ -115,16 +118,53 @@ # }; # List services that you want to enable: - + # Enable network time services.ntp.enable = true; # Enable the OpenSSH daemon. services.openssh.enable = true; + # Enable Hashicorp Consul & Nomad + services.consul.enable = true; + services.consul.extraConfig = + let public_ip = (builtins.head node_config.networking.interfaces.eno1.ipv4.addresses).address; + in + { + datacenter = "neptune"; + bootstrap_expect = 3; + server = true; + ui = true; + bind_addr = public_ip; + addresses.http = "0.0.0.0"; + retry_join = [ "192.168.1.21" "192.168.1.22" "192.168.1.23" ]; + }; + + services.nomad.enable = true; + services.nomad.settings = + let public_ip = (builtins.head node_config.networking.interfaces.eno1.ipv4.addresses).address; + in + { + datacenter = "neptune"; + server = { + enabled = true; + bootstrap_expect = 3; + }; + advertise = { + rpc = public_ip; + http = public_ip; + serf = public_ip; + }; + consul.address = "127.0.0.1:8500"; + client = { + enabled = true; + network_interface = "eno1"; + }; + }; + # Open ports in the firewall. - networking.firewall.allowedTCPPorts = [ 22 ]; - # networking.firewall.allowedUDPPorts = [ ... ]; + networking.firewall.allowedTCPPorts = [ 22 4646 4647 4648 8500 8300 8301 8302 ]; + networking.firewall.allowedUDPPorts = [ 4648 8301 8302 ]; # Or disable the firewall altogether. # networking.firewall.enable = false;