29 联网环境的映像准备 #
Edge Image Builder 用于为管理集群创建映像,本文档涵盖了设置管理集群所需的最简配置。
Edge Image Builder 在容器内运行,因此需要容器运行时,例如 Podman 或 Rancher Desktop。在本指南中,我们假设 podman 可用。
此外,作为部署高可用管理集群的先决条件,您需要在网络中预留三个 IP:
apiVIP用于 API VIP 地址(用于访问 Kubernetes API 服务器)。ingressVIP用于 Ingress VIP 地址(例如,由 Rancher UI 使用)。metal3VIP用于 Metal3 VIP 地址。
29.1 目录结构 #
运行 EIB 时,会从主机挂载一个目录,因此首先要做的是创建一个目录结构,供 EIB 用于存储配置文件和镜像本身。 此目录有以下结构:
eib
├── mgmt-cluster.yaml
├── network
│ └── mgmt-cluster-node1.yaml
├── os-files
│ └── var
│ └── lib
│ └── rancher
│ └── rke2
│ └── server
│ └── manifests
│ └── rke2-ingress-config.yaml
├── kubernetes
│ ├── manifests
│ │ ├── neuvector-namespace.yaml
│ │ ├── ingress-l2-adv.yaml
│ │ └── ingress-ippool.yaml
│ ├── helm
│ │ └── values
│ │ ├── rancher.yaml
│ │ ├── neuvector.yaml
│ │ ├── longhorn.yaml
│ │ ├── metal3.yaml
│ │ └── certmanager.yaml
│ └── config
│ └── server.yaml
├── custom
│ ├── scripts
│ │ ├── 99-register.sh
│ │ ├── 99-mgmt-setup.sh
│ │ └── 99-alias.sh
│ └── files
│ ├── rancher.sh
│ ├── mgmt-stack-setup.service
│ ├── metal3.sh
│ └── basic-setup.sh
└── base-images镜像 SL-Micro.x86_64-6.2-Base-SelfInstall-GM.install.iso 必须从 SUSE 客户中心 或 SUSE 下载页面 下载,并且必须位于 base-images 文件夹下。
您应该检查镜像的 SHA256 校验和,以确保其未被篡改。校验和可以在下载镜像的同一位置找到。
目录结构的示例可以在 SUSE Telco Cloud GitHub 储存库的“telco-examples”文件夹下找到。
29.2 管理集群定义文件 #
mgmt-cluster.yaml 文件是管理集群的主要定义文件。它包含以下信息:
apiVersion: 1.3
image:
imageType: iso
arch: x86_64
baseImage: SL-Micro.x86_64-6.2-Base-SelfInstall-GM.install.iso
outputImageName: eib-mgmt-cluster-image.iso
operatingSystem:
isoConfiguration:
installDevice: /dev/sda
users:
- username: root
encryptedPassword: $ROOT_PASSWORD
packages:
packageList:
- jq
- open-iscsi
sccRegistrationCode: $SCC_REGISTRATION_CODE
kubernetes:
version: v1.35.4+rke2r1
helm:
charts:
- name: cert-manager
repositoryName: jetstack
version: 1.20.1
targetNamespace: cert-manager
valuesFile: certmanager.yaml
createNamespace: true
installationNamespace: kube-system
- name: suse-storage
releaseName: longhorn
version: 1.11.2
repositoryName: rancher-application-collection
targetNamespace: longhorn-system
createNamespace: true
installationNamespace: kube-system
valuesFile: longhorn.yaml
- name: metallb
version: 306.0.2+up0.15.3
targetNamespace: metallb-system
createNamespace: true
repositoryName: suse-edge-charts
installationNamespace: kube-system
- name: metal3
version: 306.0.29+up0.15.0
repositoryName: suse-edge-charts
targetNamespace: metal3-system
createNamespace: true
installationNamespace: kube-system
valuesFile: metal3.yaml
- name: rancher-turtles-providers
version: 306.0.7+up0.26.2
repositoryName: suse-edge-charts
targetNamespace: cattle-turtles-system
createNamespace: true
installationNamespace: kube-system
- name: neuvector-crd
version: 109.0.2+up2.10.2
repositoryName: rancher-charts
targetNamespace: neuvector
createNamespace: true
installationNamespace: kube-system
valuesFile: neuvector.yaml
- name: neuvector
version: 109.0.2+up2.10.2
repositoryName: rancher-charts
targetNamespace: neuvector
createNamespace: true
installationNamespace: kube-system
valuesFile: neuvector.yaml
- name: rancher
version: 2.14.2
repositoryName: rancher-prime
targetNamespace: cattle-system
createNamespace: true
installationNamespace: kube-system
valuesFile: rancher.yaml
repositories:
- name: jetstack
url: https://charts.jetstack.io
- name: rancher-charts
url: https://charts.rancher.io/
- name: suse-edge-charts
url: oci://registry.suse.com/edge/charts
- name: rancher-prime
url: https://charts.rancher.com/server-charts/prime
- name: rancher-application-collection
url: oci://dp.apps.rancher.io/charts
authentication:
username: $\{APPS.RANCHER.IO_USERNAME\}
password: $\{APPS.RANCHER.IO_ACCESS_TOKEN\}
network:
apiHost: $API_HOST
apiVIP: $API_VIP
nodes:
- hostname: mgmt-cluster-node1
initializer: true
type: server
# - hostname: mgmt-cluster-node2
# type: server
# - hostname: mgmt-cluster-node3
# type: server为了解释 mgmt-cluster.yaml 定义文件中的字段和值,我们将其分为以下几个部分。
镜像部分(定义文件):
image:
imageType: iso
arch: x86_64
baseImage: SL-Micro.x86_64-6.2-Base-SelfInstall-GM.install.iso
outputImageName: eib-mgmt-cluster-image.iso其中 baseImage 是您从 SUSE 客户中心或 SUSE 下载页面下载的原始镜像。outputImageName 是将用于置备管理集群的新镜像的名称。
操作系统部分(定义文件):
operatingSystem:
isoConfiguration:
installDevice: /dev/sda
users:
- username: root
encryptedPassword: $ROOT_PASSWORD
packages:
packageList:
- jq
sccRegistrationCode: $SCC_REGISTRATION_CODE其中 installDevice 是用于安装操作系统的设备,username 和 encryptedPassword 是用于访问系统的凭据,packageList 是要安装的软件包列表(jq 在安装过程中内部需要),而 sccRegistrationCode 是在构建时用于获取软件包和依赖项的注册代码,可从 SUSE 客户中心获得。
加密密码可以使用 openssl 命令生成,如下所示:
openssl passwd -6 MyPassword!123这将输出类似于以下内容的内容:
$6$UrXB1sAGs46DOiSq$HSwi9GFJLCorm0J53nF2Sq8YEoyINhHcObHzX2R8h13mswUIsMwzx4eUzn/rRx0QPV4JIb0eWCoNrxGiKH4R31Kubernetes 部分(定义文件):
kubernetes:
version: v1.35.4+rke2r1
helm:
charts:
- name: cert-manager
repositoryName: jetstack
version: 1.20.1
targetNamespace: cert-manager
valuesFile: certmanager.yaml
createNamespace: true
installationNamespace: kube-system
- name: suse-storage
releaseName: longhorn
version: 1.11.2
repositoryName: rancher-application-collection
targetNamespace: longhorn-system
createNamespace: true
installationNamespace: kube-system
valuesFile: longhorn.yaml
- name: metal3
version: 306.0.29+up0.15.0
repositoryName: suse-edge-charts
targetNamespace: metal3-system
createNamespace: true
installationNamespace: kube-system
valuesFile: metal3.yaml
- name: metallb
version: 306.0.2+up0.15.3
targetNamespace: metallb-system
createNamespace: true
repositoryName: suse-edge-charts
installationNamespace: kube-system
- name: rancher-turtles-providers
version: 306.0.7+up0.26.2
repositoryName: suse-edge-charts
targetNamespace: cattle-turtles-system
createNamespace: true
installationNamespace: kube-system
- name: neuvector-crd
version: 109.0.2+up2.10.2
repositoryName: rancher-charts
targetNamespace: neuvector
createNamespace: true
installationNamespace: kube-system
valuesFile: neuvector.yaml
- name: neuvector
version: 109.0.2+up2.10.2
repositoryName: rancher-charts
targetNamespace: neuvector
createNamespace: true
installationNamespace: kube-system
valuesFile: neuvector.yaml
- name: rancher
version: 2.14.2
repositoryName: rancher-prime
targetNamespace: cattle-system
createNamespace: true
installationNamespace: kube-system
valuesFile: rancher.yaml
repositories:
- name: jetstack
url: https://charts.jetstack.io
- name: rancher-charts
url: https://charts.rancher.io/
- name: suse-edge-charts
url: oci://registry.suse.com/edge/charts
- name: rancher-prime
url: https://charts.rancher.com/server-charts/prime
- name: rancher-application-collection
url: oci://dp.apps.rancher.io/charts
authentication:
username: $\{APPS.RANCHER.IO_USERNAME\}
password: $\{APPS.RANCHER.IO_ACCESS_TOKEN\}
network:
apiHost: $API_HOST
apiVIP: $API_VIP
nodes:
- hostname: mgmt-cluster-node1
initializer: true
type: server
# - hostname: mgmt-cluster-node2
# type: server
# - hostname: mgmt-cluster-node3
# type: serverhelm 部分包含要安装的 Helm chart 列表、要使用的存储库以及所有这些内容的版本配置。
network 部分包含网络配置,例如 RKE2 组件要使用的 apiHost 和 apiVIP。
apiVIP 应为网络中未使用的 IP 地址,且不应属于 DHCP 池(如果我们使用 DHCP 的话)。此外,当我们在多节点集群中使用 apiVIP 时,它用于访问 Kubernetes API 服务器。
apiHost 是 RKE2 组件要使用的 apiVIP 的名称解析。
nodes 部分包含集群中要使用的节点列表。在此示例中,使用的是单节点集群,但可以通过向列表中添加更多节点(取消注释行)来将其扩展为多节点集群。
集群中的节点名称必须唯一。
(可选)使用
initializer字段指定启动主机,否则它将是列表中的第一个节点。当需要网络配置时,节点名称必须与 网络文件夹 (第 29.5 节 “Networking 文件夹”) 中定义的主机名相同。
29.3 自定义文件夹 #
custom 文件夹包含以下子文件夹:
...
├── custom
│ ├── scripts
│ │ ├── 99-register.sh
│ │ ├── 99-mgmt-setup.sh
│ │ └── 99-alias.sh
│ └── files
│ ├── rancher.sh
│ ├── mgmt-stack-setup.service
│ ├── metal3.sh
│ └── basic-setup.sh
...custom/files文件夹包含管理集群要使用的配置文件。custom/scripts文件夹包含管理集群要使用的脚本。
custom/files 文件夹包含以下文件:
basic-setup.sh:包含Metal3、Rancher和MetalLB的配置参数。仅当您想要更改要使用的名称空间时才修改此文件。#!/bin/bash # Pre-requisites. Cluster already running export KUBECTL="/var/lib/rancher/rke2/bin/kubectl" export KUBECONFIG="/etc/rancher/rke2/rke2.yaml" ################## # METAL3 DETAILS # ################## export METAL3_CHART_TARGETNAMESPACE="metal3-system" ########### # METALLB # ########### export METALLBNAMESPACE="metallb-system" ########### # RANCHER # ########### export RANCHER_CHART_TARGETNAMESPACE="cattle-system" export RANCHER_FINALPASSWORD="adminadminadmin" die(){ echo ${1} 1>&2 exit ${2} }metal3.sh:包含要使用的Metal3组件的配置(无需修改)。在未来的版本中,此脚本将被替换为使用Rancher Turtles,以简化操作。#!/bin/bash set -euo pipefail BASEDIR="$(dirname "$0")" source ${BASEDIR}/basic-setup.sh METAL3LOCKNAMESPACE="default" METAL3LOCKCMNAME="metal3-lock" trap 'catch $? $LINENO' EXIT catch() { if [ "$1" != "0" ]; then echo "Error $1 occurred on $2" ${KUBECTL} delete configmap ${METAL3LOCKCMNAME} -n ${METAL3LOCKNAMESPACE} fi } # Get or create the lock to run all those steps just in a single node # As the first node is created WAY before the others, this should be enough # TODO: Investigate if leases is better if [ $(${KUBECTL} get cm -n ${METAL3LOCKNAMESPACE} ${METAL3LOCKCMNAME} -o name | wc -l) -lt 1 ]; then ${KUBECTL} create configmap ${METAL3LOCKCMNAME} -n ${METAL3LOCKNAMESPACE} --from-literal foo=bar else exit 0 fi # Wait for metal3 while ! ${KUBECTL} wait --for condition=ready -n ${METAL3_CHART_TARGETNAMESPACE} $(${KUBECTL} get pods -n ${METAL3_CHART_TARGETNAMESPACE} -l app.kubernetes.io/name=metal3-ironic -o name) --timeout=10s; do sleep 2 ; done # Get the ironic IP IRONICIP=$(${KUBECTL} get cm -n ${METAL3_CHART_TARGETNAMESPACE} ironic -o jsonpath='{.data.IRONIC_IP}') # If LoadBalancer, use metallb, else it is NodePort if [ $(${KUBECTL} get svc -n ${METAL3_CHART_TARGETNAMESPACE} metal3-metal3-ironic -o jsonpath='{.spec.type}') == "LoadBalancer" ]; then # Wait for metallb while ! ${KUBECTL} wait --for condition=ready -n ${METALLBNAMESPACE} $(${KUBECTL} get pods -n ${METALLBNAMESPACE} -l app.kubernetes.io/component=controller -o name) --timeout=10s; do sleep 2 ; done # Do not create the ippool if already created ${KUBECTL} get ipaddresspool -n ${METALLBNAMESPACE} ironic-ip-pool -o name || cat <<-EOF | ${KUBECTL} apply -f - apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: ironic-ip-pool namespace: ${METALLBNAMESPACE} spec: addresses: - ${IRONICIP}/32 serviceAllocation: priority: 100 serviceSelectors: - matchExpressions: - {key: app.kubernetes.io/name, operator: In, values: [metal3-ironic]} EOF # Same for L2 Advs ${KUBECTL} get L2Advertisement -n ${METALLBNAMESPACE} ironic-ip-pool-l2-adv -o name || cat <<-EOF | ${KUBECTL} apply -f - apiVersion: metallb.io/v1beta1 kind: L2Advertisement metadata: name: ironic-ip-pool-l2-adv namespace: ${METALLBNAMESPACE} spec: ipAddressPools: - ironic-ip-pool EOF fi # Clean up the lock cm ${KUBECTL} delete configmap ${METAL3LOCKCMNAME} -n ${METAL3LOCKNAMESPACE}rancher.sh:包含要使用的Rancher组件的配置(无需修改)。#!/bin/bash set -euo pipefail BASEDIR="$(dirname "$0")" source ${BASEDIR}/basic-setup.sh RANCHERLOCKNAMESPACE="default" RANCHERLOCKCMNAME="rancher-lock" if [ -z "${RANCHER_FINALPASSWORD}" ]; then # If there is no final password, then finish the setup right away exit 0 fi trap 'catch $? $LINENO' EXIT catch() { if [ "$1" != "0" ]; then echo "Error $1 occurred on $2" ${KUBECTL} delete configmap ${RANCHERLOCKCMNAME} -n ${RANCHERLOCKNAMESPACE} fi } # Get or create the lock to run all those steps just in a single node # As the first node is created WAY before the others, this should be enough # TODO: Investigate if leases is better if [ $(${KUBECTL} get cm -n ${RANCHERLOCKNAMESPACE} ${RANCHERLOCKCMNAME} -o name | wc -l) -lt 1 ]; then ${KUBECTL} create configmap ${RANCHERLOCKCMNAME} -n ${RANCHERLOCKNAMESPACE} --from-literal foo=bar else exit 0 fi # Wait for rancher to be deployed while ! ${KUBECTL} wait --for condition=ready -n ${RANCHER_CHART_TARGETNAMESPACE} $(${KUBECTL} get pods -n ${RANCHER_CHART_TARGETNAMESPACE} -l app=rancher -o name) --timeout=10s; do sleep 2 ; done until ${KUBECTL} get ingress -n ${RANCHER_CHART_TARGETNAMESPACE} rancher > /dev/null 2>&1; do sleep 10; done RANCHERBOOTSTRAPPASSWORD=$(${KUBECTL} get secret -n ${RANCHER_CHART_TARGETNAMESPACE} bootstrap-secret -o jsonpath='{.data.bootstrapPassword}' | base64 -d) RANCHERHOSTNAME=$(${KUBECTL} get ingress -n ${RANCHER_CHART_TARGETNAMESPACE} rancher -o jsonpath='{.spec.rules[0].host}') # Skip the whole process if things have been set already if [ -z $(${KUBECTL} get settings.management.cattle.io first-login -ojsonpath='{.value}') ]; then # Add the protocol RANCHERHOSTNAME="https://${RANCHERHOSTNAME}" TOKEN="" while [ -z "${TOKEN}" ]; do # Get token sleep 2 TOKEN=$(curl -sk -X POST ${RANCHERHOSTNAME}/v3-public/localProviders/local?action=login -H 'content-type: application/json' -d "{\"username\":\"admin\",\"password\":\"${RANCHERBOOTSTRAPPASSWORD}\"}" | jq -r .token) done # Set password curl -sk ${RANCHERHOSTNAME}/v3/users?action=changepassword -H 'content-type: application/json' -H "Authorization: Bearer $TOKEN" -d "{\"currentPassword\":\"${RANCHERBOOTSTRAPPASSWORD}\",\"newPassword\":\"${RANCHER_FINALPASSWORD}\"}" # Create a temporary API token (ttl=60 minutes) APITOKEN=$(curl -sk ${RANCHERHOSTNAME}/v3/token -H 'content-type: application/json' -H "Authorization: Bearer ${TOKEN}" -d '{"type":"token","description":"automation","ttl":3600000}' | jq -r .token) curl -sk ${RANCHERHOSTNAME}/v3/settings/server-url -H 'content-type: application/json' -H "Authorization: Bearer ${APITOKEN}" -X PUT -d "{\"name\":\"server-url\",\"value\":\"${RANCHERHOSTNAME}\"}" curl -sk ${RANCHERHOSTNAME}/v3/settings/telemetry-opt -X PUT -H 'content-type: application/json' -H 'accept: application/json' -H "Authorization: Bearer ${APITOKEN}" -d '{"value":"out"}' fi # Clean up the lock cm ${KUBECTL} delete configmap ${RANCHERLOCKCMNAME} -n ${RANCHERLOCKNAMESPACE}mgmt-stack-setup.service:包含在首次启动期间运行脚本以创建 systemd 服务的配置(无需修改)。[Unit] Description=Setup Management stack components Wants=network-online.target # It requires rke2 or k3s running, but it will not fail if those services are not present After=network.target network-online.target rke2-server.service k3s.service # At least, the basic-setup.sh one needs to be present ConditionPathExists=/opt/mgmt/bin/basic-setup.sh [Service] User=root Type=forking # Metal3 can take A LOT to download the IPA image TimeoutStartSec=1800 ExecStartPre=/bin/sh -c "echo 'Setting up Management components...'" # Scripts are executed in StartPre because Start can only run a single one ExecStartPre=/opt/mgmt/bin/rancher.sh ExecStartPre=/opt/mgmt/bin/metal3.sh ExecStart=/bin/sh -c "echo 'Finished setting up Management components'" RemainAfterExit=yes KillMode=process # Disable & delete everything ExecStartPost=rm -f /opt/mgmt/bin/rancher.sh ExecStartPost=rm -f /opt/mgmt/bin/metal3.sh ExecStartPost=rm -f /opt/mgmt/bin/basic-setup.sh ExecStartPost=/bin/sh -c "systemctl disable mgmt-stack-setup.service" ExecStartPost=rm -f /etc/systemd/system/mgmt-stack-setup.service [Install] WantedBy=multi-user.target
custom/scripts 文件夹包含以下文件:
99-alias.sh脚本:包含管理集群在首次启动时用于加载 kubeconfig 文件的别名(无需修改)。#!/bin/bash echo "alias k=kubectl" >> /etc/profile.local echo "alias kubectl=/var/lib/rancher/rke2/bin/kubectl" >> /etc/profile.local echo "export KUBECONFIG=/etc/rancher/rke2/rke2.yaml" >> /etc/profile.local99-mgmt-setup.sh脚本:包含在首次启动期间复制脚本的配置(无需修改)。#!/bin/bash # Copy the scripts from combustion to the final location mkdir -p /opt/mgmt/bin/ for script in basic-setup.sh rancher.sh metal3.sh; do cp ${script} /opt/mgmt/bin/ done # Copy the systemd unit file and enable it at boot cp mgmt-stack-setup.service /etc/systemd/system/mgmt-stack-setup.service systemctl enable mgmt-stack-setup.service99-register.sh脚本:包含使用 SCC 注册代码注册系统的配置。必须正确设置${SCC_ACCOUNT_EMAIL}和${SCC_REGISTRATION_CODE}才能使用您的帐户注册系统。#!/bin/bash set -euo pipefail # Registration https://www.suse.com/support/kb/doc/?id=000018564 if ! which SUSEConnect > /dev/null 2>&1; then zypper --non-interactive install suseconnect-ng fi SUSEConnect --email "${SCC_ACCOUNT_EMAIL}" --url "https://scc.suse.com" --regcode "${SCC_REGISTRATION_CODE}"
29.4 Kubernetes 文件夹 #
kubernetes 文件夹包含以下子文件夹:
...
├── kubernetes
│ ├── manifests
│ │ ├── rke2-ingress-config.yaml
│ │ ├── neuvector-namespace.yaml
│ │ ├── ingress-l2-adv.yaml
│ │ └── ingress-ippool.yaml
│ ├── helm
│ │ └── values
│ │ ├── rancher.yaml
│ │ ├── neuvector.yaml
│ │ ├── metal3.yaml
│ │ └── certmanager.yaml
│ └── config
│ └── server.yaml
...kubernetes/config 文件夹包含以下文件:
server.yaml:默认安装的CNI插件是Cilium,因此您无需创建此文件夹和文件来进行设置。如果您需要自定义CNI插件,可以使用kubernetes/config文件夹下的server.yaml文件。它包含以下信息:cni: - multus - cilium ingress-controller: traefik write-kubeconfig-mode: '0644' selinux: true system-default-registry: registry.rancher.com
Traefik 入口提供程序集成在 RKE2/K3s 中,是 SUSE Telco Cloud 3.6 版本中唯一支持的入口控制器,仍然可以暂时将 Ingress-NGINX 与 Traefik 一起运行,以支持复杂的入口迁移场景,但前提是 SUSE Telco Cloud 管理集群和/或下游集群已升级到版本 3.6,并且仅在执行该迁移所需的时间内。由于 Traefik 尚不是 RKE2 中的默认入口控制器(从 RKE2 v1.36 开始将是默认控制器),因此必须从 RKE2 服务器配置文件中明确“请求”它,从而需要在为配置 SUSE Telco Cloud 3.6 管理集群节点而生成的所有 EIB 自安装 ISO 映像中包含 kubernetes/config/server.yaml 文件。
RKE2 Ingress NGINX 到 Traefik 迁移 指南提供了有关 Traefik 入口控制器取代已停用的 Ingress-NGINX 后可用的入口迁移路径的详细信息。
os-files/var/lib/rancher/rke2/server/manifests 文件夹包含以下文件:
rke2-ingress-config.yaml:包含为管理集群创建Ingress服务的配置(无需修改)。apiVersion: helm.cattle.io/v1 kind: HelmChartConfig metadata: name: rke2-traefik namespace: kube-system spec: valuesContent: |- ingressClass: isDefaultClass: true ports: web: hostPort: null # disallow hostPort exposedPort: 80 websecure: hostPort: null # disallow hostPort exposedPort: 443 service: enabled: true type: LoadBalancer spec: externalTrafficPolicy: Local allocateLoadBalancerNodePorts: false # k8s GA from 1.24; supported by MetalLB providers: kubernetesIngressNginx: # this provider allows traefik to "understand" most of the ingress-nginx annotations enabled: true ingressClass: "rke2-ingress-nginx-migration" controllerClass: "rke2.cattle.io/ingress-nginx-migration"
HelmChartConfig 必须通过 os-files 包含到 /var/lib/rancher/rke2/server/manifests 目录中,而不是像以前版本中描述的那样通过 kubernetes/manifests 包含。
kubernetes/manifests 文件夹包含以下文件:
neuvector-namespace.yaml:包含创建NeuVector名称空间的配置(无需修改)。apiVersion: v1 kind: Namespace metadata: labels: pod-security.kubernetes.io/enforce: privileged name: neuvectoringress-l2-adv.yaml:包含为MetalLB组件创建L2Advertisement的配置(无需修改)。apiVersion: metallb.io/v1beta1 kind: L2Advertisement metadata: name: ingress-l2-adv namespace: metallb-system spec: ipAddressPools: - ingress-ippoolingress-ippool.yaml:包含为rke2-traefik组件创建 MetalLBIPAddressPool对象的配置。必须正确设置${INGRESS_VIP},以定义预留用于访问(内部)rke2-traefik服务的公开 IP 地址。apiVersion: metallb.io/v1beta1 kind: IPAddressPool metadata: name: ingress-ippool namespace: metallb-system spec: addresses: - ${INGRESS_VIP}/32 serviceAllocation: priority: 100 serviceSelectors: - matchExpressions: - {key: app.kubernetes.io/name, operator: In, values: [rke2-traefik]}
kubernetes/helm/values 文件夹包含以下文件:
rancher.yaml:包含创建Rancher组件的配置。必须正确设置${INGRESS_VIP},以定义要由Rancher组件使用的 IP 地址。访问Rancher组件的 URL 将为https://rancher-${INGRESS_VIP}.sslip.io。hostname: rancher-${INGRESS_VIP}.sslip.io bootstrapPassword: "foobar" replicas: 1 global: cattle: systemDefaultRegistry: "registry.rancher.com"neuvector.yaml:包含创建NeuVector组件的配置(无需修改)。controller: replicas: 1 ranchersso: enabled: true manager: enabled: false cve: scanner: enabled: false replicas: 1 k3s: enabled: true crdwebhook: enabled: false registry: "registry.rancher.com" global: cattle: systemDefaultRegistry: "registry.rancher.com"longhorn.yaml:包含创建Longhorn组件的配置。为确保在引导时下载必要的容器镜像,请添加您的 Rancher 应用程序集合凭据。privateRegistry: createSecret: true registryUrl: dp.apps.rancher.io registryUser: $\{APPS.RANCHER.IO_USERNAME\} registryPasswd: $\{APPS.RANCHER.IO_ACCESS_TOKEN\} registrySecret: rancher-app-collectionmetal3.yaml:包含创建Metal3组件的配置。必须正确设置${METAL3_VIP},以定义要由Metal3组件使用的 IP 地址。global: ironicIP: ${METAL3_VIP} enable_vmedia_tls: false predictableNicNames: "true" # trustedCAs: tls-ca-bundle # Optional: Uncomment and set to ConfigMap name for additional trusted CAs metal3-ironic: ipa: useHauler: false persistence: ironic: size: "5Gi"重要metal3-ironic.ipa.useHaulerHelm chart 参数 must 在隔离的环境中设置为true(布尔数据类型);这指示 Metal3 从嵌入式制品仓库中检索ironic-python-agent(IPA) 容器镜像,而不是尝试从互联网下载它。此 IPA 容器镜像必须额外包含在 EIB 隔离环境镜像定义文件 (第 30.1 节 “定义文件中的修改”)的embeddedArtifactRegistry.images列表中。
媒体服务器是 Metal3 中包含的一项可选功能(默认情况下处于禁用状态)。要使用 Metal3 功能,您需要在之前的清单中对其进行配置。 要使用 Metal3 媒体服务器,请指定以下变量:
将
enable_metal3_media_server添加到true以在全局部分启用媒体服务器功能。包含有关媒体服务器的以下配置,其中 $\{MEDIA_VOLUME_PATH} 是媒体中的媒体卷路径(例如
/home/metal3/bmh-image-cache)。metal3-media: mediaVolume: hostPath: ${MEDIA_VOLUME_PATH}
可以使用外部媒体服务器来存储镜像,如果您希望将其与 TLS 一起使用,则需要为 Metal3 提供受信任的 CA 捆绑包。
准备 CA 捆绑包:
首先,准备您的 CA 捆绑包文件,其中包含 Metal3 所需的所有证书。这包括您的外部媒体服务器的 CA 证书。
+ *可选 - 系统 CA 捆绑包:*如果 Metal3还需要信任公共 CA(例如,在访问外部 HTTPS 资源时),您可以包含系统 CA 捆绑包。从容器镜像中提取它,并将其与您的自定义证书连接起来:
+
# Extract system CAs from a container image
podman run --rm registry.suse.com/bci/bci-base:latest cat /etc/ssl/certs/ca-certificates.crt > system-cas.pem
# Concatenate system CAs with your custom CA
cat system-cas.pem your-custom-ca.crt > ca-bundle.pem+ 或者,如果您只需要您的自定义 CA:
+
cp your-custom-ca.crt ca-bundle.pem+
如果您包含系统 CA 捆绑包,则有责任使其保持最新。容器镜像中的系统 CA 捆绑包可能会随着证书过期或被吊销而过时。通过从更新的容器镜像中重新提取来定期刷新捆绑包。
创建 ConfigMap:
您可以通过两种方式创建 ConfigMap:
*使用清单文件(推荐用于 EIB):*创建文件
kubernetes/manifests/metal3-cacert-configmap.yaml并以内联方式包含 CA 证书包内容。您需要使用 4 个空格正确缩进证书的每一行:apiVersion: v1 kind: Namespace metadata: name: metal3-system --- apiVersion: v1 kind: ConfigMap metadata: name: tls-ca-bundle namespace: metal3-system data: ca-bundle.pem: | -----BEGIN CERTIFICATE----- MIIDXTCCAkWgAwIBAgIJAKJ... (your certificate content here) ... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- MIIEkjCCA3qgAwIBAgIQCgF... (additional certificates if any) ... -----END CERTIFICATE-----要从您的
ca-bundle.pem自动填充此文件,可以使用:cat > kubernetes/manifests/metal3-cacert-configmap.yaml <<EOF apiVersion: v1 kind: Namespace metadata: name: metal3-system --- apiVersion: v1 kind: ConfigMap metadata: name: tls-ca-bundle namespace: metal3-system data: ca-bundle.pem: | $(sed 's/^/ /' ca-bundle.pem) EOF*使用 kubectl 直接操作(适用于手动部署):*如果您不使用 EIB 并希望直接在集群上创建 ConfigMap:
kubectl -n metal3-system create configmap tls-ca-bundle --from-file=ca-bundle.pem=./ca-bundle.pem将
metal3.yaml文件中的global.trustedCAs值设置为引用 ConfigMap 名称:global: trustedCAs: tls-ca-bundle
certmanager.yaml:包含创建Cert-Manager组件的配置(无需修改)。installCRDs: true
29.5 Networking 文件夹 #
network 文件夹包含的文件数量与管理集群中的节点数量相同。在本例中,我们只有一个节点,因此只有一个名为 mgmt-cluster-node1.yaml 的文件。
文件名必须与上述 network/node 部分中 mgmt-cluster.yaml 定义文件中定义的主机名相匹配。
如果您需要自定义网络配置,例如使用特定的静态 IP 地址(无 DHCP 场景),则可以使用 network 文件夹下的 mgmt-cluster-node1.yaml 文件。它包含以下信息:
${MGMT_GATEWAY}:网关 IP 地址。${MGMT_DNS}:DNS 服务器 IP 地址。${MGMT_MAC}:网络接口的 MAC 地址。${MGMT_NODE_IP}:管理集群的 IP 地址。
routes:
config:
- destination: 0.0.0.0/0
metric: 100
next-hop-address: ${MGMT_GATEWAY}
next-hop-interface: eth0
table-id: 254
dns-resolver:
config:
server:
- ${MGMT_DNS}
- 8.8.8.8
interfaces:
- name: eth0
type: ethernet
state: up
mac-address: ${MGMT_MAC}
ipv4:
address:
- ip: ${MGMT_NODE_IP}
prefix-length: 24
dhcp: false
enabled: true
ipv6:
enabled: false如果您想使用 DHCP 获取 IP 地址,可以使用以下配置(必须使用 ${MGMT_MAC} 变量正确设置 MAC 地址):
## This is an example of a dhcp network configuration for a management cluster
interfaces:
- name: eth0
type: ethernet
state: up
mac-address: ${MGMT_MAC}
ipv4:
dhcp: true
enabled: true
ipv6:
enabled: false根据管理集群中的节点数量,您可以创建更多类似
mgmt-cluster-node2.yaml、mgmt-cluster-node3.yaml等的文件来配置其余节点。routes部分用于定义管理集群的路由表。