KubeEdge云端部署
一.集群环境
主机名 | 角色 | 工作负载 |
---|---|---|
cloud | 云端 | K8s,docker,cloudcore |
edge | 边缘端 | docker,edgecore |
二.系统配置
2.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
# GitHub End
EOF
2.2关闭防火墙并禁用开机启动
systemctl stop firewalld & systemctl disable firewalld
2.3永久禁用SELinux
sed -i ‘s/SELINUX=permissive/SELINUX=disabled/‘ /etc/sysconfig/selinux
2.4关闭swap分区
sed -ri ‘s/.*swap.*/#&/‘ /etc/fstab
2.5创建必要目录
mkdir /usr/lib/go
mkdir /opt/idcus
mkdir /opt/idcus/go
mkdir /opt/idcus/go/src
mkdir /opt/idcus/go/bin
mkdir /opt/idcus/go/pkg
三、安装docker
3.1添加阿里云docker仓库
yum -y install yum-utils
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache
3.2安装docker
yum install docker-ce -y
3.3启动Docker服务并激活开机启动
systemctl start docker & systemctl enable docker
3.4测试docker
docker run hello-world
四、安装k8s
4.1配置主机名并重启
hostnamectl set-hostname cloud
reboot
4.2配置k8s的yum源
cat <<EOF > /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
EOF
4.3安装k8s组件
yum makecache
yum install -y kubelet kubeadm kubectl
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
4.4修改docker的cgroup driver
vi /usr/lib/systemd/system/docker.service
修改为下面所示代码:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --exec-opt native.cgroupdriver=systemd
重启docker
systemctl daemon-reload
systemctl restart docker
查看docker cgroup 驱动
docker info | grep -i cgroup
4.5修改kubectl的cgroup驱动
vi /usr/lib/systemd/system/kubelet.service.d/10-kubeadm.conf
Environment="KUBELET_KUBECONFIG_ARGS=--bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf --kubeconfig=/etc/kubernetes/kubelet.conf --cgroup-driver=systemd"
重启kubelet
systemctl daemon-reload
systemctl restart kubelet
五、拉取镜像
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
六、初始化集群
kubeadm init --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr=10.244.0.0/16
七、进一步配置
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
八、安装网络插件
mkdir -p /etc/cni/net.d
cat >/etc/cni/net.d/10-mynet.conf <<-EOF
{
"cniVersion": "0.3.0",
"name": "mynet",
"type": "bridge",
"bridge": "cni0",
"isGateway": true,
"ipMasq": true,
"ipam": {
"type": "host-local",
"subnet": "10.244.0.0/16",
"routes": [
{"dst": "0.0.0.0/0"}
]
}
}
EOF
cat >/etc/cni/net.d/99-loopback.conf <<-EOF
{
"cniVersion": "0.3.0",
"type": "loopback"
}
EOF
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
九、安装golang
yum install wget -y
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/idcus/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
十一、创建cloud节点
keadm init --advertise-address="ip地址" --kubeedge-version=版本号
keadm gettoken