Rancher Elemental 使用随记

简介

Rancher Elemental 用于快速部署和管理基于容器的操作系统,如 SLE Micro 和 openSUSE MicroOS。它专为边缘计算和云原生环境设计,可以提供极简、易维护的操作系统。

使用随记

在 Rancher Extension 安装 Elemental:

添加一个 OS Channel:

1
2
3
4
5
6
7
8
9
10
11
apiVersion: elemental.cattle.io/v1beta1
kind: ManagedOSVersionChannel
metadata:
name: sl-micro-6.0-base-channel
namespace: fleet-default
spec:
deleteNoLongerInSyncVersions: false
options:
image: registry.suse.com/rancher/elemental-channel/sl-micro:6.0-base
syncInterval: 1h
type: custom

创建一个 MachineRegistration,Cloud Configuration 可以根据需求自定义,例如设置主机名、网络配置等:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
apiVersion: elemental.cattle.io/v1beta1
kind: MachineRegistration
metadata:
name: test
namespace: fleet-default
spec:
config:
cloud-config:
runcmd:
- systemctl daemon-reload
- zypper install --no-confirm openssh
- systemctl enable sshd
- systemctl start sshd
- zypper install --no-confirm bash-completion
users:
- name: root
passwd: password
ssh-authorized-keys:
- >-
ssh-rsa xxx
write_files:
- content: |
[connection]
id=eth0
type=ethernet
interface-name=eth0
autoconnect=true

[ipv4]
method=auto
dns=172.16.16.1;

[ipv6]
method=ignore
path: /etc/NetworkManager/system-connections/eth0.nmconnection
permissions: '0600'
- content: |
export CONTAINER_RUNTIME_ENDPOINT="unix:///run/k3s/containerd/containerd.sock"
export CONTAINERD_ADDRESS="/run/k3s/containerd/containerd.sock"
export CONTAINERD_NAMESPACE="k8s.io"
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/var/lib/rancher/rke2/bin
export KUBECONFIG=/etc/rancher/rke2/rke2.yaml
source <(kubectl completion bash)
path: /root/.bashrc
permissions: '0600'
- content: |
PermitRootLogin yes
UsePam yes
path: /etc/ssh/sshd_config.d/enable-root.conf
permissions: '0600'
elemental:
install:
device-selector:
- key: Name
operator: In
values:
- /dev/sda
- /dev/vda
- /dev/nvme0
- key: Size
operator: Gt
values:
- 25Gi
reboot: true
snapshotter:
type: btrfs
reset:
reboot: true
reset-oem: true
reset-persistent: true
machineInventoryLabels:
author: warner
BlockDevices: ${System Data/Block Devices/Number Devices}
CPUCores: ${System Data/CPU/Total Cores}
CPUModel: ${System Data/CPU/Model}
CPUThreads: ${System Data/CPU/Total Threads}
CPUVender: ${System Data/CPU/Vendor}
GPUVender: ${System Data/GPU/Vendor}
Hostname: ${System Data/Runtime/Hostname}
NetworkInterfaces: ${System Data/Network/Number Interfaces}
TotalMemoryBytes: ${System Data/Memory/Total Physical Bytes}
machineUUID: ${System Information/UUID}
manufacturer: ${System Information/Manufacturer}
serialNumber: ${System Information/Serial Number}

创建完后,选择对应的 OS Version 构建镜像,点击构建后在 fleet-default 命名空间下会生成一个 Pod,用于 Base Image 拉取、镜像构建、生成镜像下载地址:

在界面下载构建好的 ISO,也可以通过 SeedImage CRD 获取下载地址:

1
kubectl -n fleet-default get seedimages.elemental.cattle.io media-image-reg-xxx -ojsonpath={.status.downloadURL}

下载好后就可以通过这个 ISO 创建虚拟机,OS 安装过程中需要用到 TPM,所以需要在 vSphere 中开启本机类型的 TPM。

vSphere 开启本机类型的 TPM 有两个前提:

  1. vSphere 需要配置域名,否则创建好后会无法进行 TPM 备份,无法备份的话就无法给虚拟机添加 TPM 设备
  2. 创建虚拟机所在的主机需要在一个集群中,否则添加 TPM 设备后会无法创建

以上条件具备后,即可创建虚拟机,引导需要选择 EFI 模式:

开机后就会自动进行 OS 安装,并注册到 Rancher Elemental 集群中,可以在节点上通过命令查看注册状态:

1
journalctl -f -u elemental-register-install.service

注册没问题的话,会生成一个 MachineInventory,记录设备的详细信息:

接着就可以用这个节点创建集群:

Author

Warner Chen

Posted on

2024-11-20

Updated on

2025-09-16

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.