云端部署环境准备
一、部署前工作(k8s、docker安装及配置、初始化集群、golang安装、keadm安装)
配置网络参数
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
#永久禁用SELinux
sed -i 's/SELINUX=permissive/SELINUX=disabled/' /etc/sysconfig/selinux
#关闭swap
sed -ri 's/.*swap.*/#&/' /etc/fstab
安装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
重启系统
reboot
配置k8s yum源
cat <<EOF > /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
##安装kubelet、kubeadm、kubectl
yum makecache
yum install -y kubelet-1.21.1 kubeadm-1.21.1 kubectl-1.21.1 ipvsadm
systemctl enable kubelet
配置内核参数
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
EOF
sysctl --system
modprobe br_netfilter
sysctl -p /etc/sysctl.d/k8s.conf
加载ipvs相关内核模块
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: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
如果初始化失败,请使用如下代码清除后重新初始化
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/*
进一步配置kubectl
mkdir -p $HOME/.kube
cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
chown $(id -u):$(id -g) $HOME/.kube/config
systemctl status kubelet
systemctl status kubelet
配置网络插件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
systemctl restart kubelet
kubectl get node
kubectl get pods -n kube-system
kubectl get svc
安装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/
##vi /etc/profile 结尾加
export HOME=/root
export GOROOT=/usr/local/go
export GOPATH=/opt/go
export PATH=$PATH:$GOPATH/bin:$GOROOT/bin
source /etc/profile
go version
安装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
二、部署kubeedge
准备工作
1.mkdir /etc/kubeedge
2.mv kubeedge-v1.8.0-linux-amd64.tar.gz /etc/kubeedge
3.mkdir /etc/kubeedge/crds/devices
下载devices_v1alpha2_devicemodel.yaml devices_v1alpha2_device.yaml 将其放入该文件夹下
4.mkdir /etc/kubeedge/crds/reliablesyncs
下载cluster_objectsync_v1alpha1.yaml objectsync_v1alpha1.yaml 将其放入该文件夹下
5.下载 cloudcore.service 放入 /etc/kubeedge
开始部署cloudcore
keadm init --advertise-address="ip地址" --kubeedge-version=1.8.0
标签:KubeEdge,etc,完美,部署,yum,kubeedge,docker,com,kubeadm
From: https://blog.51cto.com/u_13743985/8274052