your configuration file uses an old API spec: “kubeadm.k8s.io/v1alpha1”. Please use kubeadm v1.11 instead and run ‘kubeadm config migrate --old-config old.yaml --new-config new.yaml’, which will write the new, similar spec using a newer API version.
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
controllerManager:
extraArgs:
node-monitor-grace-period: "10s"
apiServer:
extraArgs:
runtime-config: "api/all=true"
kubernetesVersion: "v1.25.0"
imageRepository: "registry.aliyuncs.com/google_containers"
[kubelet-check] Initial timeout of 40s passed.
# systemctl status kubelet 查看日志
"Error getting node" err="node xxx not found"
# journalctl -xeu kubelet 错误同上
"Error getting node" err="node xxx not found"
# 删除现有的v1.25.0
apt remove kubeadm kubelet kubectl kubernetes-cni
# 重新安装一个旧版本的 如v1.23.0 (1.25和1.24都不行)
apt install -y kubelet=1.23.0-00 kubeadm=1.23.0-00 kubectl=1.23.0-00 (后面的-00必须要)
# 修改修改配置文件中k8s的版本
kubernetesVersion: "v1.23.10"
# 安装完成后直接执行kubeadm init
kubeadm init --config kubeadm.yaml
# 成功执行
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
....
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl describe pod coredns-6d8c4cb4d-drcgw -n kube-system
#logs
kubernetes installation and kube-dns: open /run/flannel/subnet.env: no such file or directory
cat < /run/flannel/subnet.env
FLANNEL_NETWORK=172.100.0.0/16
FLANNEL_SUBNET=172.100.1.0/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true
EOF
[preflight] Running pre-flight checks
Failed to request cluster-info, will try again: Get “https://xxxx:6443/api/v1/namespaces/kube-public/configmaps/cluster-info?timeout=10s”: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
可以发现是master节点的ip连不上,ping试一下发现ping不通。产生的原因是在master节点中使用的是云服务器的内网ip,在配置中改为公网ip就成功了。
controlPlaneEndpoint: "xxx.xxx.xxx.xxx(对应的公网IP):6443"
并且kubeadm init成功后的ip也为公网ip意味着修改完成。配置文件kubeadm.yaml如下:
apiVersion: kubeadm.k8s.io/v1alpha1
kind: MasterConfiguration
controllerManagerExtraArgs:
node-monitor-grace-period: "10s"
apiServerExtraArgs:
runtime-config: "api/all=true"
kubernetesVersion: "stable-1.11"
其中,“stable-1.11”就是kubeadm帮我们部署的Kubernetes版本号,即:Kubernetes release 1.11最新的稳定版,在我的环境下,它是v1.11.1。你也可以直接指定这个版本,比如:kubernetesVersion: “v1.11.1”。
kubeadm init --config kubeadm.yaml
your configuration file uses an old API spec: “kubeadm.k8s.io/v1alpha1”. Please use kubeadm v1.11 instead and run ‘kubeadm config migrate --old-config old.yaml --new-config new.yaml’, which will write the new, similar spec using a newer API version.
kubeadm config migrate --old-config old.yaml --new-config new.yaml
其实上述报错是因为配置文件中的kubernetesVersion和安装的kubeadm版本不一致,并且配置中的apiVersion也需要和此版本匹配。解决方法如下:
kubeadm version
# kubeadm version: &version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.0" ...}
kubernetesVersion: "v1.25.0"
apiVersion版本从最早的v1alpha1、v1alpha2…到现在的v1beta1、v1beta2等,随着kubeadm和kubernetesVersion版本的不同选择对应版本的apiVersion
Migration from old kubeadm config versions:
kubeadm v1.15.x and newer can be used to migrate from v1beta1 to v1beta2.
kubeadm v1.22.x and newer no longer support v1beta1 and older APIs, but can be used to migrate v1beta2 to v1beta3.
apiVersion: kubeadm.k8s.io/v1beta3
Ignored YAML document with GroupVersionKind kubeadm.k8s.io/v1beta3, Kind=MasterConfiguration
no InitConfiguration or ClusterConfiguration kind was found in the YAML file
To see the stack trace of this error execute with --v=5 or higher
apiVersion: kubeadm.k8s.io/v1beta3
kind: InitConfiguration
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
apiVersion: kubeadm.k8s.io/v1beta3
kind: JoinConfiguration
error unmarshaling configuration schema.GroupVersionKind{Group:“kubeadm.k8s.io”, Version:“v1beta3”, Kind:“ClusterConfiguration”}: strict decoding error: unknown field “apiServerExtraArgs”, unknown field “controllerManagerExtraArgs”
apiVersion: kubeadm.k8s.io/v1beta3
kind: ClusterConfiguration
controllerManager:
extraArgs:
node-monitor-grace-period: "10s"
apiServer:
extraArgs:
runtime-config: "api/all=true"
kubernetesVersion: "v1.25.0"
[init] Using Kubernetes version: v1.25.0
[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’
imageRepository: "registry.aliyuncs.com/google_containers"
[kubelet-check] Initial timeout of 40s passed.
# systemctl status kubelet 查看日志
"Error getting node" err="node xxx not found"
# journalctl -xeu kubelet 错误同上
"Error getting node" err="node xxx not found"
尝试了现有的解决方案在v1.25.0均无效,包括:
如果有大佬找到该问题在v1.25.0版本的解决方案,麻烦在评论区解答一下,万分感谢!
个人解决方法:换成旧版本的kubeadm(1.23以上都存在这个错误,1.23及以下就可以直接执行成功),重复执行上述命令直接成功。
# 删除现有的v1.25.0
apt remove kubeadm kubelet kubectl kubernetes-cni
# 重新安装一个旧版本的 如v1.23.0 (1.25和1.24都不行)
apt install -y kubelet=1.23.0-00 kubeadm=1.23.0-00 kubectl=1.23.0-00 (后面的-00必须要)
# 修改修改配置文件中k8s的版本
kubernetesVersion: "v1.23.10"
# 安装完成后直接执行kubeadm init
kubeadm init --config kubeadm.yaml
# 成功执行
Your Kubernetes control-plane has initialized successfully!
To start using your cluster, you need to run the following as a regular user:
....
至此集群中的master节点成功部署。并保存授权信息。
# kubeadm还会提示我们第一次使用Kubernetes集群所需要的配置命令:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
需要这些配置命令的原因是:Kubernetes集群默认需要加密方式访问。所以,这几条命令,就是将刚刚部署生成的Kubernetes集群的安全配置文件,保存到当前用户的.kube目录下,kubectl默认会使用这个目录下的授权信息访问Kubernetes集群。
# 查看nodes
root@master:/home/ubuntu# kubectl get nodes
NAME STATUS ROLES AGE VERSION
master NotReady control-plane,master 5m28s v1.23.0
# 查看日志
kubectl describe node master
NetworkReady=false reason:NetworkPluginNotReady message:docker: network plugin is not ready: cni config uninitialized
但是使用常用的kube-weave部署cni时一直卡住超时:
kubectl apply -f https://git.io/weave-kube-1.6
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f https://git.io/weave-kube-1.6
# 上述命令超时
kubectl apply -n kube-system -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
# 上述命令失败
# 使用kube-flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl describe pod coredns-6d8c4cb4d-drcgw -n kube-system
#logs
kubernetes installation and kube-dns: open /run/flannel/subnet.env: no such file or directory
cat < /run/flannel/subnet.env
FLANNEL_NETWORK=172.100.0.0/16
FLANNEL_SUBNET=172.100.1.0/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true
EOF
kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.0.0/aio/deploy/recommended.yaml
kubectl get pods --namespace=kubernetes-dashboard -o wide
Kubernetes的Worker节点跟Master节点几乎是相同的,它们运行着的都是一个kubelet组件。唯一的区别在于,在kubeadm init的过程中,kubelet启动后,Master节点上还会自动运行kube-apiserver、kube-scheduler、kube-controller-manger这三个系统Pod。
所以,相比之下,部署Worker节点反而是最简单的,只需要两步即可完成。
kubeadm join xxxx:6443 --token xxxx --discovery-token-ca-cert-hash sha256:xxxxxx
[preflight] Running pre-flight checks
Failed to request cluster-info, will try again: Get “https://xxxx:6443/api/v1/namespaces/kube-public/configmaps/cluster-info?timeout=10s”: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
可以发现是master节点的ip连不上,ping试一下发现ping不通。产生的原因是在master节点中使用的是云服务器的内网ip,在配置中改为公网ip就成功了。
controlPlaneEndpoint: "公网ip:6443"
并且kubeadm init成功后的ip也为公网ip意味着修改完成。
至此kubernetes集群搭建完毕!