Harvester 使用随记

Harvester 是 SUSE 的一款开源 HCI 解决方案,基于 Kubernetes 的现代化 HCI 平台,旨在简化虚拟化管理,同时与云原生技术无缝集成。

Harvester 安装且对接 Rancher 后,就可以直接在 Rancher 进行虚拟机的创建/删除等动作。

如果 Harvester 集群只有一个节点,因为默认的 StorageClass 副本为 3,需要创建一个 StorageClass 用于代替。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
cat <<EOF | kubectl apply -f -
allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
annotations:
storageclass.beta.kubernetes.io/is-default-class: "true"
storageclass.kubernetes.io/is-default-class: "true"
name: harvester-longhorn-single-replicas
parameters:
migratable: "true"
numberOfReplicas: "1"
staleReplicaTimeout: "30"
provisioner: driver.longhorn.io
reclaimPolicy: Delete
volumeBindingMode: Immediate
EOF

上传 ISO 文件

虚拟机的创建的前提是需要有 ISO 文件,Harvester 支持本地上传和通过互联网下载两种方式:

清华 Ubuntu Cloud IMG

创建 Cluster Network

需要给 Harvester 节点准备多一张网卡给虚拟机用:

创建 VM Network Bridge

使用刚刚创建的 Cluster Network:

创建 VM Cloud Config Template

User Data:

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
#cloud-config
package_update: true
packages:
- qemu-guest-agent
write_files:
- path: /etc/sysctl.conf
permissions: 0644
owner: root
content: |
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
runcmd:
- systemctl enable --now qemu-guest-agent.service
- systemctl disable --now systemd-resolved.service
- rm -rf /etc/resolv.conf
- echo 'nameserver 172.16.16.12' > /etc/resolv.conf
- timedatectl set-timezone Asia/Shanghai
- sysctl -p
ssh_authorized_keys:
- ssh-rsa xxx
system_info:
default_user:
name: ubuntu
groups: users
lock_passwd: false
sudo: ALL=(ALL) NOPASSWD:ALL
plain_text_passwd: 'ubuntu'
homedir: /home/ubuntu
shell: /bin/bash

Network Data:

1
2
3
4
5
6
7
8
9
10
11
network:
version: 2
ethernets:
enp1s0:
dhcp4: false
dhcp6: false
addresses:
- 172.16.16.132/24
routes:
- to: default
via: 172.16.16.1

创建 VM

创建后,即可 ssh 到虚拟机中:

使用 Harvester 创建 RKE2 集群

Author

Warner Chen

Posted on

2025-01-14

Updated on

2025-02-27

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.