K8S集群搭建错误解决

  • 2020-01-03
  • 74
  • 0
[root@k8s01 ~]# kubeadm init --pod-network-cidr 10.244.0.0/16
I0103 16:18:22.003120    9397 version.go:94] could not fetch a Kubernetes version from the internet: unable to get URL "https://dl.k8s.io/release/stable-1.txt": Get https://dl.k8s.io/release/stable-1.txt: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)
I0103 16:18:22.004123    9397 version.go:95] falling back to the local client version: v1.13.1
[init] Using Kubernetes version: v1.13.1
[preflight] Running pre-flight checks
    [WARNING SystemVerification]: this Docker version is not on the list of validated versions: 19.03.3. Latest validated version: 18.06
    [WARNING Service-Kubelet]: kubelet service is not enabled, please run 'systemctl enable kubelet.service'
error execution phase preflight: [preflight] Some fatal errors occurred:
    [ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
    [ERROR FileContent--proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
    [ERROR Swap]: running with swap on is not supported. Please disable swap
  • [ERROR NumCPU]: the number of available CPUs 1 is less than the required 2
    这个普遍是由于虚拟机设置的时候,给了单核.需要调整为双核.

  • [ERROR FileContent–proc-sys-net-bridge-bridge-nf-call-iptables]: /proc/sys/net/bridge/bridge-nf-call-iptables contents are not set to 1
    原因: linux系统网桥转发开关没有打开.
    设置 /proc/sys/net/bridge/bridge-nf-call-iptables 为 1 即可.

sysctl net.bridge.bridge-nf-call-iptables=1
  • [ERROR Swap]: running with swap on is not supported. Please disable swap
    解决办法:
  1. 临时解决: 执行命令swapoff -a
  2. 永久解决: 将fstab配置文件中的swap注释掉.
vim /etc/fstab
----------
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=efe1024f-5499-4a76-ac5c-d9efa49ec4a7 /boot                   xfs     defaults        0 0
#/dev/mapper/centos-swap swap                    swap    defaults        0 0

初始化成功:

Your Kubernetes master 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:
  https://kubernetes.io/docs/concepts/cluster-administration/addons/

You can now join any number of machines by running the following on each node
as root:

  kubeadm join 192.168.106.131:6443 --token 1r0shk.t1d0evxo9h9luhcm --discovery-token-ca-cert-hash sha256:43a9df76fc1dd08900f063819352294b5708bbee04724d27e8fff8e52f7bb229
[root@k8s01 ~]# kubectl get node
The connection to the server localhost:8080 was refused - did you specify the right host or port?

报错原因是kubectl命令需要绑定master节点.

export KUBECONFIG=/etc/kubernetes/admin.conf
-----
永久解决:
// 将以上的脚本,添加到 /etc/profile文件末尾.
vim /etc/profile
-------------------------------
# kubernetes
export KUBECONFIG=/etc/kubernetes/admin.conf
--------------------------------
// 更新配置文件
source /etc/profile 

参考:
kubeadm init 问题和解决问题记录

0

评论

还没有任何评论,你来说两句吧