k8s安装

K8s 安装教程 v1.24

第一步前置环境调试
第一步确定自己的内核版本高于3
uname -sr

第二步:使用elrepo源升级内核检查发现当前内核版本是3.10,
使用elrepo源升级内核
配置elrepo源,执行如下命令
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
yum install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm -y

查看最新版内核
执行如下命令查看最新的内核版本
yum --disablerepo=“*” --enablerepo=“elrepo-kernel” list available

安装最新的内核版本
执行如下命令安装主线版本:
yum --enablerepo=elrepo-kernel install kernel-ml -y

设置系统默认内核
查看系统上的所有内核版本:
grub2-mkconfig -o /boot/grub2/grub.cfg
awk -F’ ‘$1=="menuentry " {print i++ " : " $2}’ /etc/grub2.cfg

设置默认内核为我们刚才升级的内核版本
cp /etc/default/grub /etc/default/grub-bak #备份
grub2-set-default 0 #设置默认内核版本
vi /etc/default/grub
GRUB_DEFAULT=saved修改为GRUB_DEFAULT=0

重新创建内核配置
grub2-mkconfig -o /boot/grub2/grub.cfg

查看默认内核
grubby --default-kernel
grub2-editenv list

更新软件包并重启
yum makecache
reboot

第二步 安装containerd
1.安装依赖

yum install -y yum-utils device-mapper-persistent-data lvm2

2.添加yum源

yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

3.安装containerd

yum install containerd -y

4.生成配置文件

containerd config default > /etc/containerd/config.toml

5.替换 containerd 默认的 sand_box 镜像,编辑 /etc/containerd/config.toml

sandbox_image = “registry.aliyuncs.com/google_containers/pause:3.2”

6.启动服务

systemctl restart containerd && systemctl enable containerd

第三步安装K8S
后面总结部分有快捷安装方式
修改主机名
hostnamectl set-hostname master
#注意每个节点的名字要不一样

总结 :快捷前置环境配置
#!/bin/bash

关闭防火墙

systemctl stop firewalld &&
systemctl disable firewalld && \

关闭 selinux

永久关闭(重启生效)

sed -i ‘s/enforcing/disabled/’ /etc/selinux/config && \

临时关闭(即刻生效)

setenforce 0 && \

关闭swap(k8s禁止虚拟内存以提高性能)

永久关闭(重启生效)

sed -ri ‘s/.swap./#&/’ /etc/fstab && \

临时关闭(即刻生效)

swapoff -a && \

在master添加hosts

cat >> /etc/hosts << EOF
192.168.65.180 k8s-master
192.168.65.38 k8s-node1
192.168.65.195 k8s-node2
EOF

cat <<EOF | sudo tee /etc/modules-load.d/k8s.conf
overlay
br_netfilter
EOF

modprobe overlay
modprobe br_netfilter

设置所需的 sysctl 参数,参数在重新启动后保持不变

cat <<EOF | sudo tee /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF

网桥生效

sysctl --system && \

时间同步

yum install ntpdate -y &&
ntpdate time.windows.com

上述是所有节点需要做的内容
下面是主节点的内容:
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

安装k8s
yum install kubelet-1.24.3 kubeadm-1.24.3 kubectl-1.24.3 -y

启动k8s

systemctl enable kubelet.service

初始化主节点
kubeadm init --apiserver-advertise-address=192.168.65.180 --kubernetes-version v1.24.3 --service-cidr=10.96.0.0/12 --pod-network-cidr=10.244.0.0/16 --image-repository registry.cn-hangzhou.aliyuncs.com/google_containers

kubeadm init成功后出现下面内容
Your Kubernetes control-plane has initialized successfully!

To start using your cluster, you need to run the following as a regular user:

mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown ( i d − u ) : (id -u): (idu):(id -g) $HOME/.kube/config

Alternatively, if you are the root user, you can run:

export KUBECONFIG=/etc/kubernetes/admin.conf

You should now deploy a pod network to the cluster.
Run “kubectl apply -f [podnetwork].yaml” with one of the options listed at:
https://kubernetes.io/docs/concepts/cluster-administration/addons/

Then you can join any number of worker nodes by running the following on each as root:

kubeadm join 192.168.65.180:6443 --token 98wkpb.mz5qekplhqfbgfo3
–discovery-token-ca-cert-hash sha256:aa426a445ac902c74cf124520571168eb406b19c08ddfdc1bf90fe66918d3fdd

初始化网络
curl -O https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml && kubectl apply -f kube-flannel.yml

sed -i ‘s/quay.io/quay-mirror.qiniu.com/g’ kube-flannel.yml

查看pod情况
kubectl get pod -A
#查看节点情况
kubectl get nodes

常见问题
The kubelet is unhealthy due to a misconfiguration of the node in some way (required cgroups disabled)
在 CentOS 7 上,默认情况下 cgroups 是启用的,但如果进行了某些配置更改,可能会导致其被禁用。
您可以通过编辑 kubelet 的配置文件 /etc/kubernetes/kubelet 来检查 cgroups 的配置:
vi /etc/kubernetes/kubelet
#修改为合适的 cgroup 驱动程序
KUBELET_EXTRA_ARGS=–cgroup-driver=systemd

保存文件后,重新启动 kubelet 服务:
systemctl restart kubelet

  • 19
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值