因为实习接触到了边缘计算这个领域,对于环境配置自己也踩了很多坑,走了些弯路。目前KubeEdge的安装文档也过于简略,所以安装问题实在很多。最后作为小白的我还是安装成功了。
目前最新版出到了1.7.1,但是安装教程大多较老,我是参考以下资料来做的。安装了我当时的最新版1.7.0
https://www.icode9.com/content-4-854301.html
https://www.bilibili.com/video/BV1GT4y1A756/?spm_id_from=333.788.recommend_more_video.0
在开始之前,部署Kubernetes集群机器需要满足以下几个条件:
KubeEdge由云和边缘组成。它建立在Kubernetes之上,为联网、应用部署和云与边缘之间的元数据同步提供核心基础设施支持。所以如果我们想要设置KubeEdge,我们需要设置Kubernetes集群(可以使用现有的集群),云端和边缘端。
cloud side
, 我们需要安装
edge side
, 我们需要安装
角色 | IP |
---|---|
master | 192.168.107.138 |
node | 192.168.107.x |
# 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
# 关闭selinux
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
# 关闭swap
swapoff -a # 临时
sed -ri 's/.*swap.*/#&/' /etc/fstab # 永久
# 根据规划设置主机名
hostnamectl set-hostname <hostname>
# 在master添加hosts
cat >> /etc/hosts << EOF
192.168.107.138 master
EOF
# 将桥接的IPv4流量传递到iptables的链
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system # 生效
# 时间同步
yum install ntpdate -y
ntpdate time.windows.com
Kubernetes默认CRI(容器运行时)为Docker,因此先安装Docker。
$ wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
$ yum -y install docker-ce-18.06.1.ce-3.el7
$ systemctl enable docker && systemctl start docker
$ docker --version
Docker version 18.06.1-ce, build e68fc7a
$ cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors": ["https://b9pmyelo.mirror.aliyuncs.com"]
}
EOF
$ systemctl restart docker
$ cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
由于版本更新频繁,这里指定版本号部署:
$ yum install -y kubelet-1.18.0 kubeadm-1.18.0 kubectl-1.18.0
$ systemctl enable kubelet
在192.168.31.61(Master)执行。
$ kubeadm init \
--apiserver-advertise-address=192.168.107.138 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.18.0 \
--service-cidr=10.96.0.0/12 \
--pod-network-cidr=10.244.0.0/16
由于默认拉取镜像地址k8s.gcr.io国内无法访问,这里指定阿里云镜像仓库地址。
使用kubectl工具:
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
$ kubectl get nodes
问题1:kubeadm reset
后kubeadm init
出现的问题
# kubectl get node
Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "kubernetes")`
问题1解决办法:
I got the same error while running $ kubectl get nodes
as a root user. I fixed it by exporting kubelet.conf
to environment variable.
$ export KUBECONFIG=/etc/kubernetes/kubelet.conf
$ kubectl get nodes
wget https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
如果下不了,建议手动下载到本机后,共享到服务器上。
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
kube-flannel-ds-amd64-2pc95 1/1 Running 0 72s
安装有两种方式,一种源码编译手动安装,还有一种是使用kubeedge提供的工具-keadm。手动安装比较繁琐,主要是编译X509
经常是个噩梦,有些编译报错网上搜索不到解决方案。对于新手而言是一种很大的心智负担,所以我还是用keadm这个工具去安装。
但是,这种方式安装最大的问题就是国内的墙的问题会导致很多某些资源无法下载,比如说 CRD的yaml,cloudcore启动的service,所以我会结合两者,采用半手动半工具的安装方式去帮助大家顺利的完成ke的集群搭建。
wget https://github.com/kubeedge/kubeedge/releases/download/v1.7.0/keadm-v1.7.0-linux-amd64.tar.gz
下载下来之后执行
tar -zxvf keadm-v1.7.0-linux-amd64.tar.gz # 解压keadm的tar.gz的包
cd keadm-v1.7.0-linux-amd64/keadm/
cp keadm /usr/sbin/ #将其配置进入环境变量,方便使用
输入:
keadm init --advertise-address=192.168.107.138 --kubeedge-version=1.7.0
–advertise-address=xxx.xx.xx.xx 这里的xxx.xx.xx.xx换成你master机器的ip,可以是内网地址,也可以是公网ip地址,–kubeedge-version=1.7.0 意思是指定安装的kubeEdge的版本,如果你默认不指定那么keadm会自动去下载最新的版本。
很遗憾,我在执行
keadm init --advertise-address=xxx.xx.xx.xx --kubeedge-version=1.7.0
命令的时候出错了,这个错的问题在于网络被墙了,特别是在公有云的虚拟机上,出现这种问题的概率特别大。
输出:
F0608 11:40:15.689702 5530 keadm.go:27] failed to exec 'bash -c cd /etc/kubeedge/crds/devices && wget -k --no-check-certificate --progress=bar:force https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/devices/devices_v1alpha2_device.yaml', err: --2021-06-08 11:39:54-- https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/devices/devices_v1alpha2_device.yaml
正在解析主机 raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.110.133, 185.199.108.133, ...
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... 失败:拒绝连接。
正在连接 raw.githubusercontent.com (raw.githubusercontent.com)|185.199.110.133|:443... 已连接。
无法建立 SSL 连接。
已转换了 0 个文件,用时 0 秒。
keadm init
失败解决方案# GitHub Start
52.74.223.119 github.com
192.30.253.119 gist.github.com
54.169.195.247 api.github.com
185.199.111.153 assets-cdn.github.com
151.101.76.133 raw.githubusercontent.com
151.101.108.133 user-images.githubusercontent.com
151.101.76.133 gist.githubusercontent.com
151.101.76.133 cloud.githubusercontent.com
151.101.76.133 camo.githubusercontent.com
151.101.76.133 avatars0.githubusercontent.com
151.101.76.133 avatars1.githubusercontent.com
151.101.76.133 avatars2.githubusercontent.com
151.101.76.133 avatars3.githubusercontent.com
151.101.76.133 avatars4.githubusercontent.com
151.101.76.133 avatars5.githubusercontent.com
151.101.76.133 avatars6.githubusercontent.com
151.101.76.133 avatars7.githubusercontent.com
151.101.76.133 avatars8.githubusercontent.com
# GitHub End
**目的:**解决keadm初始化过程中可能无法解析raw.githubusercontent.com的问题。
如果试了上述方法还是不行,我们回过头看错误
F0608 11:40:15.689702 5530 keadm.go:27] failed to exec 'bash -c cd /etc/kubeedge/crds/devices && wget -k --no-check-certificate --progress=bar:force https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/devices/devices_v1alpha2_device.yaml', err: --2021-06-08 11:39:54-- https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/devices/devices_v1alpha2_device.yaml
这是下载devices_v1alpha2_device.yaml
这个crd的yaml失败。
熟悉源码安装的朋友一定知道这就是用于设备接入的CRD。
一个叫devices_v1alpha2_device.yaml
,一个叫devices_v1alpha2_devicemodel
。
我的做法就是从源码里把这两个crd搞下来。
mkdir -p /etc/kubeedge/crds/devices && mkdir -p /etc/kubeedge/crds/reliablesyncs
将所需文件从https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/devices/devices_v1alpha2_device.yaml
下载下来,通过vmware共享文件夹共享到/etc/kubeedge/crds/devices
cd /mnt/hgfs/vmshare/ #我是用vmware共享文件的形式上传的,也可以采用其他共享文件方式
cp devices_v1alpha2_device.yaml /etc/kubeedge/crds/devices/
使用keadm安装cloudcore
输入:
keadm init --advertise-address=192.168.107.138 --kubeedge-version=1.7.0
**输出:**再次报错
F0608 14:10:11.700467 42153 keadm.go:27] failed to exec 'bash -c cd /etc/kubeedge/crds/devices && wget -k --no-check-certificate --progress=bar:force https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/devices/devices_v1alpha2_devicemodel.yaml', err: --2021-06-08 14:10:11-- https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/devices/devices_v1alpha2_devicemodel.yaml
同理将对应文件下载下来共享进入/etc/kubeedge/crds/devices
cd /mnt/hgfs/vmshare/ #我是用vmware共享文件的形式上传的,也可以采用其他共享文件方式
cp devices_v1alpha2_devicemodel.yaml /etc/kubeedge/crds/devices/
/etc/kubeedge/crds/
里面对应的文件夹要注意报错信息,不要完全按我提供的网站链接去配,不同版本的yaml配置文件不同,一定要选择错误提示的对应版本配置文件,不然校验过不了。
https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/reliablesyncs/cluster_objectsync_v1alpha1.yaml#例如,由该网站可知,文件应该共享到reliablesyncs
https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/reliablesyncs/objectsync_v1alpha1.yaml
https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/router/router_v1_rule.yaml
https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/crds/router/router_v1_ruleEndpoint.yaml
使用keadm安装cloudcore,关于yaml的配置文件配置完了,现在要配置cloudcore.service
,此处提醒文件应该存在/etc/kubeedge
里面,不是crds
里面了。
输入:
keadm init --advertise-address=192.168.107.138 --kubeedge-version=1.7.0
输出:
F0608 14:27:07.887553 45073 keadm.go:27] fail to download service file,error:{failed to exec 'bash -c cd /etc/kubeedge/ && sudo -E wget -t 5 -k --no-check-certificate https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/tools/cloudcore.service', err: --2021-06-08 14:27:07-- https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/tools/cloudcore.service
下载文件共享到/etc/kubeedge
https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/tools/cloudcore.service
https://github.com/kubeedge/kubeedge/releases/download/v1.7.0/kubeedge-v1.7.0-linux-amd64.tar.gz
输入:
keadm init --advertise-address=192.168.107.138 --kubeedge-version=1.7.0
输出:
Kubernetes version verification passed, KubeEdge installation will start...
Expected or Default KubeEdge version 1.7.0 is already downloaded and will checksum for it.
kubeedge-v1.7.0-linux-amd64.tar.gz checksum:
checksum_kubeedge-v1.7.0-linux-amd64.tar.gz.txt content:
kubeedge-v1.7.0-linux-amd64.tar.gz in your path checksum failed and do you want to delete this file and try to download again?
[y/N]:
此处输入N
,checksum
失败不影响配置,不必担心。选择y
通过不了。
附加输出信息
kubeedge-v1.7.0-linux-amd64/
kubeedge-v1.7.0-linux-amd64/edge/
kubeedge-v1.7.0-linux-amd64/edge/edgecore
kubeedge-v1.7.0-linux-amd64/cloud/
kubeedge-v1.7.0-linux-amd64/cloud/csidriver/
kubeedge-v1.7.0-linux-amd64/cloud/csidriver/csidriver
kubeedge-v1.7.0-linux-amd64/cloud/admission/
kubeedge-v1.7.0-linux-amd64/cloud/admission/admission
kubeedge-v1.7.0-linux-amd64/cloud/cloudcore/
kubeedge-v1.7.0-linux-amd64/cloud/cloudcore/cloudcore
kubeedge-v1.7.0-linux-amd64/version
KubeEdge cloudcore is running, For logs visit: /var/log/kubeedge/cloudcore.log
CloudCore started
keadm gettoken
更新yum源
$yum -y update
添加EPEL软件库
$yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
下载mosquitto
$yum -y install mosquitto
下载keadm
wget https://github.com/kubeedge/kubeedge/releases/download/v1.7.0/keadm-v1.7.0-linux-amd64.tar.gz
解压
tar -zxvf keadm-v1.7.0-linux-amd64.tar.gz
进入目录
cd /mnt/hgfs/vmshare #我将keadm存入在共享文件夹中
cd keadm-v1.7.0-linux-amd64/keadm
加入cloud
./keadm join --cloudcore-ipport=192.168.107.138:10000 --edgenode-name=node --kubeedge-version=1.7.0 --token=3dc13e89ee6b907f7346786d018d0fa4c1efa7ddb0017607c7512bc1b4926449.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjM5OTg0ODd9.hTQMyupZd5d_e5uOVtz3RVsfe9H_BSFnwuLzPRy2ZUg<上面keadm gettoken里面的返回内容>
输出:
F0608 15:03:13.805669 3177 keadm.go:27] failed to exec 'bash -c cd /etreleases/download/v1.7.0/kubeedge-v1.7.0-linux-F0608 15:05:37.624302 3197 keadm.go:27] failed to exec 'bash -c cd /etc/kubeedge/ && wget -k --no-check-certificate --progress=bar:force https://github.com/kubeedge/kubeedge/releases/download/v1.7.0/kubeedge-v1.7.0-linux-amd64.tar.gz', err: --2021-06-08 15:05:37-- https://github.com/kubeedge/kubeedge/releases/download/v1.7.0/kubeedge-v1.7.0-linux-amd64.tar.gz
正在解析主机 github.com (github.com)... 13.250.177.223
正在连接 github.com (github.com)|13.250.177.223|:443... 已连接。
无法建立 SSL 连接。
已转换了 0 个文件,用时 0 秒。
amd64.tar.gz', err: --2021md64.tar.gz
正在解析主机 github.com (github.com)... 13.229.188.59
正在连接 github.com (github.com)|13.229.188.59|:443... 已连接。
无法建立 SSL 连接。
已转换了 0 个文件,用时 0 秒。
同样类似于cloudcore,将下面对应文件共享到配置目录/etc/kubeedge
https://github.com/kubeedge/kubeedge/releases/download/v1.7.0/kubeedge-v1.7.0-linux-amd64.tar.gz
https://raw.githubusercontent.com/kubeedge/kubeedge/release-1.7/build/tools/edgecore.service
在master节点
输入
kubectl get nodes
输出
NAME STATUS ROLES AGE VERSION
master Ready master 4h4m v1.18.0
node Ready agent,edge 9s v1.19.3-kubeedge-v1.7.0