kubeedge安装与部署

演示主机与环境

  • master Ubuntu18.04(公网 123.249.112.195)
  • worknode01 centos7.9(公网 139.198.18.68)
  • docker 20.10.7
  • k8s 1.21.5
  • kubeedge 1.8.2

docker的安装

centos安装docker

# yum配置
yum install -y yum-utils
yum-config-manager \
--add-repo \
http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo 
yum install -y docker-ce-20.10.7 docker-ce-cli-20.10.7  containerd.io-1.4.6

ubuntu安装docker

apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce=5:20.10.7~3-0~ubuntu-bionic docker-ce-cli=5:20.10.7~3-0~ubuntu-bionic containerd.io docker-buildx-plugin docker-compose-plugin

docker的配置

systemctl enable docker --now
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://s7jg78tv.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

其他设置

#每台主机都需要设置
swapoff -a  
sed -ri 's/.*swap.*/#&/' /etc/fstab
sudo systemctl stop ufw
sudo systemctl disable ufw
cat <

k8s的安装

kubeadm引导安装
#安装golang并添加环境变量
sudo wget https://dl.google.com/go/go1.18.3.linux-amd64.tar.gz
sudo tar -zxvf go1.18.3.linux-amd64.tar.gz -C /usr/local/
sudo cp /usr/local/go/bin/go /usr/local/bin/go
#master端部署及初始化
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - 
cat </etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
#安装指定版本的三大件
apt-get install -y kubelet=1.21.5-00 kubeadm=1.21.5-00 kubectl=1.21.5-00
master初始化
systemctl enable --now kubelet
#查看有哪些参数需要指定
kubeadm init -h
# 一般指定以下参数即可
#默认镜像为Google无情况下会导致拉取失败,更换为阿里云的镜像
#指定网段以及kubernetes版本
kubeadm init \
--apiserver-advertise-address=192.168.0.85 \
--control-plane-endpoint=cluster-endpoint \
--image-repository=registry.aliyuncs.com/google_containers \
--kubernetes-version v1.21.5 \
--service-cidr=10.96.0.0/16 \
--pod-network-cidr=192.168.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
网络插件的安装(calico)
curl https://docs.projectcalico.org/archive/v3.21/manifests/calico.yaml -O
kubectl apply -f calico.yaml

二进制安装参照kubernets官方文档

kubeedge安装

云端环境
#需要四个文件
#checksum_kubeedge-v1.8.2-linux-amd64.tar.gz.txt
#keadm-v1.8.2-linux-amd64.tar.gz
#kubeedge-v1.8.2-linux-amd64.tar.gz
#v1.8.2.tar.gz
tar -zxvf keadm-v1.8.2-linux-amd64.tar.gz
cd /etc/kubeedge/
cp ~/ke/checksum_kubeedge-v1.8.2-linux-amd64.tar.gz.txt .
cd ~/ke
tar -zxvf v1.8.2.tar.gz
cd kubeedge-1.8.2/build/tools
cp cloudcore.service  edgecore.service /etc/kubeedge
cd ..
cp -r crds/ /etc/kubeedge
keadm init --kubeedge-version=1.8.2  --advertise-address=123.249.112.195
ps aux | grep 'cloudcore'
netstat -nplt

值得注意的是cloudcore有时候不会启动,当你发现你的edgecore处于(code=exited,status=255)时.查看10000和10002端口是否有cloudcore使用

#设置自动启动
sudo cp /etc/kubeedge/cloudcore.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl start cloudcore.service
sudo systemctl enable cloudcore.service
边缘端环境
vim /etc/hosts
123.249.112.195 master
scp root@master:/usr/local/bin/keadm /usr/local/bin/
scp -r root@master:/etc/kubeedge /etc/
#在master上 keadm gettoken获得令牌 有时间限制
keadm join --cloudcore-ipport=123.249.112.195:10000  --kubeedge-version=1.8.2 --token=d4143460867e37a127f4c252650cd024b376e0b5df5e683837914a8a6cdc228a.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2Nzc5NjUwOTN9.1WfulQG
systemctl status edgecore.service
#当你的edgecore有任何问题的时候,你都可以使用以下命令来打印日志
journalctl -u edgecore.service
# 你有可能会遇见驱动不一致的问题,一般在daemon.json里面修改"exec-opts": ["native.cgroupdriver=cgroupfs"]就能得到解决

查看node情况

kubectl get nodes -o wide

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