Clustering LXD (Linux Container)

Membuat Cluster pada LXD (linux container)

IP address server LXD

  • LXD-1 : 192.168.88.11
  • LXD-2 : 192.168.88.12
  • LXD-3 : 192.168.88.13
  • Install lxd pada semua server
apt update
apt install zfsutils-linux -y
apt install lxd -y
  • Cek versi lxd
lxd --version
4.22

  • Buat network bridge pada node LXD-1
root@LXD-1:~/sys-ops.id# lxc network create lxdbr0 ipv6.address=none ipv4.address=10.101.10.1/24 ipv4.nat=true

root@LXD-1:~/sys-ops.id# ip a show lxdbr0
3: lxdbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 00:16:3e:39:15:04 brd ff:ff:ff:ff:ff:ff
    inet 10.101.10.1/24 scope global lxdbr0
       valid_lft forever preferred_lft forever
  • Setting cluster pada node LXD-1
root@LXD-1:~/sys-ops.id# lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: yes
What IP address or DNS name should be used to reach this node? [default=192.168.88.11]: 192.168.88.11
Are you joining an existing cluster? (yes/no) [default=no]: no
What name should be used to identify this node in the cluster? [default=LXD-1]: LXD-1
Setup password authentication on the cluster? (yes/no) [default=no]: yes
Trust password for new clients:
Again:
Do you want to configure a new local storage pool? (yes/no) [default=yes]: yes
Name of the storage backend to use (btrfs, dir, lvm, zfs) [default=zfs]: zfs
Create a new ZFS pool? (yes/no) [default=yes]: yes
Would you like to use an existing empty block device (e.g. a disk or partition)? (yes/no) [default=no]: no
Size in GB of the new loop device (1GB minimum) [default=7GB]: 25GB
Do you want to configure a new remote storage pool? (yes/no) [default=no]: no
Would you like to connect to a MAAS server? (yes/no) [default=no]: no
Would you like to configure LXD to use an existing bridge or host interface? (yes/no) [default=no]: yes
Name of the existing bridge or host interface: lxdbr0
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] yes
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: no
  • Setting join cluster pada node LXD-2 dan LXD-3
root@LXD-2:~/sys-ops.id# lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: yes
What IP address or DNS name should be used to reach this node? [default=192.168.88.12]: 192.168.88.12
Are you joining an existing cluster? (yes/no) [default=no]: yes
Do you have a join token? (yes/no/[token]) [default=no]: no
What name should be used to identify this node in the cluster? [default=LXD-2]: LXD-2
IP address or FQDN of an existing cluster member: 192.168.88.11
Cluster fingerprint: 76920933ccae436b613b1d9ecac60d1da7a0d46a94de7eb43ae6e66bcffe6f38
You can validate this fingerprint by running "lxc info" locally on an existing node.
Is this the correct fingerprint? (yes/no/[fingerprint]) [default=no]: yes
Cluster trust password:
All existing data is lost when joining a cluster, continue? (yes/no) [default=no] yes
Choose "size" property for storage pool "local": 25GB
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]: no
root@LXD-3:~/sys-ops.id# lxd init
Would you like to use LXD clustering? (yes/no) [default=no]: yes
What IP address or DNS name should be used to reach this node? [default=192.168.88.13]: 192.168.88.13
Are you joining an existing cluster? (yes/no) [default=no]: yes
Do you have a join token? (yes/no/[token]) [default=no]: no
What name should be used to identify this node in the cluster? [default=LXD-3]: LXD-3
IP address or FQDN of an existing cluster member: 192.168.88.11
Cluster fingerprint: 76920933ccae436b613b1d9ecac60d1da7a0d46a94de7eb43ae6e66bcffe6f38
You can validate this fingerprint by running "lxc info" locally on an existing node.
Is this the correct fingerprint? (yes/no/[fingerprint]) [default=no]: yes
Cluster trust password:
All existing data is lost when joining a cluster, continue? (yes/no) [default=no] yes
Choose "size" property for storage pool "local": 25GB
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]: no
  • Verifikasi cluster pada masing-masing node LXD
root@LXD-1:~/sys-ops.id# lxc cluster list
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| NAME  |            URL             |      ROLES      | ARCHITECTURE | FAILURE DOMAIN | DESCRIPTION | STATE  |      MESSAGE      |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-1 | https://192.168.88.11:8443 | database-leader | x86_64       | default        |             | ONLINE | Fully operational |
|       |                            | database        |              |                |             |        |                   |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-2 | https://192.168.88.12:8443 | database        | x86_64       | default        |             | ONLINE | Fully operational |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-3 | https://192.168.88.13:8443 | database        | x86_64       | default        |             | ONLINE | Fully operational |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+

