项目场景

在Ubuntu22.04.3搭建k8s集群时,需要用kubeadm init初始化集群:

sudo kubeadm init \
        --apiserver-advertise-address=192.168.159.131 \
        --control-plane-endpoint=master \
        --image-repository  registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version v1.20.2 \
        --service-cidr=10.96.0.0/12 \
        --pod-network-cidr=10.244.0.0/16

问题描述

运行kubeadm init时,初始化集群失败。
出现了[ERROR Port-6443]: Port 6443 is in use,发现有端口号占用的情况;而且[ERROR FileAvailable–etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists提示了相关的yaml文件已存在。

[init] Using Kubernetes version: v1.20.2
[preflight] Running pre-flight checks
	[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 24.0.7. Latest validated version: 19.03
error execution phase preflight: [preflight] Some fatal errors occurred:
	[ERROR Port-6443]: Port 6443 is in use
	[ERROR Port-10259]: Port 10259 is in use
	[ERROR Port-10257]: Port 10257 is in use
	[ERROR FileAvailable--etc-kubernetes-manifests-kube-apiserver.yaml]: /etc/kubernetes/manifests/kube-apiserver.yaml already exists
	[ERROR FileAvailable--etc-kubernetes-manifests-kube-controller-manager.yaml]: /etc/kubernetes/manifests/kube-controller-manager.yaml already exists
	[ERROR FileAvailable--etc-kubernetes-manifests-kube-scheduler.yaml]: /etc/kubernetes/manifests/kube-scheduler.yaml already exists
	[ERROR FileAvailable--etc-kubernetes-manifests-etcd.yaml]: /etc/kubernetes/manifests/etcd.yaml already exists
	[ERROR Port-10250]: Port 10250 is in use
	[ERROR Port-2379]: Port 2379 is in use
	[ERROR Port-2380]: Port 2380 is in use
	[ERROR DirAvailable--var-lib-etcd]: /var/lib/etcd is not empty
[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`
To see the stack trace of this error execute with --v=5 or higher

原因分析:

说明了已有kubeadm在运行中,需要关闭当前已运行的kubeadm。

解决方案:

1.重启kubeadm

kubeadm reset

2.删除相关配置文件(终端提示有kubeadm reset 执行后不会删除$HOME/.kube文件,需要手动删除)

rm -r $HOME/.kube/config

3.重新输入kubeadm init

sudo kubeadm init \
        --apiserver-advertise-address=192.168.159.131 \
        --control-plane-endpoint=master \
        --image-repository  registry.cn-hangzhou.aliyuncs.com/google_containers --kubernetes-version v1.20.2 \
        --service-cidr=10.96.0.0/12 \
        --pod-network-cidr=10.244.0.0/16

之后会加载以下信息

[init] Using Kubernetes version: v1.20.2
[preflight] Running pre-flight checks
	[WARNING SystemVerification]: this Docker version is not on the list of validated versions: 24.0.7. Latest validated version: 19.03
[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'
[certs] Using certificateDir folder "/etc/kubernetes/pki"
[certs] Generating "ca" certificate and key
......(省略描述)

直至出现Your Kubernetes control-plane has initialized successfully!
成功将kubeadm主节点初始化了,如下图所示。
kubeadm successful

Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