k8s配置

一、前期准备

1、修改主机的/etc/hosts文件挟持域名

root@k8s-master \~\]# vim /etc/hosts 192.168.8.199 k8s-master 192.168.8.200 k8s-node1 192.168.8.201 k8s-node2

2、配置yum源

root@k8s-master \~\]# cd /etc/yum.repos.d/ \[root@k8s-master yum.repos.d\]# vim 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/rpmpackage-key.gpg \[root@k8s-master yum.repos.d\]# vim 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 yum.repos.d\]# yum clean all \&\& yum makecache

3、安装必备软件

root@k8s-master yum.repos.d\]# yum install wget jq psmisc vim net-tools telnet yum-utils device-mapper-persistent-data lvm2 git -y

4、同步时间

root@k8s-master yum.repos.d\]# yum -y install ntpdate \[root@k8s-master yum.repos.d\]# ntpdate time2.aliyun.com \[root@k8s-master yum.repos.d\]# crontab -e */5 * * * * /usr/sbin/ntpdate time2.aliyun.com \[root@k8s-master yum.repos.d\]# which ntpdate /usr/sbin/ntpdate

5、配置limit

root@k8s-master yum.repos.d\]# ulimit -SHn 65535 \[root@k8s-master yum.repos.d\]# vim /etc/security/limits.conf * soft nofile 65536 * hard nofile 131072 * soft nproc 65535 * hard nproc 655350 * soft memlock unlimited * hard memlock unlimited

6、安装 k8s ⾼可⽤性 Git 仓库

root@k8s-master \~\]# git clone https://gitee.com/dukuan/k8s-ha-install.git ![](https://i-blog.csdnimg.cn/direct/8bac37b49b724d39b348422e4639c455.png) 重启虚拟机

二、配置内核模块

1、配置 ipvs 模块

root@k8s-master \~\]# yum install ipvsadm ipset sysstat conntrack libseccomp -y \[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 # 在系统启动时加载下列 IPVS 和相关功能所需的模块 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 Early Detection)算法模>块 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隧道功能的模块,使得数据可以在两个网络之间进行传 输

2、配置 k8s 内核

root@k8s-master \~\]# yum -y install kubernetes \[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 # 用于设置系统中最大的监>听队列的长度

三、基本组件安装

1、安装 Containerd

root@k8s-master \~\]# yum remove -y podman runc containerd \[root@k8s-master \~\]# yum -y install containerd.io \[root@k8s-master \~\]# yum remove -y docker \[root@k8s-master \~\]# yum -y install docker-ce docker-ce-cli

2、配置 Containerd 所需模块

root@k8s-master \~\]# cat \<\ overlay \> br_netfilter \> EOF \[root@k8s-master \~\]# modprobe -- overlay \[root@k8s-master \~\]# modprobe -- br_netfilter

3、配置 Containerd 所需内核

root@k8s-master \~\]# vim /etc/sysctld./99-kubernetes-cri.conf 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 \[root@k8s-master \~\]# vim /etc/containerd/config.toml #128 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

5、配置 crictl 客户端连接的运⾏位置

root@k8s-master \~\]# vim /etc/crictl.yaml runtime-endpoint: unix:///run/containerd/containerd.sock image-endpoint: unix:///run/containerd/containerd.sock timeout: 10 debug: false

6、安装 Kubernetes 组件

root@k8s-master \~\]# yum install kubeadm-1.28\* kubelet-1.28\* kubectl-1.28\* -y \[root@k8s-master \~\]# yum -y remove kubernetes-client-1.5.2-0.7.git269f928.el7.x86_64 \[root@k8s-master \~\]# yum -y install kubectl-1.28.2-0.x86_64 \[root@k8s-master \~\]# yum -y install kubelet-1.28.2-0.x86_64 \[root@k8s-master \~\]# yum -y install kubeadm-1.28.2-0.x86_64 \[root@k8s-master \~\]# systemctl daemon-reload \[root@k8s-master \~\]# systemctl enable --now kubelet

1.Kubeadm 配置⽂件

