Incus快速起步
Ubuntu 24.04 LTS以及后续版本都默认包含了 incus 软件包,可以非常轻松直接安装:
安装Incus
sudo apt update
sudo apt install incus -y
将自己加入
incus-admin组以便能够以普通用户身份来管理:
加入
incus-admin 组sudo adduser $USER incus-admin
newgrp incus-admin
备注
incus有两个组:
incus是普通的用户使用,不提供配置和限制到每个用户的项目操作incus-adin允许所有的控制操作
incus初始化:
初始化incus
$ sudo incus admin init
Would you like to use clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]:
Name of the storage backend to use (lvm, lvmcluster, zfs, btrfs, dir) [default=zfs]:
Create a new ZFS pool? (yes/no) [default=yes]: no
Name of the existing ZFS pool or dataset: incus-zpool
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=incusbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
Would you like the server to be available over the network? (yes/no) [default=no]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]:
Would you like a YAML "init" preseed to be printed? (yes/no) [default=no]:
备注
这里使用了 Incus使用ZFS作为存储 实践构建的ZFS存储
启动运行 Debian 12:
运行debian 12容器
incus launch images:debian/12 debian12-dev
这里使用了 incus launch 表示下载、创建并直接启动容器(如果只想创建但不启动,可以使用 incus create )
image:debian/12 指定了官方镜像,这会下载最新的Debian 12(Bookworm)官方纯净系统镜像
debian12-dev 则是为容器起的名字
检查容器状态:
检查容器状态
incus list
输出类似:
检查容器状态
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| NAME | STATE | IPV4 | IPV6 | TYPE | SNAPSHOTS |
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
| debian12-dev | RUNNING | 10.108.19.229 (eth0) | fd42:77f7:87dd:98fc:216:3eff:feda:86a6 (eth0) | CONTAINER | 0 |
+--------------+---------+----------------------+-----------------------------------------------+-----------+-----------+
进入容器(方法其实类似Docker)
执行进入容器
incus exec debian12-dev -- bash
此时可以看到位于 root@debian12-dev:~# 提示符下,表明已经进入了容器内部
对于执行容器内命令,可以按照docker的方式来执行单条命令:
执行单条命令
incus exec debian-k8s-node1 -- apt update