root@LXD-2:~/sys-ops.id# lxc cluster list
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| NAME  |            URL             |      ROLES      | ARCHITECTURE | FAILURE DOMAIN | DESCRIPTION | STATE  |      MESSAGE      |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-1 | https://192.168.88.11:8443 | database-leader | x86_64       | default        |             | ONLINE | Fully operational |
|       |                            | database        |              |                |             |        |                   |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-2 | https://192.168.88.12:8443 | database        | x86_64       | default        |             | ONLINE | Fully operational |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-3 | https://192.168.88.13:8443 | database        | x86_64       | default        |             | ONLINE | Fully operational |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+

root@LXD-3:~/sys-ops.id# lxc cluster list
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| NAME  |            URL             |      ROLES      | ARCHITECTURE | FAILURE DOMAIN | DESCRIPTION | STATE  |      MESSAGE      |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-1 | https://192.168.88.11:8443 | database-leader | x86_64       | default        |             | ONLINE | Fully operational |
|       |                            | database        |              |                |             |        |                   |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-2 | https://192.168.88.12:8443 | database        | x86_64       | default        |             | ONLINE | Fully operational |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+
| LXD-3 | https://192.168.88.13:8443 | database        | x86_64       | default        |             | ONLINE | Fully operational |
+-------+----------------------------+-----------------+--------------+----------------+-------------+--------+-------------------+

  • Buat container ubuntu 20.04 pada masing-masing node LXD
root@LXD-1:~/sys-ops.id# lxc launch images:ubuntu/20.04/amd64 ubuntu-2004-c1
root@LXD-2:~/sys-ops.id# lxc launch images:ubuntu/20.04/amd64 ubuntu-2004-c2
root@LXD-3:~/sys-ops.id# lxc launch images:ubuntu/20.04/amd64 ubuntu-2004-c3
  • Verifikasi list container pada masing-masing node LXD
  • Akan terlihat setiap container yang buat akan tersebar ke masing-masing node LXD, karena secara default menggunakan algoritma round-robin agar beban node seimbang.
root@LXD-1:~/sys-ops.id# lxc list
+----------------+---------+----------------------+------+-----------+-----------+----------+
|      NAME      |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS | LOCATION |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c1 | RUNNING | 10.101.10.115 (eth0) |      | CONTAINER | 0         | LXD-1    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c2 | RUNNING | 10.101.10.48 (eth0)  |      | CONTAINER | 0         | LXD-2    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c3 | RUNNING | 10.101.10.41 (eth0)  |      | CONTAINER | 0         | LXD-3    |
+----------------+---------+----------------------+------+-----------+-----------+----------+

root@LXD-2:~/sys-ops.id# lxc list
+----------------+---------+----------------------+------+-----------+-----------+----------+
|      NAME      |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS | LOCATION |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c1 | RUNNING | 10.101.10.115 (eth0) |      | CONTAINER | 0         | LXD-1    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c2 | RUNNING | 10.101.10.48 (eth0)  |      | CONTAINER | 0         | LXD-2    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c3 | RUNNING | 10.101.10.41 (eth0)  |      | CONTAINER | 0         | LXD-3    |
+----------------+---------+----------------------+------+-----------+-----------+----------+

root@LXD-3:~/sys-ops.id# lxc list
+----------------+---------+----------------------+------+-----------+-----------+----------+
|      NAME      |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS | LOCATION |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c1 | RUNNING | 10.101.10.115 (eth0) |      | CONTAINER | 0         | LXD-1    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c2 | RUNNING | 10.101.10.48 (eth0)  |      | CONTAINER | 0         | LXD-2    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c3 | RUNNING | 10.101.10.41 (eth0)  |      | CONTAINER | 0         | LXD-3    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
  • Tes ping dari dalam container
root@LXD-1:~/sys-ops.id# lxc exec ubuntu-2004-c1 -- ping detik.com -c3
PING detik.com (203.190.242.211) 56(84) bytes of data.
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=1 ttl=47 time=83.6 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=2 ttl=47 time=89.4 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=3 ttl=47 time=86.9 ms

root@LXD-1:~/sys-ops.id# lxc exec ubuntu-2004-c2 -- ping detik.com -c3
PING detik.com (203.190.242.211) 56(84) bytes of data.
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=1 ttl=47 time=104 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=2 ttl=47 time=104 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=3 ttl=47 time=208 ms

root@LXD-1:~/sys-ops.id# lxc exec ubuntu-2004-c3 -- ping detik.com -c3
PING detik.com (203.190.242.211) 56(84) bytes of data.
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=1 ttl=47 time=108 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=2 ttl=47 time=626 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=3 ttl=47 time=101 ms

  • Menambahkan container pada spesifik node tertentu (node LXD-3)
root@LXD-3:~/sys-ops.id# lxc launch images:ubuntu/20.04/amd64 ubuntu-2004-c4 --target LXD-3