root@k8s-master \~\]# vim kubeadm-config.yaml apiVersion: kubeadm.k8s.io/v1beta3 # 指定Kubernetes>配置文件的版本,使用的是kubeadm API的v1beta3版本 bootstrapTokens: # 定义bootstrap tokens的信息。这>些tokens用于在Kubernetes集群初始化过程中进行身份验证 - groups: # 定义了与此token关联的组 - system:bootstrappers:kubeadm:default-node-token token: 7t2weq.bjbawausm0jaxury # bootstrap token的值 ttl: 24h0m0s # token的生存时间,这里设置为24小时 usages: # 定义token的用途 - signing # 数字签名 - authentication # 身份验证 kind: InitConfiguration # 指定配置对象的类型,InitConfiguration:表示这是一个初始化配置 localAPIEndpoint: # 定义本地API端点的地址和端口 advertiseAddress: 192.168.8.199 bindPort: 6443 nodeRegistration: # 定义节点注册时的配置 criSocket: unix:///var/run/containerd/containerd.sock # 容器运行时(CRI)的套接字路径 name: k8s-master # 节点的名称 taints: # 标记 - effect: NoSchedule # 免调度节点 key: node-role.kubernetes.io/control-plane # 该节点>为控制节点 --- apiServer: # 定义了API服务器的配置 certSANs: # 为API服务器指定了附加的证书主体名称(SAN),指定IP即可 - 192.168.8.199 timeoutForControlPlane: 4m0s # 控制平面的超时时间,这>里设置为4分钟 apiVersion: kubeadm.k8s.io/v1beta3 # 指定API Server>版本 certificatesDir: /etc/kubernetes/pki # 指定了证书的存储目录 clusterName: kubernetes # 定义了集群的名称为"kubernetes" controlPlaneEndpoint: 192.168.8.199:6443 # 定义了>控制节点的地址和端口 controllerManager: {} # 控制器管理器的配置,为空表示使>用默认配置 etcd: # 定义了etcd的配置 local: # 本地etcd实例 dataDir: /var/lib/etcd # 数据目录 imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers # 指定了Kubernetes使用的镜像仓库的地址,阿里云的镜 像仓库。 kind: ClusterConfiguration # 指定了配置对象的类型,ClusterConfiguration:表示这是一个集群配置 kubernetesVersion: v1.28.2 # 指定了kubernetes的版本 networking: # 定义了kubernetes集群网络设置 dnsDomain: cluster.local # 定义了集群的DNS域为:cluster.local podSubnet: 172.16.0.0/16 # 定义了Pod的子网 serviceSubnet: 10.96.0.0/16 # 定义了服务的子网 scheduler: {} # 使用默认的调度器行为 \[root@k8s-master \~\]# kubeadm config migrate --old-config kubeadm-config.yaml --new-config new.yaml

2.下载组件镜像

root@k8s-master \~\]# kubeadm config images pull --config /root/new.yaml

3.集群初始化

root@k8s-master \~\]# kubeadm init --config /root/new.yaml --upload-certs

相关推荐
东风微鸣31 分钟前
关于全球化大规模混合云 Kubernetes Prometheus 监控体系标准化及 GitOps 自动化改进方案
kubernetes·自动化·prometheus
xxxx12344535 分钟前
Linux驱动开发-网络设备驱动
linux·运维·驱动开发
一条闲鱼_mytube38 分钟前
[k8s]随笔-typemeta metadata
云原生·容器·kubernetes
洛阳泰山1 小时前
Windows 11 家庭中文版 安装docker desktop 无法开启自启动问题处理
windows·docker·容器
ak啊1 小时前
Nginx 调试与排查指南
nginx
小小不董1 小时前
Oracle OCP认证考试考点详解083系列03
运维·服务器·数据库·oracle·dba
刘若水1 小时前
Linux: 线程控制
linux·运维·服务器
网硕互联的小客服2 小时前
香港服务器租用对分布式计算的作用
运维·服务器
迷茫运维路2 小时前
K8S+Prometheus+Consul+alertWebhook实现全链路服务自动发现与监控、告警配置实战
运维·kubernetes·go·prometheus·consul