在本文中,你将学会如何使用国内镜像搭建并启动一个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
分类: 计算机科学软件

12 条评论

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.

source · 2022年7月12日 下午12:29

I’m amazed, I must say. Rarely do I come across a blog that’s equally educative and
interesting, and let me tell you, you have hit the nail
on the head. The problem is something too few folks are speaking intelligently about.
Now i’m very happy that I stumbled across this in my search for something concerning this.

here · 2022年7月14日 上午9:25

I used to be able to find good information from your content.

como tomar el kamagra · 2022年7月19日 下午7:42

I’d like to find out more? I’d care to find out some
additional information.

https://viagrakob.quest/ · 2022年7月20日 上午7:45

It’s fantastic that yoou are getting thoughts from this piece of writing ass well as from our dialogue made at this time.

solaceinabook · 2022年7月28日 下午6:56

Great web site. Plenty of useful information here.

I am sending it to a few buddies ans additionally sharing
in delicious. And obviously, thank you for your sweat!

achetercialis2022.quest · 2022年7月29日 下午6:06

What a data of un-ambiguity and preserveness of precious know-how about unexpected emotions.

ecored · 2022年7月31日 下午11:16

Hey There. I found your blog the use of msn. This
is an extremely well written article. I’ll be sure to bookmark it and return to read extra of
your helpful information. Thanks for the post. I’ll definitely comeback.

נערות ליווי באתר ישראל לאדי · 2022年8月2日 上午9:18

Next time I read a blog, I hope that it wont disappoint me just as much as this particular one. After all, Yes, it was my choice to read through, nonetheless I actually believed you would have something helpful to talk about. All I hear is a bunch of moaning about something you could possibly fix if you werent too busy looking for attention.

发表评论

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