Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Creating a LXD Cluster

In a production environment, we don't want to put all of our containers on a single LXD host. After all, what happens should that host fail? Instead, we generally want to work with a LXD cluster, multiple LXD servers that share a distributed database and allow for redundancy and some fault tolerance. In this hands-on lab, we set up a small LXD cluster of three hosts.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Beginner
Duration
Clock icon 30m
Published
Clock icon Apr 03, 2020

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Configure the First Server in the Cluster

    Use lxd init to begin configuring the cluster, answering the questions appropriately:

    Would you like to use LXD clustering? (yes/no) [default=no]: yes
    What name should be used to identify this node in the cluster? [default=lxd1]: lxd1
    What IP address or DNS name should be used to reach this node? [default=10.0.1.100]: 10.0.1.100
    Are you joining an existing cluster? (yes/no) [default=no]: no
    Setup password authentication on the cluster? (yes/no) [default=yes]: yes
    Trust password for new clients: pinehead
    Again: pinehead
    

    Configure the rest of the server to use the default settings.

  2. Challenge

    Add the Second Server to the Cluster

    Log into the second server via SSH.

    Use sudo lxd init to initialize the server with the provided prompts. This time, we want to ensure we join the cluster on 10.0.1.100, as well as print a preseed:

    Would you like to use LXD clustering? (yes/no) [default=no]: yes
    What name should be used to identify this node in the cluster? [default=lxd2]: lxd2
    What IP address or DNS name should be used to reach this node? [default=10.0.1.110]: 10.0.1.110
    Are you joining an existing cluster? (yes/no) [default=no]: yes
    IP address or FQDN of an existing cluster node: 10.0.1.100
    Cluster fingerprint: fa49603e55ef0a8fe4985a08d64ae785bdbcdaa9b97c7aefe6776244f2607085
    You can validate this fingerprint by running "lxc info" locally on 'lxd1' server.
    Is this the correct fingerprint? (yes/no) [default=no]: yes
    Cluster trust password: pinehead
    All existing data is lost when joining a cluster, continue? (yes/no) [default=no] yes
    Choose "size" property for storage pool "local":
    Choose "source" property for storage pool "local":
    Choose "zfs.pool_name" property for storage pool "local":
    Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: yes
    

    To check the fingerprint on the initial LXD server (lxd1), use lxc info during the configuration process:

    lxc info
    

    Copy the output preseed and save it to a file:

    vim preseed.yaml
    

    Note: If using Instant Terminal you will need to set the PASTE format in VIM using :SET PASTE to correctly paste the copied text.

    The copied text should look something like the example below - but do NOT copy the example settings below as it contains a different certificate.

    config:
      core.https_address: 10.0.1.110:8443
    networks:
    - config:
        bridge.mode: fan
        fan.underlay_subnet: 10.0.1.0/24
      description: ""
      managed: true
      name: lxdfan0
      type: bridge
    storage_pools:
    - config:
        size: 15GB
        source: ""
      description: ""
      name: local
      driver: zfs
    profiles:
    - config: {}
      description: ""
      devices: {}
      name: default
    cluster:
      server_name: lxd2
      enabled: true
      member_config: []
      cluster_address: 10.0.1.100:8443
      cluster_certificate: |
        -----BEGIN CERTIFICATE-----
        MIIB/TCCAYOgAwIBAgIQHcd/PX7W80q9XI9EI6ER6DAKBggqhkjOPQQDAzAyMRww
        GgYDVQQKExNsaW51eGNvbnRhaW5lcnMub3JnMRIwEAYDVQQDDAlyb290QGx4ZDEw
        HhcNMjAwMzAzMTUzOTIwWhcNMzAwMzAxMTUzOTIwWjAyMRwwGgYDVQQKExNsaW51
        eGNvbnRhaW5lcnMub3JnMRIwEAYDVQQDDAlyb290QGx4ZDEwdjAQBgcqhkjOPQIB
        BgUrgQQAIgNiAAT/9qymn5B8d1RVY3BCHz62Mo9MB9MtQEjlGdSG/W4NsxiVb1tH
        xp6Dbq27Sydkubzyz0hEwbw+tz7sr4CUkd2+n9MWQLmo79vH7sx5P7CoQAJ+n0NC
        94n+HqZwjG67rv2jXjBcMA4GA1UdDwEB/wQEAwIFoDATBgNVHSUEDDAKBggrBgEF
        BQcDATAMBgNVHRMBAf8EAjAAMCcGA1UdEQQgMB6CBGx4ZDGHBH8AAAGHEAAAAAAA
        AAAAAAAAAAAAAAEwCgYIKoZIzj0EAwMDaAAwZQIxAMF9XbIwl8y/amt2yaGUHsuQ
        SHSGswbKHo6uW5FFvLUDi6V7YZsWqR0YkBgdSV0xvQIwAeKK6YZT71Qyhuy52ptE
        X36Oo7aTeqZCckgR9GSsZ18zmLl0QlJHG9K+BKWbRrBj
        -----END CERTIFICATE-----
      server_address: 10.0.1.110:8443
      cluster_password: pinehead
    
  3. Challenge

    Add the Third Server to the Cluster

    From the lxd2 server, copy the preseed.yaml file to the lxd3 server:

    scp preseed.yaml [email protected]:
    

    Log into the lxd3 server with SSH:

    ssh [email protected]
    

    Open the preseed.yaml file and update the core.https_address to be 10.0.1.120:8443 Locate server_name and change it to lxd3:

    vim preseed.yaml
    
    core.https_address: 10.0.1.120:8443
    
    ...
    
    server_name: lxd3
    
    ...
    

    Initialize the server using the preseed file:

    cat preseed.yaml | sudo lxd init --preseed
    
  4. Challenge

    Create Containers

    Return to lxd1. View all clusters:

    lxc cluster list
    

    Create three containers to test the cluster:

    lxc launch images:alpine/3.11 web1
    lxc launch images:alpine/3.11 web2
    lxc launch images:alpine/3.11 web3
    

    To see which server on the cluster these containers ended up on, run lxc list and look for the location value. There should be one container per node.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans