在CentOS系统上进行Kubernetes(K8S)部署测试,可以按照以下步骤进行:
环境准备
- 关闭防火墙:
sudo systemctl stop firewalld sudo systemctl disable firewalld
- 关闭SELinux:
sudo setenforce 0 sudo sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
- 禁用交换分区:
sudo swapoff -a sudo sed -i '/swap/d' /etc/fstab
- 配置主机名:
sudo hostnamectl set-hostname k8s-master
- 配置网络参数:
编辑
/etc/sysctl.d/k8s.conf
文件,添加以下内容:net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 vm.swappiness = 0
使更改生效:sudo sysctl --system
安装Docker
- 安装Docker所需的工具:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
- 配置Docker的YUM源:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 安装Docker:
sudo yum install -y docker-ce docker-ce-cli containerd.io sudo systemctl enable docker sudo systemctl start docker
安装Kubernetes组件
- 添加Kubernetes的YUM仓库:
cat <
- 安装kubelet、kubeadm和kubectl:
sudo yum install -y kubelet-1.22.15 kubeadm-1.22.15 kubectl-1.22.15 sudo systemctl enable kubelet sudo systemctl start kubelet
初始化Master节点
- 初始化Master节点:
sudo kubeadm init --apiserver-advertise-address 192.168.1.100 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.22.15 --service-cidr 10.96.0.0/12 --pod-network-cidr 10.244.0.0/16 --ignore-preflight-errors all
- 拷贝K8s认证文件:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
加入Worker节点
- 在Worker节点上执行kubeadm join命令:
sudo kubeadm join 192.168.1.100:6443 --token abcdef.0123456789abcdef --discovery-token-ca-cert-hash sha256:1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef
验证集群状态
- 在Master节点查询节点状态:
kubectl get nodes
通过以上步骤,你可以在CentOS系统上成功部署并测试一个Kubernetes集群。