Deployment Overview of LXD on Server¶
Prerequisites and Basic Requirements¶
The deployment process requires a server running a specific operating system version with administrative privileges. The following conditions must be met before initiating the installation:
- Operating System: Ubuntu 22.04 (codename
jammy). - Privileges: Root access or a user with
sudoprivileges is required to install system packages, manage services, and configure the firewall. - Dependencies: The system must have
snapdandsquashfs-toolsinstalled to support the LXD snap package. - Network: The server must have network connectivity to download the LXD snap and, if applicable, to allow external access to the LXD API/UI.
File and Directory Structure¶
The application utilizes specific directories for configuration, data storage, and certificate management. The following paths are established during the deployment:
- Nginx Configuration Directory:
/root/nginx- This directory contains the Docker Compose file and related configuration for the reverse proxy.
- Docker Compose File:
/root/nginx/compose.yml- Defines the services for the Nginx and Certbot container.
- User Configuration Directory:
/data/nginx/user_conf.d- Stores individual host configuration files, such as
{{ prefix }}{{ server_id }}.hostkey.in.conf.
- Stores individual host configuration files, such as
- Environment Variables:
/data/nginx/nginx-certbot.env- Contains environment variables required by the Nginx-Certbot container.
- Let's Encrypt Secrets:
/etc/letsencrypt- Mounted volume for storing SSL/TLS certificates and keys managed by Certbot.
Application Installation Process¶
The deployment involves installing the LXD container hypervisor via the Snap package manager and configuring a reverse proxy using Docker.
LXD Installation Steps:
- Install the
snapdandsquashfs-toolspackages using theaptpackage manager. - Install the LXD snap package using the command
snap install lxd --channel=<channel>. If LXD is already installed, it is refreshed to the desired channel usingsnap refresh lxd --channel=<channel>. - Wait for the LXD daemon to become ready by verifying the version with
/snap/bin/lxc version. - Initialize LXD with minimal defaults by running
/snap/bin/lxd init --minimalif the storage backend is not yet configured. - Configure the LXD UI setting using
snap set lxd ui.enable=<true|false>and restart the daemon withsystemctl restart snap.lxd.daemonif the setting changes. - Set the HTTPS listen address for the LXD API/UI using
/snap/bin/lxc config set core.https_address=<address>.
Docker and Proxy Installation Steps:
- Ensure the Docker CLI is present. If missing, install Docker and start the service.
- Wait for the Docker socket at
/var/run/docker.sockto become available. - Verify the Docker daemon is ready by running
docker info. - Create the directory
/root/nginxwith permissions0755owned byroot. - Generate the
compose.ymlfile in/root/nginxbased on the required configuration. - Update the Nginx user configuration file located at
/data/nginx/user_conf.d/{{ prefix }}{{ server_id }}.hostkey.in.confto include theproxy_passdirective pointing tohttps://127.0.0.1:<internal_port>. - Start the Nginx and Certbot containers by running
docker compose up -dfrom the/root/nginxdirectory.
Access Rights and Security¶
Security configurations include user group management and firewall rules to control access to the LXD service.
- User Group: The administrator user is added to the
lxdgroup to allow non-root execution of LXD commands. - Firewall (UFW):
- The
ufwpackage is installed if firewall management is enabled. - SSH access is allowed via the
OpenSSHrule. - The LXD HTTPS port is opened to allow traffic. By default, this allows connections from any IP address.
- If specific CIDR ranges are defined, the firewall is configured to allow traffic to the LXD HTTPS port only from those specific IP ranges.
- The
Docker Containers and Their Deployment¶
The reverse proxy and SSL management are handled by a Docker container orchestrated via Docker Compose.
- Container Image:
jonasal/nginx-certbot:latest - Restart Policy:
unless-stopped - Network Mode:
host - Volumes:
nginx_secrets(external) mounted to/etc/letsencryptfor certificate storage./data/nginx/user_conf.dmounted to/etc/nginx/user_conf.dfor custom Nginx configurations.
- Environment:
CERTBOT_EMAILis set to[email protected].- Additional environment variables are loaded from
/data/nginx/nginx-certbot.env.
Proxy Servers¶
The deployment utilizes Nginx as a reverse proxy with integrated Let's Encrypt (Certbot) for SSL/TLS certificate management.
- Service: Nginx running inside a Docker container.
- SSL Management: Certbot is used to automatically obtain and renew SSL certificates.
- Configuration: Custom host configurations are stored in
/data/nginx/user_conf.d. The proxy is configured to forward requests to the internal LXD service athttps://127.0.0.1:<internal_port>. - Domain: The configuration supports custom domains defined in the user configuration files.
Permission Settings¶
File and directory permissions are set to ensure secure operation of the services.
- Nginx Directory: The
/root/nginxdirectory is created with0755permissions, owned byroot:root. - Compose File: The
/root/nginx/compose.ymlfile is set to0644permissions, owned byroot:root. - User Configuration: Files in
/data/nginx/user_conf.dare managed by the deployment process to ensure the Nginx container can read the configuration.
Starting, Stopping, and Updating¶
The following commands are used to manage the services after deployment.
LXD Service Management:
- Restart Daemon:
systemctl restart snap.lxd.daemon - Check Version:
/snap/bin/lxc version - List Storage:
/snap/bin/lxc storage list --format csv
Docker Container Management:
- Start/Update Containers:
docker compose up -d(executed from/root/nginx) - Stop Containers:
docker compose down(executed from/root/nginx) - Check Docker Status:
docker info