使用 PVE 搭建 Kubernetes 集群

在前面我已经使用NUC10搭建好了PVE,最近热衷于Kubernetes的自动化部署,现在我们就基于PVE构建一个三个节点的Kubernetes 集群。

1.版本信息

  • Proxmox Virtual Environment 8.1.10
  • Debian 12.5.0
  • Kubernetes 1.29.4

2.使用 Cloud-Init 配置虚拟机模版

我们需要使用PVE创建三个服务器作为三个Kubernetes集群的节点,手动创建实在是麻烦,这里使用 Cloud-Init 配置一个Debian的虚拟机模版,来批量创建服务器。

2.1. 访问 Proxmox 主机

让我们通过SSH以root用户身份连接到PVE服务器(替换 pve-host-ip 为你的PVE服务器IP地址或主机名)。

1
ssh root@pve-host-ip

2.2. 下载 Debian Cloud 镜像

使用命令 wget 获取专为云环境设计的 Debian 云映像。

1
wget https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2

解释:
wget 命令从指定的 URL 下载 QCOW2 格式的最新 Debian 云映像。

2.3. 在 Proxmox 上创建虚拟机

现在,让我们使用 qm createqm set 命令在Proxmox上创建VM来配置VM属性。

1
qm create 9000 --name debian12-cloudinit --net0 virtio,bridge=vmbr0 --scsihw virtio-scsi-pci --machine q35

解释:

  • qm create 9000 :创建 ID 为 9000 的新 VM。
  • --name debian12-cloudinit :将虚拟机命名为 “debian12-cloudinit”。
  • --net0 virtio,bridge=vmbr0 :将第一个网络接口配置为使用“virtio”驱动程序并桥接到“vmbr0”。
  • --scsihw virtio-scsi-pci :将SCSI控制器硬件设置为“virtio-scsi-pci”。
  • --machine q35 :对 VM 使用 Q35 计算机类型。

2.4. 配置磁盘和内存

我们的 VM 需要磁盘和内存才能正常运行。让我们设置磁盘并将其大小调整为合适的大小,例如 8GB。

1
2
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 控制台以进行必要的更改,例如网络设置、用户配置等。

Proxmox Cloud-Init Settings

2.11. 创建虚拟机模板

在最后一步中,我们将从自定义的 VM 创建可重用的 VM 模板。此模板允许我们快速部署具有相同配置的多个 VM 实例。

1
qm template 9000

说明:从 VM 9000 创建模板,该模板可用作创建具有相同配置的新 VM 的基础。

2.12. 部署 Cloud-Init 模板

您可以通过克隆轻松部署此类模板:

1
2
3
qm clone 9000 111 --name Debian1
qm clone 9000 112 --name Debian2
qm clone 9000 113 --name Debian3

然后配置用于身份验证的 SSH 公钥:

1
2
3
qm set 111 --sshkey ~/.ssh/id_rsa.pub
qm set 112 --sshkey ~/.ssh/id_rsa.pub
qm set 113 --sshkey ~/.ssh/id_rsa.pub

说明:你可以使用ssh-genkey生成一个新的SSH私钥和公钥,~/.ssh/id_rsa.pub为生成公钥的路径。

配置三个服务器设置固定 IP :

1
2
3
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

说明:ip=192.168.110.111/24,gw=192.168.110.1需要配置为自己网络的IP和网管,Mac可以使用arp -a命令查看当前局域网的IP占用情况,避免设置为已经分配的IP。

2.13. 安装 QEMU 客户机代理

使用私钥SSH登陆创建好的服务器,接下来安装QEMU 客户机代理。

1
2
3
sudo apt update
sudo apt install -y qemu-guest-agent
sudo reboot

可选:你也可以修改apt源为国内源,设置SSH允许密码验证登陆,还有SSH允许root用户远程登录,具体参照其他教程。

配置虚拟机网络

我们已经创建好了三个虚拟机,如下:

ID Name IP 配置
111 Debian1 192.168.23.111 2C2-2G
112 Debian2 192.168.23.112 2C2-2G
113 Debian3 192.168.23.113 2C2-2G

3. 配置虚拟机网络

参考 https://kubernetes.io/docs/setup/production-environment/container-runtimes/#forwarding-ipv4-and-letting-iptables-see-bridged-traffic

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
cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

sudo modprobe overlay
sudo modprobe br_netfilter

# 设置所需的 sysctl 参数,参数在重新启动后保持不变
cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF

# 应用 sysctl 参数而不重新启动
sudo sysctl --system

# 通过运行以下指令确认 br_netfilter 和 overlay 模块被加载
lsmod | grep br_netfilter
lsmod | grep overlay

# 通过运行以下指令确认 net.bridge.bridge-nf-call-iptables、net.bridge.bridge-nf-call-ip6tables 和 net.ipv4.ip_forward 系统变量在你的 sysctl 配置中被设置为 1
sysctl net.bridge.bridge-nf-call-iptables net.bridge.bridge-nf-call-ip6tables net.ipv4.ip_forward

# 如果有防火墙需要参考此文档
# https://kubernetes.io/docs/reference/networking/ports-and-protocols/

4. 配置容器运行时

参考 https://kubernetes.io/docs/setup/production-environment/container-runtimes/#containerd

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装 containerd
sudo apt-get update && sudo apt-get install -y containerd

# 配置 containerd
sudo mkdir -p /etc/containerd
sudo containerd config default | sudo tee /etc/containerd/config.toml

# 修改为 SystemdCgroup
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/' /etc/containerd/config.toml
cat /etc/containerd/config.toml | grep SystemdCgroup

# 配置 containerd 服务
sudo systemctl enable containerd
sudo systemctl restart containerd
sudo systemctl status containerd

5. 安装 kubelet/kubeadm/kubectl

参考 https://v1-29.docs.kubernetes.io/zh-cn/docs/setup/production-environment/tools/kubeadm/install-kubeadm/

基于 Debian 的发行版

以下指令适用于 Kubernetes 1.29.

  1. 更新 apt 包索引并安装使用 Kubernetes apt 仓库所需要的包:

    1
    2
    3
    sudo apt-get update
    # apt-transport-https 可能是一个虚拟包(dummy package);如果是的话,你可以跳过安装这个包
    sudo apt-get install -y apt-transport-https ca-certificates curl gpg
  2. 下载用于 Kubernetes 软件包仓库的公共签名密钥。所有仓库都使用相同的签名密钥,因此你可以忽略URL中的版本:

    1
    2
    3
    # 如果 `/etc/apt/keyrings` 目录不存在,则应在 curl 命令之前创建它,请阅读下面的注释。
    # sudo mkdir -p -m 755 /etc/apt/keyrings
    curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.29/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

说明:

在低于 Debian 12 和 Ubuntu 22.04 的发行版本中,/etc/apt/keyrings 默认不存在。 应在 curl 命令之前创建它。

  1. 添加 Kubernetes apt 仓库。 请注意,此仓库仅包含适用于 Kubernetes 1.29 的软件包; 对于其他 Kubernetes 次要版本,则需要更改 URL 中的 Kubernetes 次要版本以匹配你所需的次要版本 (你还应该检查正在阅读的安装文档是否为你计划安装的 Kubernetes 版本的文档)。

    1
    2
    # 此操作会覆盖 /etc/apt/sources.list.d/kubernetes.list 中现存的所有配置。
    echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.29/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list
  2. 更新 apt 包索引,安装 kubelet、kubeadm 和 kubectl,并锁定其版本:

    1
    2
    3
    sudo apt-get update
    sudo apt-get install -y kubelet kubeadm kubectl
    sudo apt-mark hold kubelet kubeadm kubectl

kubelet 现在每隔几秒就会重启,因为它陷入了一个等待 kubeadm 指令的死循环。

6. 创建 Kubernetes 集群

