1、第一个报错是因为没有关闭swap分区,由于我自己在虚拟机上面安装的,将swap分区没有关闭,报错如下

[ERROR Swap]: running with swap on is not supported. Please disable swap

解决方法:

swapoff -a

关闭swap分区之后,继续执行kubeadm init   准备初始化集群。


2、由于第一次安装了calico网络插件,准备替换成flannel插件,报错如下:

Warning FailedCreatePodSandBox 7m52s kubelet Failed to create pod sandbox:
rpc error: code = Unknown desc = failed to set up sandbox container "abef835314ad175e12170af25ddc0603962e94d6818e71dd52c532c601fcfa8e" 
network for pod "coredns-6c76c8bb89-6krhq": networkPlugin cni failed to set up 
pod "coredns-6c76c8bb89-6krhq_kube-system" network: stat /var/lib/calico/nodename:
no such file or directory: check that the calico/node container is running and has mounted /var/lib/calico/

看到这个信息之后,发现明明安装的是flannel 插件,和calico有什么关系呢,莫名其妙。最后发现之前的calico pod虽然已经删除,但是在其在位时间中创建的家产还在呢,就是/var/lib/cni/calico 和/etc/cni/net.d/*,找到这两个目录,删除文件就可以。

解决办法:

删除节点上关于calico的配置信息,并重启kubelet服务
rm -rf /etc/cni/net.d/*
rm -rf /var/lib/cni/calico
systemctl restart kubelet
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl apply -f kube-flannel.yml

3、报错信息:open /run/flannel/subnet.env: no such file or directory

networkPlugin cni failed to set up pod “coredns-9d85f5447-2j4t8_kube-system” network: open /run/flannel/subnet.env: no such file or directory

查看这个文件内容,是否有如下输出:

FLANNEL_NETWORK=10.244.0.0/16
FLANNEL_SUBNET=10.224.0.1/24
FLANNEL_MTU=1450
FLANNEL_IPMASQ=true

10.244.0.0 这个ip地址在初始化集群的时候就指定,下面是在初始化集群时候使用的yml文件。大家可以参考参考。

cat kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
  - system:bootstrappers:kubeadm:default-node-token
  token: abcdef.0123456789abcdef
  ttl: 24h0m0s
  usages:
  - signing
  - authentication
kind: InitConfiguration
localAPIEndpoint:
  advertiseAddress: 10.0.2.4  #这里是自己master节点的IP,就是本机IP
  bindPort: 6443
nodeRegistration:
  criSocket: /var/run/dockershim.sock
  imagePullPolicy: IfNotPresent
  name: master-2-4  #本机的hostname
  taints: null
---
apiServer:
  timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager: {}
dns: {}
etcd:
  local:
    dataDir: /var/lib/etcd
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers
kind: ClusterConfiguration
kubernetesVersion: 1.22.0
networking:
  dnsDomain: cluster.local
  podSubnet: "10.244.0.0/16"  #这里的IP地址
  serviceSubnet: 10.96.0.0/12   
scheduler: {}

4、Kubernetes的从节点上运行 kubectl get nodes 命令出现了如下错误

The connection to the server localhost:8080 was refused - did you specify the right host or port?

原因:出现这个问题的原因是kubectl命令需要使用kubernetes-admin来运行,解决方法如下,将主节点中的【/etc/kubernetes/admin.conf】文件拷贝到从节点相同目录下,然后配置环境变量。

echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
source ~/.bash_profile

刚刚初始化的从节点是没有admin.conf这个文件,这个文件可以从master节点中传输到从节点上面。

scp /etc/kubernetes/admin.conf node1:/etc/kubernetes/

重新执行kubectl get nodes就可以查看了

Logo

开源、云原生的融合云平台

更多推荐