使用keadm安装部署kubeedge
使用两台机器做部署测试,一台云(master),一台边(node)
云端:docker,k8s集群,k8s组件(kubelet、kubeadm、kubectl) ,golang
边缘端:docker,golang
以下操作是两台机器都需要进行的
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
systemctl disable firewalld
sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux
sed -ri 's/.*swap.*/#&/' /etc/fstab
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
以下操作在云端机器进行
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
yum makecache
yum install -y kubelet-1.21.1 kubeadm-1.21.1 kubectl-1.21.1 ipvsadm
systemctl enable kubelet
cat < /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
EOF
modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
modprobe nf_conntrack_ipv4
lsmod | grep ip_vs
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
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/*
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
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
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/
##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
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
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
重新执行上述命令
keadm gettoken
以下操作在边缘端机器进行
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
./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
重新执行上述命令