Skip to content

Setup local LXD cluster

David Edler edited this page May 17, 2023 · 3 revisions
  1. Create a new project with all settings to default. Choose a good name like "my-cluster".
  2. Edit the default profile in the "my-cluster" project and
    1. Choose an existing storage pool.
    2. Add a network "lxcbr0" with name "eth0".
  3. Create and start 3 instances with "jammy" and all default settings
    1. All 3 instances should have a shared network and get an ipv4 like "10.216.192.xxx" after booting.
  4. Open the terminal tab of the first instance
    1. Run "lxd init"
    2. Answer 1st question with yes: "Would you like to use LXD clustering? (yes/no) [default=no]: yes"
    3. Accept default for the next 3 questions
    4. Setup password auth: "Setup password authentication on the cluster? (yes/no) [default=no]: yes"
    5. Choose a password and confirm it: "Trust password for new clients: "
    6. Accept default for the remaining questions
  5. Open a terminal tab on the 2nd instance
    1. Run "lxd init"
    2. Answer 1st question with yes: "Would you like to use LXD clustering? (yes/no) [default=no]: yes"
    3. Accept default for the next question
    4. Answer joining a cluster with yes "Are you joining an existing cluster? (yes/no) [default=no]: yes"
    5. Accept default for the next two questions
    6. Enter ip of the first instance "IP address or FQDN of an existing cluster member (may include port): 10.216.192.xxx"
    7. Confirm the fingerprint, "Is this the correct fingerprint? (yes/no/[fingerprint]) [default=no]: yes"
    8. Enter trust password from the step 4.5. "Cluster trust password: "
    9. Allow data override "All existing data is lost when joining a cluster, continue? (yes/no) [default=no] yes"
    10. Accept default for the last two questions
  6. Repeat the steps from 5. for the 3rd instance to add it to the cluster
  7. Ensure your cluster is running on one of the three nodes
    1. in the terminal, run "lxd cluster show" and verify all three nodes are listed.
  8. Add your certificate to the new cluster
    1. In your local checkout of lxd-ui, run dotrun once, to ensure your certificates are created.
    2. Copy the contents of keys/lxd-ui.crt from your checkout directory
    3. Open a terminal to one of the three cluster nodes
      1. Create a new file "vim cert" and paste the contents from step 8.2., save and exit the file
      2. Add that cert to the trust store "lxc config trust add cert"
      3. Ensure everything is setup correctly "lxc config trust list" should look like this:
+--------+------------------+-----------------------+--------------+------------------------------+------------------------------+
|  TYPE  |       NAME       |      COMMON NAME      | FINGERPRINT  |          ISSUE DATE          |         EXPIRY DATE          |
+--------+------------------+-----------------------+--------------+------------------------------+------------------------------+
| client | cert             | localhost             | 438fe5856e9a | Jan 26, 2023 at 8:36am (UTC) | Apr 14, 2031 at 8:36am (UTC) |
+--------+------------------+-----------------------+--------------+------------------------------+------------------------------+
| server | enabling-hermit  | root@enabling-hermit  | e2be195e8a3d | May 15, 2023 at 7:34am (UTC) | May 12, 2033 at 7:34am (UTC) |
+--------+------------------+-----------------------+--------------+------------------------------+------------------------------+
| server | polished-mustang | root@polished-mustang | 32c6836027af | May 15, 2023 at 7:38am (UTC) | May 12, 2033 at 7:38am (UTC) |
+--------+------------------+-----------------------+--------------+------------------------------+------------------------------+
| server | suited-octopus   | root@suited-octopus   | c980c04ce1f8 | May 15, 2023 at 7:43am (UTC) | May 12, 2033 at 7:43am (UTC) |
+--------+------------------+-----------------------+--------------+------------------------------+------------------------------+
  1. Update the ip for your local dev setup to use the cluster as a backend
    1. Create a file .env.local in the main directory of your lxd-ui checkout
    2. Enter a single line with the content LXD_UI_BACKEND_IP=10.216.192.148, replace the ip with one of the cluster members. (Warning, the ip might change after rebooting the cluster nodes).
    3. (Re-) start dotrun
    4. You can see and manage the cluster now under https://localhost:8407/ui/cluster