4

给家里的k8s集群添加节点

 1 year ago
source link: https://www.bboy.app/2021/05/28/%E7%BB%99%E5%AE%B6%E9%87%8C%E7%9A%84k8s%E9%9B%86%E7%BE%A4%E6%B7%BB%E5%8A%A0%E8%8A%82%E7%82%B9/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

给家里的k8s集群添加节点

发表于

2021-05-28 分类于 kubernetes

20210528155925.png

家里的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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK