qm set 9000 --scsi0 local-lvm:0,discard=on,ssd=1,format=qcow2,import-from=/root/debian-12-generic-amd64.qcow2 qm disk resize 9000 scsi0 20G
解释:
qm set 9000 --scsi0 local-lvm:0,discard=on,ssd=1,format=qcow2,import-from=/root/debian-12-generic-amd64.qcow2 :将第一个 ID 为 0 的 SCSI 磁盘设置为使用 local-lvm 存储,并提供丢弃、SSD 和 QCOW2 格式选项。它导入我们之前下载的 Debian 云映像作为磁盘的内容。
qm disk resize 9000 scsi0 20G :将 ID 为 VM 9000 的 ID 为 0 的磁盘调整为 20GB 的大小。
2.5. 设置引导顺序
确保我们的 VM 知道如何正确启动。设置引导顺序以优先从磁盘引导。
1
qm set 9000 --boot order=scsi0
解释: 将 VM 9000 的引导顺序设置为从 ID 为 0 的第一个 SCSI 磁盘引导。
2.6. 配置 CPU 和内存资源
我们的 VM 需要足够的资源来执行其任务。相应地配置 CPU 和内存分配。
1
qm set 9000 --cpu host --cores 2 --memory 2048
解释: 将 VM 9000 设置为使用具有 2 个 CPU 内核的主机 CPU 型号,并分配 2048 MB (2GB) 内存。
2.7. 配置 BIOS 和 EFI
为了实现平稳运行,我们需要为 VM 设置 BIOS 和 EFI 属性。
1
qm set 9000 --bios ovmf --efidisk0 local-lvm:1,format=qcow2,efitype=4m,pre-enrolled-keys=1
解释:
qm set 9000 --bios ovmf: Configures VM 9000 to use the OVMF BIOS. qm set 9000 --bios ovmf :将 VM 9000 配置为使用 OVMF BIOS。
--efidisk0 local-lvm:1,format=qcow2,efitype=4m,pre-enrolled-keys=1: Sets the first EFI disk with ID 1 to use the local-lvm storage, with QCOW2 format, an EFI partition size of 4MB, and pre-enrolled keys for secure boot. --efidisk0 local-lvm:1,format=qcow2,efitype=4m,pre-enrolled-keys=1 :将第一个 ID 为 1 的 EFI 磁盘设置为使用 local-lvm 存储,格式为 QCOW2,EFI 分区大小为 4MB,并使用预注册密钥进行安全启动。
2.8. 设置 Cloud-Init
通过附加 cloud-init 驱动器,为 VM 提供 cloud-init 功能。
1
qm set 9000 --ide2 local-lvm:cloudinit
解释:
将 ID 为 2 的第二个 IDE 磁盘设置为使用 local-lvm 存储,该存储将用作 VM 的 cloud-init 驱动器。
2.9. 启用 QEMU Guest Agent
通过启用 QEMU 客户机代理来增强 VM 交互。
1
qm set 9000 --agent enabled=1
解释: 启用 VM 9000 的 QEMU 客户机代理,从而从主机更好地与 VM 通信。
2.10. 自定义 Cloud-Init 设置
可以根据您的要求自定义 cloud-init 设置。访问 VM 控制台以进行必要的更改,例如网络设置、用户配置等。
2.11. 创建虚拟机模板
在最后一步中,我们将从自定义的 VM 创建可重用的 VM 模板。此模板允许我们快速部署具有相同配置的多个 VM 实例。
qm set 111 --ipconfig0 ip=192.168.23.111/24,gw=192.168.23.1 qm set 112 --ipconfig0 ip=192.168.23.112/24,gw=192.168.23.1 qm set 113 --ipconfig0 ip=192.168.23.113/24,gw=192.168.23.1
I0422 08:47:23.768881 20115 version.go:256] remote version is much newer: v1.30.0; falling back to: stable-1.29 [init] Using Kubernetes version: v1.29.4 [preflight] Running pre-flight checks [preflight] Pulling images required for setting up a Kubernetes cluster [preflight] This might take a minute or two, depending on the speed of your internet connection [preflight] You can also perform this action in beforehand using 'kubeadm config images pull' W0422 08:47:26.201196 20115 checks.go:835] detected that the sandbox image "registry.k8s.io/pause:3.6" of the container runtime is inconsistent with that used by kubeadm. It is recommended that using "registry.k8s.io/pause:3.9" as the CRI sandbox image. [certs] Using certificateDir folder "/etc/kubernetes/pki" [certs] Generating "ca" certificate and key [certs] Generating "apiserver" certificate and key [certs] apiserver serving cert is signed for DNS names [kubernetes kubernetes.default kubernetes.default.svc kubernetes.default.svc.cluster.local debian1] and IPs [10.96.0.1 192.168.23.111] [certs] Generating "apiserver-kubelet-client" certificate and key [certs] Generating "front-proxy-ca" certificate and key [certs] Generating "front-proxy-client" certificate and key [certs] Generating "etcd/ca" certificate and key [certs] Generating "etcd/server" certificate and key [certs] etcd/server serving cert is signed for DNS names [localhost debian1] and IPs [192.168.23.111 127.0.0.1 ::1] [certs] Generating "etcd/peer" certificate and key [certs] etcd/peer serving cert is signed for DNS names [localhost debian1] and IPs [192.168.23.111 127.0.0.1 ::1] [certs] Generating "etcd/healthcheck-client" certificate and key [certs] Generating "apiserver-etcd-client" certificate and key [certs] Generating "sa" key and public key [kubeconfig] Using kubeconfig folder "/etc/kubernetes" [kubeconfig] Writing "admin.conf" kubeconfig file [kubeconfig] Writing "super-admin.conf" kubeconfig file [kubeconfig] Writing "kubelet.conf" kubeconfig file [kubeconfig] Writing "controller-manager.conf" kubeconfig file [kubeconfig] Writing "scheduler.conf" kubeconfig file [etcd] Creating static Pod manifest for local etcd in "/etc/kubernetes/manifests" [control-plane] Using manifest folder "/etc/kubernetes/manifests" [control-plane] Creating static Pod manifest for "kube-apiserver" [control-plane] Creating static Pod manifest for "kube-controller-manager" [control-plane] Creating static Pod manifest for "kube-scheduler" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Starting the kubelet [wait-control-plane] Waiting for the kubelet to boot up the control plane as static Pods from directory "/etc/kubernetes/manifests". This can take up to 4m0s [apiclient] All control plane components are healthy after 8.501807 seconds [upload-config] Storing the configuration used in ConfigMap "kubeadm-config" in the "kube-system" Namespace [kubelet] Creating a ConfigMap "kubelet-config" in namespace kube-system with the configuration for the kubelets in the cluster [upload-certs] Skipping phase. Please see --upload-certs [mark-control-plane] Marking the node debian1 as control-plane by adding the labels: [node-role.kubernetes.io/control-plane node.kubernetes.io/exclude-from-external-load-balancers] [mark-control-plane] Marking the node debian1 as control-plane by adding the taints [node-role.kubernetes.io/control-plane:NoSchedule] [bootstrap-token] Using token: xrocr4.lm0nide5laift733 [bootstrap-token] Configuring bootstrap tokens, cluster-info ConfigMap, RBAC Roles [bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to get nodes [bootstrap-token] Configured RBAC rules to allow Node Bootstrap tokens to post CSRs in order for nodes to get long term certificate credentials [bootstrap-token] Configured RBAC rules to allow the csrapprover controller automatically approve CSRs from a Node Bootstrap Token [bootstrap-token] Configured RBAC rules to allow certificate rotation for all node client certificates in the cluster [bootstrap-token] Creating the "cluster-info" ConfigMap in the "kube-public" namespace [kubelet-finalize] Updating "/etc/kubernetes/kubelet.conf" to point to a rotatable kubelet client certificate and key [addons] Applied essential addon: CoreDNS [addons] Applied essential addon: kube-proxy
这可能会需要几分钟。完成之后你应该看到:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
You should now deploy a Pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: /docs/concepts/cluster-administration/addons/
You can now join any number of machines by running the following on each node as root:
[preflight] Running pre-flight checks [preflight] Reading configuration from the cluster... [preflight] FYI: You can look at this config file with 'kubectl -n kube-system get cm kubeadm-config -o yaml' [kubelet-start] Writing kubelet configuration to file "/var/lib/kubelet/config.yaml" [kubelet-start] Writing kubelet environment file with flags to file "/var/lib/kubelet/kubeadm-flags.env" [kubelet-start] Starting the kubelet [kubelet-start] Waiting for the kubelet to perform the TLS Bootstrap...
This node has joined the cluster: * Certificate signing request was sent to apiserver and a response was received. * The Kubelet was informed of the new secure connection details.
Run 'kubectl get nodes' on the control-plane to see this node join the cluster.
namespace/kube-flannel created serviceaccount/flannel created clusterrole.rbac.authorization.k8s.io/flannel created clusterrolebinding.rbac.authorization.k8s.io/flannel created configmap/kube-flannel-cfg created daemonset.apps/kube-flannel-ds created