Debian11之基于kubeadm安装K8S(v1.26.0) 集群
安装k8s - 阿里云镜像
docker 设置国内镜像源
1、Master主机:2核CPU、4G内存、20G硬盘
2、Node主机:4+核CPU、8G+内存、40G+硬盘
2、集群中的所有机器的网络彼此均能相互连接(公网和内网都可以)
3、节点之中不可以有重复的主机名、MAC 地址或 product_uuid
4、开启机器上的某些端口
5、为了保证 kubelet 正常工作,必须禁用交换分区
ONBOOT=yes
IPADDR=192.168.72.139
NETMASK=255.255.255.0
GATEWAY=192.168.72.2
DNS1=8.8.8.8
DNS2=114.114.114.114
systemctl restart netowrk
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
# 清除yum缓存
yum clean all
# 缓存阿里云镜像
yum makecache
hostnamectl set-hostname k8smaster && hostname # 设置主节点1的主机名称
hostnamectl set-hostname k8snode01 && hostname # 设置从节点1的主机名称
#根据自己设备ip配置
vi /etc/hosts # 编辑文件,注意不能有空格
192.168.111.30 k8smaster
192.168.111.33 k8snode01
systemctl disable firewalld && systemctl stop firewalld
查看selinux信息
sestatus
临时禁用
setenforce 0
永久禁用
1、打开/etc/sysconfig/selinux文件
2、将配置SELinux=enforcing改为SELinux=disabled
vi /etc/sysconfig/selinux
SELINUX=disabled
swapoff -a && sed -i 's/.*swap.*/#&/' /etc/fstab # 注释掉swap那一行
free -h 查看是分区空间
参考: K8S学习笔记之CentOS7集群使用Chrony实现时间同步
yum install chrony -y
修改配置文件
vim /etc/chrony.conf
修改时间服务器为阿里云服务器 ntp1.aliyun.com
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
server ntp1.aliyun.com iburst
启动服务
systemctl enable chronyd.service && systemctl start chronyd.service && systemctl status chronyd.service
每台节点查看时间是否一致
date
vim /etc/sysctl.d/k8s.conf
#写入如下两行的参数
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
#使配置生效命令
sysctl --system # 生效
参考: centos7安装Docker详细步骤(无坑版教程)
本次安装docker版本
配置docker参数
vim /etc/docker/daemon.json
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://rrnv06ig.mirror.aliyuncs.com","https://reg-mirror.qiniu.com","https://docker.mirrors.ustc.edu.cn"]
}
#重启docker
systemctl daemon-reload && systemctl start docker && systemctl enable docker
查看docker信息
docker info
参考:centos7 部署 k8s1.25.3 版本 (使用cri-dockerd方式安装)
[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
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet --now
kubeadm config images list --image-repository registry.aliyuncs.com/google_containers
kubeadm config images pull --kubernetes-version=v1.26.1 --image-repository registry.aliyuncs.com/google_containers --cri-socket unix:///var/run/cri-dockerd.sock
kubeadm init --apiserver-advertise-address=192.168.72.139 --kubernetes-version=v1.26.1 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --token-ttl=0 --cri-socket=unix:///var/run/cri-dockerd.sock --image-repository registry.aliyuncs.com/google_containers --upload-certs --ignore-preflight-errors=all
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubeadm join 192.168.72.139:6443 --token tbrqt5.e9xje0c0i1vv6b66 --discovery-token-ca-cert-hash sha256:f27da12089c64c1c5611ed5b6e008032e07988cc5fbbf190899314d098cfb0fb --cri-socket=unix:///var/run/cri-dockerd.sock
在master节点执行如下命令
kubectl get nodes
参考官网地址:https://docs.tigera.io/calico/3.25/getting-started/kubernetes/self-managed-onprem/onpremises
查看calico支持的kubernetes版本信息
https://docs.tigera.io/calico/3.25/getting-started/kubernetes/requirements
calico/node v3.25.0
calico/pod2daemon-flexvol v3.25.0
calico/cni v3.25.0
calico/kube-controllers v3.25.0
curl https://raw.githubusercontent.com/projectcalico/calico/v3.25.0/manifests/calico.yaml -O
kubectl apply -f calico.yaml
kubectl get nodes
kubectl get pods -A
步步踩坑啊-------------------------奖励自己不放弃,哈哈哈
1、在安装calico网络之前coredns一直处于pending状态,
例子:docker pull calico/cni:v3.25.0
docker打包镜像和容器
Rancher中导入新搭建的Kubernetes集群
通过kubelet下载镜像失败问题,更换docker镜像源解决
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": ["https://registry.docker-cn.com","http://hub-mirror.c.163.com","https://rrnv06ig.mirror.aliyuncs.com","https://reg-mirror.qiniu.com","https://docker.mirrors.ustc.edu.cn"]
}
创作不易:觉得内容不错的可以点个start,感谢支持!
gitee地址:https://gitee.com/full-stack-learn/fs/