root@LXD-3:~/sys-ops.id# lxc list
+----------------+---------+----------------------+------+-----------+-----------+----------+
|      NAME      |  STATE  |         IPV4         | IPV6 |   TYPE    | SNAPSHOTS | LOCATION |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c1 | RUNNING | 10.101.10.115 (eth0) |      | CONTAINER | 0         | LXD-1    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c2 | RUNNING | 10.101.10.48 (eth0)  |      | CONTAINER | 0         | LXD-2    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c3 | RUNNING | 10.101.10.41 (eth0)  |      | CONTAINER | 0         | LXD-3    |
+----------------+---------+----------------------+------+-----------+-----------+----------+
| ubuntu-2004-c4 | RUNNING | 10.101.10.251 (eth0) |      | CONTAINER | 0         | LXD-3    |
+----------------+---------+----------------------+------+-----------+-----------+----------+

root@LXD-3:~/sys-ops.id# lxc exec ubuntu-2004-c4 -- ping detik.com -c3
PING detik.com (203.190.242.211) 56(84) bytes of data.
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=1 ttl=47 time=92.4 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=2 ttl=47 time=102 ms
64 bytes from s2-211-242.190.203.detik.com (203.190.242.211): icmp_seq=3 ttl=47 time=183 ms
  • Menambahkan virtual machine pada spesifik node tertentu (node LXD-2)
root@LXD-2:~/sys-ops.id# lxc launch images:centos/7/amd64 --vm centos-7-vm1 --target LXD-2

root@LXD-2:~/sys-ops.id# lxc list
+----------------+---------+----------------------+------+-----------------+-----------+----------+
|      NAME      |  STATE  |         IPV4         | IPV6 |      TYPE       | SNAPSHOTS | LOCATION |
+----------------+---------+----------------------+------+-----------------+-----------+----------+
| centos-7-vm1   | RUNNING | 10.101.10.75 (eth0)  |      | VIRTUAL-MACHINE | 0         | LXD-2    |
+----------------+---------+----------------------+------+-----------------+-----------+----------+
| ubuntu-2004-c1 | RUNNING | 10.101.10.115 (eth0) |      | CONTAINER       | 0         | LXD-1    |
+----------------+---------+----------------------+------+-----------------+-----------+----------+
| ubuntu-2004-c2 | RUNNING | 10.101.10.48 (eth0)  |      | CONTAINER       | 0         | LXD-2    |
+----------------+---------+----------------------+------+-----------------+-----------+----------+
| ubuntu-2004-c3 | RUNNING | 10.101.10.41 (eth0)  |      | CONTAINER       | 0         | LXD-3    |
+----------------+---------+----------------------+------+-----------------+-----------+----------+
| ubuntu-2004-c4 | RUNNING | 10.101.10.251 (eth0) |      | CONTAINER       | 0         | LXD-3    |
+----------------+---------+----------------------+------+-----------------+-----------+----------+
  • Cek perbedaan container pada virtual machinde dengan perintah hostnamectl, lihat pada bagian Virtualization
root@LXD-1:~/sys-ops.id# lxc exec centos-7-vm1 -- hostnamectl
   Static hostname: n/a
Transient hostname: localhost.localdomain
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 74a33cc07b6c4a738d10265de9bcdcc4
           Boot ID: 9f50416ae17b4d819e6cc43c3cbbac34
    Virtualization: kvm
  Operating System: CentOS Linux 7 (Core)
       CPE OS Name: cpe:/o:centos:centos:7
            Kernel: Linux 3.10.0-1160.53.1.el7.centos.plus.x86_64
      Architecture: x86-64

root@LXD-1:~/sys-ops.id# lxc exec ubuntu-2004-c1 -- hostnamectl
   Static hostname: ubuntu-2004-c1
         Icon name: computer-container
           Chassis: container
        Machine ID: a26c665c270d4c669ba8e04da6e60f7e
           Boot ID: dc76532c7f244278a6c64c80c3bf8927
    Virtualization: lxc
  Operating System: Ubuntu 20.04.3 LTS
            Kernel: Linux 5.4.0-99-generic
      Architecture: x86-64

  • Verifikasi network brige lxdbr0
root@LXD-1:~/sys-ops.id# lxc network list
+--------+----------+---------+----------------+------+-------------+---------+---------+
|  NAME  |   TYPE   | MANAGED |      IPV4      | IPV6 | DESCRIPTION | USED BY |  STATE  |
+--------+----------+---------+----------------+------+-------------+---------+---------+
| enp0s3 | physical | NO      |                |      |             | 0       |         |
+--------+----------+---------+----------------+------+-------------+---------+---------+
| lxdbr0 | bridge   | YES     | 10.101.10.1/24 | none |             | 5       | CREATED |
+--------+----------+---------+----------------+------+-------------+---------+---------+

root@LXD-1:~/sys-ops.id# lxc network show lxdbr0
config:
  ipv4.address: 10.101.10.1/24
  ipv4.nat: "true"
  ipv6.address: none
description: ""
name: lxdbr0
type: bridge
used_by:
- /1.0/instances/centos-7-vm1
- /1.0/instances/ubuntu-2004-c1
- /1.0/instances/ubuntu-2004-c2
- /1.0/instances/ubuntu-2004-c3
- /1.0/instances/ubuntu-2004-c4
- /1.0/profiles/default
managed: true
status: Created
locations:
- LXD-2
- LXD-3
- LXD-1

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.