简介
家里的k8s是用kubespray搭建的,最近加了一台16g内存的软路由,装了esxi,在里面安装了软路由,dns,黑群晖之后还有大概8g多的内存,所以准备直接在里面再添加一个k8s节点,下面记录下
操作
关闭swap
vim /etc/fstab
注释掉
/dev/mapper/centos-swap swap swap defaults 0 0
然后
swapoff -a
设置主机名
hostnamectl set-hostname node8
配置hosts
这里我就不展示配置了,反正可以解析到集群就可以,有dns的直接忽略
配置yum源
这里我使用的是阿里云源
vim /etc/yum.repos.d/kubernetes.repo
下面是配置
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
安装kubeadm kubectl kublet
注意要安装对应版本
yum install kubeadm-1.21.0-0 kubectl-1.21.0-0 kubelet-1.21.0
导入镜像
ctr -n k8s.io images import coredns.tar
ctr -n k8s.io images import etcd.tar
ctr -n k8s.io images import kube-apiserver.tar
ctr -n k8s.io images import kube-controller-manager.tar
ctr -n k8s.io images import kube-proxy.tar
ctr -n k8s.io images import kube-scheduler.tar
ctr -n k8s.io images import pause.tar
ctr -n k8s.io images import pause:3.2.tar
创建token
在master节点执行
kubeadm token create
得到sha256
openssl x509 -pubkey -in /etc/kubernetes/pki/ca.crt | openssl rsa -pubin -outform der 2>/dev/null | \\n openssl dgst -sha256 -hex | sed 's/^.* //'
加入集群
kubeadm join k8s.bboysoul.cn:8080 --token j8ffm0.etst12vup9x714jh --discovery-token-ca-cert-hash sha256:b633abe2a11a7e1e4d32fa28exxe8234ss8a5ffdc7e215c8bc50508d5add874a --cri-socket /run/containerd/containerd.sock --v=6
因为我是使用containerd的所以要加上
--cri-socket /run/containerd/containerd.sock
之后就是处理各种在执行kubeadm join时候的问题了
报错
[ERROR FileContent--proc-sys-net-ipv4-ip_forward]: /proc/sys/net/ipv4/ip_forward contents are not set to 1
echo 1 > /proc/sys/net/ipv4/ip_forward
继续报错
[ERROR CRI]: container runtime is not running: output: time="2021-05-28T14:11:57+08:00" level=fatal msg="getting status of runtime failed: rpc error: code = Unimplemented desc = unknown service runtime.v1alpha2.RuntimeService"
编辑
vim /etc/containerd/config.toml
注释掉
disabled_plugins = ["cri"]
重启containerd
systemctl restart containerd
一直卡在
The HTTP call equal to 'curl -sSL http://localhost:10248/healthz' failed with error: Get "http://localhost:10248/healthz": dial tcp [::1]:10248: connect: connection refused.
表示kubelet没有起来,看了一下日志
Failed to construct kubelet dependencies" err="unable to load client CA file /etc/kubernetes/ssl/ca.crt: open /etc/kubernetes/ssl/ca.crt: no such file or directory"
创建一个软链接
ln -s /etc/kubernetes/pki/ /etc/kubernetes/ssl
[ERROR FileAvailable--etc-kubernetes-pki-ca.crt]: /etc/kubernetes/pki/ca.crt already exists
reset 下集群
kubeadm reset
之后重新kubeadm join就ok了
欢迎关注我的博客www.bboy.app
Have Fun