Intelligente Lösungen
in neuer Dimension

LXC-Container Debian-10

Hier beschreibe ich, wie ich meinen Basiscontainer mit Debian-10 erzeuge.

Voraussetzungen

  1. LXD ist installiert: lxd --version –> 4.1
  2. LXC ist installiert: lxc --version –> 4.1
  3. Es gibt diverse LXC-Netzwerke: lxc network list
1
2
3
4
5
6
7
8
9
+-------------+----------+---------+-------------+---------+
|    NAME     |   TYPE   | MANAGED | DESCRIPTION | USED BY |
+-------------+----------+---------+-------------+---------+
| enp0s31f6   | physical | NO      |             | 0       |
+-------------+----------+---------+-------------+---------+
| lxdhostonly | bridge   | YES     |             | 6       |
+-------------+----------+---------+-------------+---------+
| lxdnat      | bridge   | YES     |             | 5       |
+-------------+----------+---------+-------------+---------+

Basiscontainer einrichten

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[email protected]# lxc image list images:debian/10|grep x86_64
| debian/10 (7 more)               | 1e9364a19acc | yes    | Debian buster amd64 (20200516_05:24)   | x86_64       | VIRTUAL-MACHINE | 253.13MB | May 16, 2020 at 12:00am (UTC) |
| debian/10 (7 more)               | 310e84be2766 | yes    | Debian buster amd64 (20200516_05:24)   | x86_64       | CONTAINER       | 73.15MB  | May 16, 2020 at 12:00am (UTC) |
| debian/10/cloud (3 more)         | 0bdd03c3ef24 | yes    | Debian buster amd64 (20200516_05:24)   | x86_64       | VIRTUAL-MACHINE | 264.00MB | May 16, 2020 at 12:00am (UTC) |
| debian/10/cloud (3 more)         | f387c0cf358b | yes    | Debian buster amd64 (20200516_05:24)   | x86_64       | CONTAINER       | 87.64MB  | May 16, 2020 at 12:00am (UTC) |
[email protected]# lxc launch images:debian/10 debian-10
Creating debian-10
Starting debian-10                           
[email protected]# lxc list debian-10
+-----------+---------+---------------------+------+-----------+-----------+
|   NAME    |  STATE  |        IPV4         | IPV6 |   TYPE    | SNAPSHOTS |
+-----------+---------+---------------------+------+-----------+-----------+
| debian-10 | RUNNING | 10.38.131.61 (eth0) |      | CONTAINER | 0         |
+-----------+---------+---------------------+------+-----------+-----------+

Ansible-Zugriff freischalten

Für Ansible brauchen wir

  • Python
  • SSH
  • PublicKey in SSH

Hier die Kommandos:

1
2
3
4
5
6
7
8
9
[email protected]# lxc exec debian-10 /bin/bash
[email protected]# apt-get install openssh-server
[email protected]# mkdir .ssh
[email protected]# cat >.ssh/authorized_keys <<EOF
ssh-rsa AAAAB3NzaC1...ZDoITmw== [email protected]
EOF
[email protected]# chmod 700 .ssh
[email protected]# chmod 600 .ssh/authorized_keys
[email protected]# apt-get install python3

Ansible-Zugriff

  • Direkter Test: ansible debian-10 -m ping –> “[WARNING]: No hosts matched, nothing to do”
  • Ansible-Inventory erweitern
  • Erneuter Test: ansible debian-10 -m ping –> “Failed to connect to the host via ssh…”
  • ~/ssh/config erweitern oder Ansible-Setup erweitern
  • Erneuter Test: ansible debian-10 -m ping –> “SUCCESS”

Basiscontainer anpassen

1
$ ansible-playbook debian-basiscontainers.yml

Stand 2020-05-15 werden diese Aktionen durchgeführt:

  • Install joe openssh-server netcat acl
  • Deactivate HISTSIZE in /etc/skel/.bashrc und /root/.bashrc
  • Deactivate HISTFILESIZE in /etc/skel/.bashrc und /root/.bashrc
  • Extend /etc/bash.bashrc for better history
  • Set timezone to Europe/Berlin
  • Create some folders within /root: bin, systemd
  • Install apt-proxy.sh
  • Install apt-proxy.service

Container umhängen auf Host-Only-Netz

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
[email protected]# CONTAINER=debian-10
[email protected]# lxc network attach lxdhostonly "${CONTAINER}" eth0
[email protected]# lxc list "${CONTAINER}"
+-----------+---------+------+------+-----------+-----------+
|   NAME    |  STATE  | IPV4 | IPV6 |   TYPE    | SNAPSHOTS |
+-----------+---------+------+------+-----------+-----------+
| debian-10 | RUNNING |      |      | CONTAINER | 1         |
+-----------+---------+------+------+-----------+-----------+
[email protected]# lxc stop "${CONTAINER}"
[email protected]# lxc start "${CONTAINER}"
+-----------+---------+--------------------+------+-----------+-----------+
|   NAME    |  STATE  |        IPV4        | IPV6 |   TYPE    | SNAPSHOTS |
+-----------+---------+--------------------+------+-----------+-----------+
| debian-10 | RUNNING | 10.2.110.61 (eth0) |      | CONTAINER | 1         |
+-----------+---------+--------------------+------+-----------+-----------+

Test: Funktioniert der Ansible-Zugriff noch? Ja!

Änderungen

  • 2020-05-16: Erste Version