6.1. 使用kubeadm创建主节点

在集群主节点虚拟机(我选Debian1)上执行:

1
2
3
4
# 提前拉取镜像
sudo kubeadm config images pull
# control-plane-endpoint 是控制平面的地址,node-name 是当前节点的名称,pod-network-cidr 是 pod 网络的网段(不能和集群内其他网段冲突)
sudo kubeadm init

有关 kubeadm init 参数的更多信息,请参见 kubeadm 参考指南

要使用配置文件配置 kubeadm init 命令, 请参见带配置文件使用 kubeadm init

要重新配置一个已经创建的集群, 请参见重新配置一个 kubeadm 集群

要再次运行 kubeadm init,你必须首先卸载集群

然后 kubeadm init 下载并安装集群控制平面组件。以下是执行日志:

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
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:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

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:

kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>

主节点已经安装完成,要使用非root用户kubectl,请运行以下命令配置kubeconfig,它们也是 kubeadm init 输出的一部分:

1
2
3
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config

如果是 root 用户,则可以运行:

1
export KUBECONFIG=/etc/kubernetes/admin.conf

记录 kubeadm init 输出的 kubeadm join 命令。 你需要此命令将节点加入集群

6.2. 安装 Pod 网络附加组件

在主节点执行以下命令:

1
2
# 安装 flannel
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml

6.3. 把 Worker 节点加入集群

SSH到另外两台虚拟机,运行 kubeadm init 输出的kubeadm join 命令:

1
2
sudo kubeadm join 192.168.23.111:6443 --token hki676.***** \
--discovery-token-ca-cert-hash sha256:*****

输出日志:

1
2
3
4
5
6
7
8
9
10
11
12
13
[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.

6.4.检查集群运行情况

执行命令:

1
kubectl get pods --all-namespaces

发现出现了问题:

1
2
3
4
5
6
7
8
9
10
kubectl get pods --all-namespaces
NAMESPACE NAME READY STATUS RESTARTS AGE
kube-flannel kube-flannel-ds-rgjkw 0/1 Error 1 (13s ago) 17s
kube-system coredns-76f75df574-8zzzc 0/1 ContainerCreating 0 68s
kube-system coredns-76f75df574-dc5nj 0/1 ContainerCreating 0 68s
kube-system etcd-debian1 1/1 Running 1 76s
kube-system kube-apiserver-debian1 1/1 Running 1 74s
kube-system kube-controller-manager-debian1 1/1 Running 1 72s
kube-system kube-proxy-jfxpg 1/1 Running 0 69s
kube-system kube-scheduler-debian1 1/1 Running 1 76s

kube-flannel 处于 Error 状态,检查日志:

1
kubectl logs kube-flannel-ds-rgjkw -n kube-flannel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Defaulted container "kube-flannel" out of: kube-flannel, install-cni-plugin (init), install-cni (init)
I0422 08:48:54.745393 1 main.go:210] CLI flags config: {etcdEndpoints:http://127.0.0.1:4001,http://127.0.0.1:2379 etcdPrefix:/coreos.com/network etcdKeyfile: etcdCertfile: etcdCAFile: etcdUsername: etcdPassword: version:false kubeSubnetMgr:true kubeApiUrl: kubeAnnotationPrefix:flannel.alpha.coreos.com kubeConfigFile: iface:[] ifaceRegex:[] ipMasq:true ifaceCanReach: subnetFile:/run/flannel/subnet.env publicIP: publicIPv6: subnetLeaseRenewMargin:60 healthzIP:0.0.0.0 healthzPort:0 iptablesResyncSeconds:5 iptablesForwardRules:true netConfPath:/etc/kube-flannel/net-conf.json setNodeNetworkUnavailable:true}
W0422 08:48:54.745534 1 client_config.go:618] Neither --kubeconfig nor --master was specified. Using the inClusterConfig. This might not work.
I0422 08:48:54.753856 1 kube.go:139] Waiting 10m0s for node controller to sync
I0422 08:48:54.753892 1 kube.go:455] Starting kube subnet manager
I0422 08:48:55.754600 1 kube.go:146] Node controller sync successful
I0422 08:48:55.754661 1 main.go:230] Created subnet manager: Kubernetes Subnet Manager - debian1
I0422 08:48:55.754668 1 main.go:233] Installing signal handlers
I0422 08:48:55.754745 1 main.go:442] Found network config - Backend type: vxlan
I0422 08:48:55.754782 1 match.go:210] Determining IP address of default interface
I0422 08:48:55.755018 1 match.go:263] Using interface with name eth0 and address 192.168.23.111
I0422 08:48:55.755063 1 match.go:285] Defaulting external address to interface address (192.168.23.111)
I0422 08:48:55.755189 1 vxlan.go:141] VXLAN config: VNI=1 Port=0 GBP=false Learning=false DirectRouting=false
I0422 08:48:55.757221 1 kube.go:621] List of node(debian1) annotations: map[string]string{"kubeadm.alpha.kubernetes.io/cri-socket":"unix:///var/run/containerd/containerd.sock", "node.alpha.kubernetes.io/ttl":"0", "volumes.kubernetes.io/controller-managed-attach-detach":"true"}
E0422 08:48:55.757488 1 main.go:333] Error registering network: failed to acquire lease: node "Debian1" pod cidr not assigned
I0422 08:48:55.757561 1 main.go:422] Stopping shutdownHandler...

