在线虚拟机安装-云原生边缘计算KubeEdge安装配置(使用负载均衡器LoadBalancer)

1.准备一个K8S集群。

说明:192.168.186.128 192.168.186.129 是K8S集群,192.168.186.130是边缘端。

#主机名:
hostnamectl set-hostname k8s-ke-cloud  && bash
hostnamectl set-hostname k8s-ke-edge1  && bash
hostnamectl set-hostname ke-edge1  && bash
#关闭防火墙:
systemctl stop firewalld
systemctl disable firewalld
#关闭selinux:
sed -i 's/enforcing/disabled/' /etc/selinux/config # 永久
setenforce 0 # 临时
#关闭swap:
swapoff -a # 临时
sed -i 's/.*swap.*/#&/' /etc/fstab # 永久
#添加hosts:
cat >> /etc/hosts << EOF
192.168.186.128  k8s-ke-cloud
192.168.186.129  k8s-ke-edge1
192.168.186.130  ke-edge1
EOF
#设置yum源
yum -y install wget
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
#时间同步
yum install -y chrony -y 
cat > /etc/chrony.conf << EOF
server ntp.aliyun.com iburst
stratumweight 0
driftfile /var/lib/chrony/drift
rtcsync
makestep 10 3
bindcmdaddress 127.0.0.1
bindcmdaddress ::1
keyfile /etc/chrony.keys
commandkey 1
generatecommandkey
logchange 0.5
logdir /var/log/chrony
EOF

systemctl enable --now chronyd 
chronyc sources 
#配置内核参数
cat > /etc/modprobe.d/k8s.conf <<EOF
#!/bin/bash
#modprobe -- br_netfilter
modprobe -- ip_vs
modprobe -- ip_vs_rr
modprobe -- ip_vs_wrr
modprobe -- ip_vs_sh
modprobe -- nf_conntrack_ipv4
EOF

chmod 755 /etc/modprobe.d/k8s.conf
bash /etc/modprobe.d/k8s.conf
lsmod | grep -E "ip_vs|nf_conntrack_ipv4"
#加载ip_vs内核模块
cat > /etc/sysctl.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1
net.ipv4.ip_forward=1
net.ipv4.ip_forward_use_pmtu = 0
EOF

sysctl --system
sysctl -a|grep "ip_forward"
#安装Docker
yum -y install epel-release wget
wget https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo
yum -y install docker-ce-20.10.0-3.el7  #指定版本
#yum -y install docker-ce  #安装docker最新版
systemctl enable docker && systemctl start docker && systemctl status docker

#设置仓库地址
cat > /etc/docker/daemon.json << EOF
{
"registry-mirrors":["https://rsbud4vc.mirror.aliyuncs.com","https://registry.docker-cn.com","https://docker.mirrors.ustc.edu.cn","https://dockerhub.azk8s.cn","http://hub-mirror.c.163.com","http://qtid6917.mirror.aliyuncs.com", "https://rncxm540.mirror.aliyuncs.com"],
  "exec-opts": ["native.cgroupdriver=systemd"]
} 
EOF

systemctl restart docker &&  systemctl status docker
docker --version
#添加yum 源
cat > /etc/yum.repos.d/kubernetes.repo << EOF
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
#安装kubeadm,kubelet 和kubectl
yum clean all && yum makecache -y
#yum list kubectl --showduplicates | sort -r #列出kubectl可用的版本

yum install -y kubelet-1.22.17-0 kubeadm-1.22.17-0 kubectl-1.22.17-0
systemctl enable kubelet
kubeadm init --apiserver-advertise-address=192.168.186.128  --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.22.17 --service-cidr=10.96.0.0/12  --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
kubectl apply -f  calico.yaml  #这个文件单独发你了
部署metrics-server
wget https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml
kubectl apply -f components.yaml
kubectl get pods -n kube-system
# 在kubernetes群集中创建Nginx
kubectl create deployment nginx --image=nginx 
kubectl expose deployment nginx --port=80 --type=NodePort
kubectl scale deployment  nginx --replicas=2  #pod副本的数量增加到10个
kubectl get pod,svc -o wide
#测试正常后请删除
kubectl delete deployment,svc nginx
kubectl get pod,svc,deployment

浏览器打开:集群任意IP:端口 浏览器能打开

到这里说明集群安装成功了

你可能感兴趣的:(kubernetes,docker容器相关,云原生,边缘计算,负载均衡)