KubeEdge部署 完美运行 附问题解决方法

KubeEdge部署

使用keadm安装部署kubeedge
使用两台机器做部署测试,一台云(master),一台边(node)

必备环境(工具)

云端:docker,k8s集群,k8s组件(kubelet、kubeadm、kubectl) ,golang
边缘端:docker,golang

以下操作是两台机器都需要进行的

1.配置网络参数

cat >> /etc/hosts << EOF
#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
192.30.255.112  github.com git
185.31.16.184 github.global.ssl.fastly.net
#GitHub End
EOF

2.关闭防火墙

systemctl disable firewalld

3.永久禁用SELinux

sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux

4.关闭swap

sed -ri 's/.*swap.*/#&/' /etc/fstab
5.安装docker
update-alternatives --set iptables /usr/sbin/iptables-legacy
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache
yum -y install docker-ce

systemctl start docker
systemctl enable docker

以下操作在云端机器进行

1.配置k8s yum源

cat < /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF

2.安装kubelet、kubeadm、kubectl

yum makecache
yum install -y kubelet-1.21.1 kubeadm-1.21.1 kubectl-1.21.1 ipvsadm
systemctl enable kubelet

3.配置内核参数

cat <  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
EOF

4.加载ipvs相关内核模块

modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe nf_conntrack_ipv4

lsmod | grep ip_vs

5.拉取镜像(将镜像切换为阿里云,特别重要,关乎到k8s集群能否成功)

kubeadm config print init-defaults > kubeadm.conf 
sed -i "s/imageRepository: .*/imageRepository: registry.aliyuncs.com\/google_containers/g" kubeadm.conf
kubeadm config images pull --config kubeadm.conf
docker images

如果发现已下载的镜像里面没有 registry.aliyuncs.com/google_containers/coredns/coredns:v1.8.0这个镜像
使用 docker 命令拉取镜像

docker pull registry.aliyuncs.com/google_containers/coredns:1.8.0
docker tag registry.aliyuncs.com/google_containers/coredns:1.8.0 registry.aliyuncs.com/google_containers/coredns/coredns:v1.8.0

6.初始化集群

kubeadm init --kubernetes-version=1.21.0 \
--image-repository registry.aliyuncs.com/google_containers  \
--pod-network-cidr=10.244.0.0/16

说明:
kubernetes-version 使用的k8s版本,根据需求自行更改
此处可能会出现问题,初始化失败,用以下命令清除后,重新初始化

kubeadm reset
ifconfig cni0 down
ip link delete cni0
ifconfig flannel.1 down
ip link delete flannel.1
rm -rf /var/lib/cni/
rm -rf /var/lib/etcd/*

7.初始化成功后,进一步配置

mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config

查看kubelet状态

systemctl status kubelet

8.初始化网络插进(flannel)

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
//重启kubelet
systemctl restart kubelet
//查看集群状态,应为running
kubectl get node
kubectl get pods -n kube-system
kubectl get svc

9.安装golang

yum install wget
wget https://golang.google.cn/dl/go1.15.3.linux-amd64.tar.gz
tar zxvf go1.15.3.linux-amd64.tar.gz
mv go /usr/local/

10.配置golang环境

##vi /etc/profile 结尾加
 
export GOROOT=/usr/local/go
export GOPATH=/data/gopath
export PATH=$PATH:$GOROOT/bin:$GOPATH/bin
//加载系统配置
source /etc/profile
//查看GO版本
go version

11.安装keadm

wget https://github.com/kubeedge/kubeedge/releases/download/v1.5.0/keadm-v1.5.0-linux-amd64.tar.gz

tar zxvf keadm-v1.5.0-linux-amd64.tar.gz 
cd keadm-v1.5.0-linux-amd64/keadm/
cp keadm /usr/local/sbin

12.云端安装kubeedge

keadm init --advertise-address="192.168.1.100" --kubeedge-version=1.8.0

–advertise-address 云端ip
–kubeedge-version kubeedge版本

如果安装报错,尝试如下解决办法

提前在/etc目录下创建kubeedge目录。里面放下载好的文件

/etc/kubeedge/crds/devices下存放
devices_v1alpha2_devicemodel.yaml、devices_v1alpha2_device.yaml两个文件

/etc/kubeedge/crds/reliablesyncs下存放
cluster_objectsync_v1alpha1.yaml、objectsync_v1alpha1.yaml两个文件

/etc/kubeedge下存放kubeedge-v1.8.0-linux-amd64.tar.gz、cloudcore.service
重新执行上述命令

13.利用keadm获取令牌

keadm gettoken

至此云端部署已完成


以下操作在边缘端机器进行

1.安装keadm

wget https://github.com/kubeedge/kubeedge/releases/download/v1.5.0/keadm-v1.5.0-linux-amd64.tar.gz

tar zxvf keadm-v1.5.0-linux-amd64.tar.gz 
cd keadm-v1.5.0-linux-amd64/keadm/
cp keadm /usr/local/sbin

2.加入到云端(此处可能出现问题)

./keadm join --cloudcore-ipport=192.168.1.47:10000 --token=1ee3a7a8183129a6d77aeced8a90437b843ec7615bd641fa773c32b067e7f904.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTQxNTIyMjl9.qofgOilyjO0sGy_O3wrFc9zhBuPBVNMilyE3duMthaw

解决办法

提前创建/etc/kubeedge
将edgecore.service、kubeedge-v1.8.0-linux-amd64.tar.gz 放在下/etc/kubeedge
重新执行上述命令

你可能感兴趣的:(Kubeedge,kubernetes,docker,容器)