通过这篇文章解决了这个问题:

https://dev.to/sherpaurgen/detected-that-the-sandbox-image-registryk8siopause38-of-the-container-runtime-is-inconsistent-with-that-used-by-kubeadm-1glc

解决方案:

在所有节点上创建文件 /run/flannel/subnet.env

1
2
3
4
5
6
cat <<EOF | tee /run/flannel/subnet.env
FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.244.0.0/16
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true
EOF

在所有节点上运行补丁:

1
2
3
kubectl patch node Debian1 -p '{"spec":{"podCIDR":"10.244.0.0/16"}}'
kubectl patch node Debian2 -p '{"spec":{"podCIDR":"10.244.0.0/16"}}'
kubectl patch node Debian3 -p '{"spec":{"podCIDR":"10.244.0.0/16"}}'

在主节点删除现有的 flannel:

1
kubectl delete -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
1
2
3
4
5
6
namespace "kube-flannel" deleted
serviceaccount "flannel" deleted
clusterrole.rbac.authorization.k8s.io "flannel" deleted
clusterrolebinding.rbac.authorization.k8s.io "flannel" deleted
configmap "kube-flannel-cfg" deleted
daemonset.apps "kube-flannel-ds" deleted

重新安装:

1
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
1
2
3
4
5
6
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

重新检查集群:

1
kubectl get pods --all-namespaces

现在集群恢复正常,pod都是Running的状态。

1
2
3
4
5
6
7
8
9
10
11
12
13
NAMESPACE      NAME                              READY   STATUS    RESTARTS      AGE
kube-flannel kube-flannel-ds-6gsgg 1/1 Running 0 98m
kube-flannel kube-flannel-ds-8kw4f 1/1 Running 0 97m
kube-flannel kube-flannel-ds-k7g9s 1/1 Running 0 96m
kube-system coredns-76f75df574-8zzzc 1/1 Running 0 109m
kube-system coredns-76f75df574-dc5nj 1/1 Running 0 109m
kube-system etcd-debian1 1/1 Running 0 109m
kube-system kube-apiserver-debian1 1/1 Running 0 109m
kube-system kube-controller-manager-debian1 1/1 Running 0 109m
kube-system kube-proxy-9sszr 1/1 Running 0 96m
kube-system kube-proxy-jfxpg 1/1 Running 0 109m
kube-system kube-proxy-nczj4 1/1 Running 0 97m
kube-system kube-scheduler-debian1 1/1 Running 0 109m

至此PVE安装Kubernetes集群结束。