20180613
Transactional updates with kubic 小記
OS: openSUSE Tumbleweed Kubic
先解釋 Kubic
官方網站:
有一段說明
Container as a Service Platform based on Kubernetes atop openSUSE MicroOS
簡單來說就是以 openSUSE Tumbleweed 為 Base OS 來提供容器平台
- 裡面有使用 openSUSE MicroOS (https://en.opensuse.org/Kubic:MicroOS ) 來針對容器使用最佳化, 使用 atomic 方式針對 read-only room filesystem 進行升級
- 可以使用 docker and podman 來使用容器
- 可以使用 Kubernetes 來進行容器叢集管理
- openSUSE / SUSE 使用 velum ( https://github.com/kubic-project/velum ) 來進行 cluster 架設, 詳細可以看 Github 的說明
所以要使用 kubic 的第一步就是要了解 atomic 方式更新, 因為 openSUSE MicroOS 是 read-only root filesystem
- 無法直接用 zypper 安裝 套件
- 要使用 transactional-update 指令安裝套件
- 安裝完套件要 reboot 才會生效
- 可以 rollback 回到 snapshot
- 搭配 btrfs filesystem
想要了解 transactional-update 可以參考 openSUSE Conference 2018 這場演講
我擷取裡面的一張簡報
簡單來說就是進行變更的時候
- 會將現在的檔案系統建立快照 ( pre )
- 進行變更
- 建立變更後的快照 ( post )
- 要生效要重新開機
先來看看指令說明吧
# transactional-update --help
Syntax: transactional-update [options] [general-command...] [package-command]
transactional-update [options] individual-command
Applies modifications to the system to a new snapshot without touching
the running system.
General Commands:
cleanup Mark removable snapshots
grub.cfg Regenerate grub.cfg
bootloader Reinstall the bootloader
initrd Regenerate initrd
kdump Regenerate kdump initrd
reboot Reboot after update
shell Open rw shell in snapshot before exiting
...
如果使用 zypper 來安裝套件, 會得到下列相關錯誤訊息
Error: Subprocess failed. Error: RPM failed: error: can't create transaction lock on /var/lib/rpm/.rpm.lock (Read-only file system)
所以要使用 transactional-update 指令來安裝套件, 這邊也用 traceroute 套件來示範
# transactional-update pkg in traceroute
Checking for newer version.
transactional-update 2.3 started
Options: pkg in traceroute
Separate /var detected.
Creating read-only snapshot of current system state (#1)
Running in non UTF-8 locale. Setup is unsupported.
Copying /etc state into backup snapshot
Running in non UTF-8 locale. Setup is unsupported.
Copying /etc state into snapshot
Calling zypper install
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following NEW package is going to be installed:
traceroute
1 new package to install.
Overall download size: 0 B. Already cached: 52.5 KiB. After the operation,
additional 103.5 KiB will be used.
Continue? [y/n/...? shows all options] (y): Y
Checking for file conflicts: .............................................[done]
In cache traceroute-2.0.21-1.10.x86_64.rpm (1/1), 52.5 KiB (103.5 KiB unpacked)
(1/1) Installing: traceroute-2.0.21-1.10.x86_64 ..........................[done]
Trying to rebuild kdump initrd
Running in non UTF-8 locale. Setup is unsupported.
Please reboot your machine to activate the changes and avoid data loss.
transactional-update finished
這邊會提示要重開機才會生效
可以使用 findmnt 或是後面看到的 btrfs 指令來觀察目前的 snapshot
# findmnt /
TARGET SOURCE FSTYPE OPTIONS
/ /dev/sda2[/@/.snapshots/1/snapshot] btrfs ro,relatime,space_cache,subvolid=267,subvol=/@/.snapshots/1
使用 snapper list 來觀察目前的快照
# snapper list
Failed to set locale. Fix your system.
Running in non UTF-8 locale. Setup is unsupported.
Type | # | Pre # | Date | User | Cleanup | Description | Userdata
-------+---+-------+--------------------------+------+---------+-----------------------+--------------
single | 0 | | | root | | current |
single | 1 | | Wed Jun 13 13:45:15 2018 | root | | first root filesystem |
single | 2 | | Wed Jun 13 13:49:44 2018 | root | number | after installation | important=yes
pre | 3 | | Wed Jun 13 15:03:33 2018 | root | number | RO-Clone of #1 | important=yes
post | 4 | 3 | Wed Jun 13 15:03:34 2018 | root | | Snapshot Update |
如果去執行 traceroue 指令, 會發現沒辦法執行, 因為還沒有生效
重開機來進行生效
# reboot
重開機之後可以使用 btrfs 指令觀察目前的 snapshot
# btrfs subvolume get-default /
ID 274 gen 73 top level 266 path @/.snapshots/4/snapshot
如果要回到某個狀態 可以 使用 transactional-update rollback 快照號碼
# transactional-update rollback 1
transactional-update 2.3 started
Options: rollback 1
Separate /var detected.
Rollback to snapshot 1...
Running in non UTF-8 locale. Setup is unsupported.
Please reboot to finish rollback!
但是還是要重開機才會生效
這樣也算是跨出 kubic 一小步
~ enjoy it
Reference:
沒有留言:
張貼留言