在本文中,你将学会如何使用国内镜像搭建并启动一个kubernetes集群,并安装一个metrics-server用来收集集群中的资源使用情况,根据资源使用情况自动扩缩容。

一、系统需求
  • Centos8.2
  • 禁用Swap
  • 禁用SELinux
二、30秒安装
1、所有节点执行如下命令
wget https://raw.githubusercontent.com/cocofhu/k8s-setup/main/1.18.2.sh && bash 1.18.2.sh
2、master节点执行如下命令
# 使用阿里云镜像启动k8s
kubeadm init --kubernetes-version=1.18.2 \
--ignore-preflight-errors=all \
--image-repository registry.aliyuncs.com/google_containers 
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 https://docs.projectcalico.org/manifests/calico.yaml
3、work节点加入集群

执行如下命令生成加入命令,在所有work节点上执行

kubeadm token create --print-join-command
三、安装细节
# 清理旧版本的docker容器
yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine
# 安装yum-utils
yum install -y yum-utils
# 设置阿里云镜像
yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装docker
yum install docker-ce docker-ce-cli containerd.io -y
# 启动docker
systemctl start docker

# 使用本地软件包管理软件安装 kubectl 二进制文件
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 install -y kubelet-1.18.2 kubeadm-1.18.2 kubectl-1.18.2
# 设置开机启动
systemctl enable kubelet && systemctl start kubelet
# # 加载网桥过滤模块
modprobe br_netfilter

# 使桥接流量对iptables可见
cat <<EOF >  /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system

# 设置IP forward
echo "1" >/proc/sys/net/ipv4/ip_forward

# 关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

# 安装IPvs
yum install ipvsadm -y
yum install ipset -y
四、启用IPVS

ipvs模式和iptables类似,kube-proxy监控Pod的变化并创建相应的ipvs规则。ipvs相对iptables转发效率更高。除此以外,ipvs支持更多的LB算法。

1、安装并开启IPVS
yum install ipvsadm ipset -y
yum install ipset -y
# 将mode修改为ipvs
kubectl edit cm kube-proxy -n kube-system
# 重启这些pod
kubectl delete pod -l k8s-app=kube-proxy -n kube-system
2、一些说明
# 10.97.97.97:80 是service提供的访问入口
# 当访问这个入口的时候,可以发现后面有三个pod的服务在等待调用,
# kube-proxy会基于rr(轮询)的策略,将请求分发到其中一个pod上去
# 这个规则会同时在集群内的所有节点上都生成,所以在任何一个节点上访问都可以。
[root@master ~]# ipvsadm -Ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.97.97.97:80 rr
  -> 10.244.1.39:80               Masq    1      0          0
  -> 10.244.1.40:80               Masq    1      0          0
  -> 10.244.2.33:80               Masq    1      0          0
五、安装metrics-server

metrics-server可以用来收集集群中的资源使用情况,根据资源使用情况自动扩缩容

kubectl create -f https://raw.githubusercontent.com/cocofhu/k8s-setup/main/metrics-server.yaml
分类: 计算机科学软件

4 条评论

Make Money · 2022年3月4日 上午3:06

See how you can earn $27 in 7 minutes! Read here – https://bit.ly/32NSumo

카지노사이트추천 · 2022年3月25日 下午3:40

Hello There. I found your blog using msn. This is an extremely well written article.I’ll be sure to bookmark it and come back to read more of your useful info.Thanks for the post. I will definitely return.
That is a great tip especially to those fresh to the blogosphere. Simple but very precise information… Appreciate your sharing this one. A must read article!
If you want to increase your knowledge only keep visiting this website and be updated with the hottest information posted here.

카지노사이트 · 2022年3月29日 上午11:45

I was recommended this blog by way of my cousin. I’m not certain whether this post is written by means of him as nobody else recognise such exact approximately my difficulty. You’re incredible! Thanks!

נערות ליווי במרכז · 2022年4月20日 下午8:58

Next time I read a blog, Hopefully it does not disappoint me as much as this one. After all, Yes, it was my choice to read through, nonetheless I truly thought youd have something helpful to talk about. All I hear is a bunch of crying about something that you can fix if you were not too busy seeking attention.

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注