k8s环境部署1

[root@k8s-master ~]# vim /etc/hosts
192.168.1.11 k8s-master
192.168.1.22 k8s-node1
192.168.1.33 k8s-node2
[root@k8s-master ~]# vim /etc/yum.repos.d/docker-ce.repo
[docker-ce-stable]
name=Docker CE Stable - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-debuginfo]
name=Docker CE Stable - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-stable-source]
name=Docker CE Stable - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/stable
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test]
name=Docker CE Test - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-debuginfo]
name=Docker CE Test - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-test-source]
name=Docker CE Test - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/test
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly]
name=Docker CE Nightly - $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-debuginfo]
name=Docker CE Nightly - Debuginfo $basearch
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/debug-$basearch/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg

[docker-ce-nightly-source]
name=Docker CE Nightly - Sources
baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/source/nightly
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
[root@k8s-master ~]# vim /etc/yum.repos.d/kubernetes.repo
[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
[root@k8s-master ~]# yum clean all
[root@k8s-master ~]# yum makecache
[root@k8s-master ~]# yum -y install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git
[root@k8s-master ~]# yum -y install ntpdate
[root@k8s-master ~]# ntpdate time2.aliyun.com
[root@k8s-master ~]# crontab -e
* 5 * * * /usr/sbin/ntpdate time2.aliyun.com
[root@k8s-master ~]# ulimit -SHn 65535 //单个进程可以打开的⽂件数量将被限制为65535
[root@k8s-master ~]# vim /etc/security/limits.conf 
//末尾添加如下内容
* soft nofile 65536
* hard nofile 131072
* soft nproc 65535
* hard nproc 655350
* soft memlock unlimited
* hard memlock unlimited
[root@k8s-master ~]# git clone https://gitee.com/dukuan/k8s-ha-install.git //在/root/⽬录下克隆⼀个名为 k8s-ha-install.git 的Git 仓库
[root@k8s-master ~]# reboot
配置内核模块
 配置 ipvs 模块
[root@k8s-master ~]#  yum -y install ipvsadm ipset sysstat conntrack libseccomp
[root@k8s-master ~]# modprobe -- ip_vs
[root@k8s-master ~]# modprobe -- ip_vs_rr
[root@k8s-master ~]# modprobe -- ip_vs_wrr
[root@k8s-master ~]# modprobe -- ip_vs_sh
[root@k8s-master ~]# modprobe -- nf_conntrack
[root@k8s-master ~]# vim /etc/modules-load.d/ipvs.conf
ip_vs         # 负载均衡模块
ip_vs_lc      # ⽤于实现基于连接数量的负载均衡算法
ip_vs_wlc     # ⽤于实现带权重的最少连接算法的模块
ip_vs_rr      # 负载均衡rr算法模块
ip_vs_wrr     # 负载均衡wrr算法模块       
ip_vs_lblc    # 负载均衡算法,它结合了最少连接(LC)算法和基于偏置的轮询(Round Robin with Bias)算法
ip_vs_lblcr   # ⽤于实现基于链路层拥塞状况的最少连接负载调度算法的模块
ip_vs_dh      # ⽤于实现基于散列(Hashing)的负载均衡算法的模块
ip_vs_sh      # ⽤于源端负载均衡的模块
ip_vs_fo      # ⽤于实现基于本地服务的负载均衡算法的模块
ip_vs_nq      # ⽤于实现NQ算法的模块
ip_vs_sed     # ⽤于实现随机早期检测(Random EarlyDetection)算法的模块
ip_vs_ftp     # ⽤于实现FTP服务的负载均衡模块
ip_vs_sh
nf_conntrack  # ⽤于跟踪⽹络连接的状态的模块
ip_tables     # ⽤于管理防护墙的机制
ip_set        # ⽤于创建和管理IP集合的模块
xt_set        # ⽤于处理IP数据包集合的模块,提供了与iptables等⽹络⼯具的接⼝
ipt_set       # ⽤于处理iptables规则集合的模块
ipt_rpfilter  # ⽤于实现路由反向路径过滤的模块
ipt_REJECT    # iptables模块之⼀,⽤于将不符合规则的数据包拒绝,并返回特定的错误码
ipip          # ⽤于实现IP隧道功能的模块,使得数据可以在两个⽹络之间进⾏传输
[root@k8s-master ~]# systemctl enable systemd-modules-load.service
[root@k8s-master ~]# systemctl start systemd-modules-load.service
[root@k8s-master ~]# vim /etc/sysctl.d/k8s.conf 
# 写入k8s所需内核模块
net.bridge.bridge-nf-call-iptables = 1          # 控制网络桥接与iptables之间的网络转发行为
net.bridge.bridge-nf-call-ip6tables = 1         # 用于控制网络桥接(bridge)的IP6tables过滤规则。当该参数设置为1时,表示启用对网络桥接
的IP6tables过滤规则
fs.may_detach_mounts = 1                # 用于控制文件系统是否允许分离挂载,1表示允许
net.ipv4.conf.all.route_localnet = 1            # 允许本地网络上的路由。设置为1表示允许,设置为0表示禁止。
vm.overcommit_memory=1          # 控制内存分配策略。设置为1表示允许内存过量分配,设置为0表示不允许。
vm.panic_on_oom=0               # 决定当系统遇到内存不足(OOM)时是否产生panic。设置为0表示不产生panic,设置为1表示产生panic。
fs.inotify.max_user_watches=89100               # inotify可以监视的文件和目录的最大数量。
fs.file-max=52706963            # 系统级别的文件描述符的最大数量。
fs.nr_open=52706963                     # 单个进程可以打开的文件描述符的最大数量。
net.netfilter.nf_conntrack_max=2310720          # 网络连接跟踪表的最大大小。
net.ipv4.tcp_keepalive_time = 600               # TCP保活机制发送探测包的间隔时间(秒)。
net.ipv4.tcp_keepalive_probes = 3               # TCP保活机制发送探测包的最大次数。
net.ipv4.tcp_keepalive_intvl =15                # TCP保活机制在发送下一个探测包之前等待响应的时间(秒)。
net.ipv4.tcp_max_tw_buckets = 36000     # TCP TIME_WAIT状态的bucket数量。
net.ipv4.tcp_tw_reuse = 1               # 允许重用TIME_WAIT套接字。设置为1表示允许,设置为0表示不允许。
net.ipv4.tcp_max_orphans = 327680               # 系统中最大的孤套接字数量。
net.ipv4.tcp_orphan_retries = 3                 # 系统尝试重新分配孤套接字的次数。
net.ipv4.tcp_syncookies = 1             # 用于防止SYN洪水攻击。设置为1表示启用SYN cookies,设置为0表示禁用。
net.ipv4.tcp_max_syn_backlog = 16384            # SYN连接请求队列的最大长度。
net.ipv4.ip_conntrack_max = 65536               # IP连接跟踪表的最大大小。
net.ipv4.tcp_max_syn_backlog = 16384            # 系统中最大的监听队列的长度。
net.ipv4.tcp_timestamps = 0             # 用于关闭TCP时间戳选项。
net.core.somaxconn = 16384              # 用于设置系统中最大的监听队列的长度
[root@k8s-master ~]# reboot
[root@k8s-master ~]# yum remove -y podman runc containerd //卸载之前的containerd
[root@k8s-master ~]# yum -y install  docker-ce docker-ce-cli containerd.io
配置 Containerd 所需模块
[root@k8s-master ~]# cat  <<EOF | sudo tee /etc/modules-load.d/containerd.conf
> overlay
> br_netfilter
> EOF
overlay
br_netfilter
[root@k8s-master ~]# modprobe -- overlay
[root@k8s-master ~]#  modprobe -- br_netfilter
配置 Containerd 所需内核
[root@k8s-master ~]# cat <<EOF | sudo tee /etc/sysctl.d/99-kubernetes-cri.conf
> net.bridge.bridge-nf-call-iptables = 1
> net.ipv4.ip_forward = 1
> net.bridge.bridge-nf-call-ip6tables = 1
> EOF
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
[root@k8s-master ~]# sysctl --system
[root@k8s-master ~]# mkdir -p /etc/containerd
[root@k8s-master ~]# containerd config default | tee /etc/containerd/config.toml //读取containerd的配置并保存到/etc/containerd/config.toml
[root@k8s-master ~]# vim /etc/containerd/config.toml 
63     sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9"
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
            BinaryName = ""
            CriuImagePath = ""
            CriuPath = ""
            CriuWorkPath = ""
            IoGid = 0
            IoUid = 0
            NoNewKeyring = false
            NoPivotRoot = false
            Root = ""
            ShimCgroup = ""
            SystemdCgroup = true
            sandbox_image = "registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.9"
[root@k8s-master ~]# systemctl daemon-reload
[root@k8s-master ~]# systemctl enable --now containerd
配置 crictl 客户端连接的运⾏位置
[root@k8s-master ~]# cat > /etc/crictl.yaml <<EOF
> runtime-endpoint:unix:///run/containerd/containerd.sock
> image-endpoint:unix:///run/containerd/containerd.sock
> timeout: 10
> debug: false
> EOF
安装 Kubernetes 组件
[root@k8s-master ~]# yum list kubeadm.x86_64 --showduplicates | sort -r //查询最新的Kubernetes版本号
[root@k8s-master ~]# yum -y install kubeadm-1.28* kubelet-1.28* kubectl-1.28* 
[root@k8s-master ~]# systemctl daemon-reload
[root@k8s-master ~]# systemctl enable --now kubelet
[root@k8s-master ~]# kubeadm version //查看当前安装的kubeadm版本号
Kubernetes 集群初始化
[root@k8s-master ~]# vim kubeadm-config.yaml
apiVersion: kubeadm.k8s.io/v1beta3  
bootstrapTokens:  
- groups: # 定义了与此token关联的组  
  - system:bootstrappers:kubeadm:default-node-token  
  token: 7t2weq.bjbawausm0jaxury  
  ttl: 24h0m0s  
  usages:  
  - signing # 数字签名  
  - authentication # 身份验证  
kind: InitConfiguration # 指定配置对象的类型  
localAPIEndpoint: # 定义本地API端点的地址和端口  
  advertiseAddress: 192.168.1.11  
  bindPort: 6443  
nodeRegistration: # 定义节点注册时的配置  
  criSocket: unix:///var/run/containerd/containerd.sock  
  name: k8s-master # 节点的名称  
  taints: # 标记  
  - effect: NoSchedule # 免调度节点  
    key: node-role.kubernetes.io/control-plane # 该节点为控制节点  
---  
apiServer: # 定义了API服务器的配置  
  certSANs: # 为API服务器指定了附加的证书主体名称(SAN),指定IP即可  
  - 192.168.1.11  
  timeoutForControlPlane: 4m0s # 控制平面的超时时间  
apiVersion: kubeadm.k8s.io/v1beta3 # 指定APIServer版本  
certificatesDir: /etc/kubernetes/pki   
clusterName: kubernetes # 定义了集群的名称为"kubernetes"  
controlPlaneEndpoint: 192.168.1.11:6443   
controllerManager: {} # 控制器管理器的配置  
etcd: # 定义了etcd的配置  
  local: # 本地etcd实例  
    dataDir: /var/lib/etcd  
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers  
kind: ClusterConfiguration # 指定了配置对象的类型  
kubernetesVersion: v1.28.2 # 指定了kubernetes的版本  
networking:  
  dnsDomain: cluster.local # 定义了集群的DNS域为:cluster.local  
  podSubnet: 172.16.0.0/16  
  serviceSubnet: 10.96.0.0/16  
scheduler: {}
[root@k8s-master ~]# kubeadm config migrate --old-config kubeadm-config.yaml --new-config new.yaml //将旧的kubeadm配置⽂件转换为新的格式
下载组件镜像
[root@k8s-master ~]#  kubeadm config images pull --config /root/new.yaml
集群初始化
禁用 Swap
[root@k8s-master ~]# swapoff -a
[root@k8s-master ~]# vim /etc/fstab
#/dev/mapper/centos-swap swap                    swap    defaults        0 0 //注释
root@k8s-master ~]# kubeadm init --config /root/new.yaml --upload-certs
[root@k8s-master ~]# kubeadm reset -f ; ipvsadm --clear ; rm -rf ~/.kube //重新初始化


rm -f /etc/kubernetes/manifests/kube-apiserver.yaml  
rm -f /etc/kubernetes/manifests/kube-controller-manager.yaml  
rm -f /etc/kubernetes/manifests/kube-scheduler.yaml  
rm -f /etc/kubernetes/manifests/etcd.yaml

mkdir -p /etc/kubernetes/manifests/backup  
mv /etc/kubernetes/manifests/*.yaml /etc/kubernetes/manifests/backup/

lsof -i :10250
[root@k8s-master ~]# vim /etc/docker/daemon.json
{
    "registry-mirrors": [
        "https://do.nark.eu.org",
        "https://dc.j8.work",
        "https://docker.m.daocloud.io",
        "https://dockerproxy.com",
        "https://docker.mirrors.ustc.edu.cn",
        "https://docker.nju.edu.cn"
    ],
        "hosts":[
                "tcp://0.0.0.0:2375",
                "unix:///var/run/docker.sock"
        ]
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值