Kubernetes on CentOS: Essential Installation Resources & Requirements
Installing Kubernetes (K8s) on CentOS requires careful preparation of system resources, configuration adjustments, and sequential execution of steps. Below are critical resources and recommendations to ensure a successful deployment.
1. System Requirements
Before starting, verify your CentOS system meets the minimum hardware and software specifications:
- Operating System: CentOS 7.x or 8.x (64-bit). Higher versions (e.g., CentOS Stream 8/9) may require additional compatibility checks.
- Hardware:
- CPU: At least 2 physical cores (4+ cores recommended for production workloads with pods).
- Memory: Minimum 2GB RAM (4GB+ recommended to avoid performance bottlenecks).
- Storage: At least 20GB available disk space (30GB+ recommended for storing container images, logs, and persistent volumes).
- Network: All nodes (Master/Worker) must be on the same network, with stable internet access to pull container images (e.g., from Docker Hub).
2. Pre-Installation Configuration
Preparation is key to avoiding conflicts during installation. Follow these critical steps:
- Disable SELinux: Kubernetes does not support SELinux in enforcing mode. Run the following commands to disable it permanently:
sudo setenforce 0 # Temporary disable sudo sed -i 's/^SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config # Permanent disable - Disable Swap: Kubernetes requires swap to be turned off to manage memory efficiently. Execute:
sudo swapoff -a # Temporary disable sudo sed -i '/swap/s//#/' /etc/fstab # Comment out swap entry in fstab (permanent disable) - Configure Kernel Parameters: Adjust sysctl settings to enable bridge networking (required for pod communication). Create/Edit
/etc/sysctl.d/k8s.confand add:
Load the changes withnet.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1sudo sysctl --system. - Set Hostnames & Update Hosts File: Assign unique hostnames to each node (e.g.,
master-node,worker-node1) usinghostnamectl set-hostname. Then, edit/etc/hostson all nodes to map IP addresses to hostnames (e.g.,192.168.1.10 master-node). - Synchronize Time: Use
ntpdateorchronyto sync system time across nodes. For example:sudo yum install -y ntpdate sudo ntpdate time.windows.com # Or use a local NTP server
These steps ensure system stability and compatibility with Kubernetes.
3. Installing Prerequisite Software
Kubernetes relies on Docker (or another compatible container runtime) and its own components (kubelet, kubeadm, kubectl). Follow these steps to install them:
- Install Docker:
- Add the Docker YUM repository:
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo - Install Docker Engine and containerd:
sudo yum install -y docker-ce docker-ce-cli containerd.io - Start and enable Docker:
sudo systemctl enable docker && sudo systemctl start docker
- Add the Docker YUM repository:
- Add Kubernetes YUM Repository: Create a file
/etc/yum.repos.d/kubernetes.repowith the following content:[kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg - Install Kubernetes Components: Install
kubelet,kubeadm, andkubectl:
Enable and startsudo yum install -y kubelet kubeadm kubectl --disableexcludes=kuberneteskubelet:sudo systemctl enable kubelet && sudo systemctl start kubelet
Docker is the most commonly used container runtime, but you can also use containerd or CRI-O if preferred.
4. Initializing the Kubernetes Cluster
The kubeadm tool simplifies cluster setup. Here’s how to initialize a Master node:
- Initialize Master: Run the following command (replace
with your Master node’s IP and adjust--pod-network-cidrif needed):
This command generates asudo kubeadm init --apiserver-advertise-address=--pod-network-cidr=10.244.0.0/16 kubeadm joincommand (save it—you’ll need it for Worker nodes) and sets up the Master node. - Configure kubectl: Set up the kubeconfig file for your user:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config - Install Network Plugin: A network plugin (e.g., Flannel, Calico) is required for pod communication. For Flannel:
For Calico (recommended for production):kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.ymlkubectl apply -f https://docs.projectcalico.org/manifests/tigera-operator.yaml kubectl apply -f https://docs.projectcalico.org/manifests/custom-resources.yaml
The Master node is now ready. Verify its status with kubectl get nodes (it should show “NotReady” until Worker nodes join).
5. Adding Worker Nodes
To scale your cluster, join Worker nodes using the kubeadm join command generated during Master initialization. On each Worker node:
sudo kubeadm join :6443 --token --discovery-token-ca-cert-hash <hash>
Replace and with values from the Master’s kubeadm init output. After joining, run kubectl get nodes on the Master to confirm the Worker node status (should change to “Ready”).
6. Post-Installation Verification
Check the health of your cluster with these commands:
- List Nodes:
kubectl get nodes - Check Pod Status:
kubectl get pods -A - Test Deployment: Deploy a sample application (e.g., Nginx) to verify functionality:
kubectl create deployment nginx --image=nginx kubectl expose deployment nginx --type=NodePort --port=80 kubectl get svc nginx
Access the Nginx service using the NodePort (e.g., http://).
By following these recommendations and steps, you can successfully install Kubernetes on CentOS. Always refer to the official Kubernetes documentation for the latest updates and troubleshooting tips.
以上就是关于“k8s centos安装资源推荐”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm