Kubernetes is a powerful open-source platform for automating deployment, scaling, and management of containerized applications. This guide will show you how to install Kubernetes on CentOS 7.
Disabling SELinux
Disable SELinux as it can interfere with Kubernetes:
sudo setenforce 0 sudo sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
Installing Docker
Kubernetes requires a container runtime; Docker is a popular choice:
sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo sudo yum install docker-ce docker-ce-cli containerd.io -y sudo systemctl start docker sudo systemctl enable docker
Configuring Kubernetes Repository
Add the Kubernetes repository:
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch 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 EOF
Installing Kubernetes Components
Install Kubernetes components (kubelet, kubeadm, kubectl):
sudo yum install -y kubelet kubeadm kubectl sudo systemctl enable kubelet sudo systemctl start kubelet
Disabling Swap
Kubernetes requires swap to be disabled:
sudo sed -i '/swap/d' /etc/fstab sudo swapoff -a
Initializing Kubernetes Cluster
Initialize the Kubernetes cluster using kubeadm:
sudo kubeadm init
Configuring kubectl
To start using Kubernetes, set up the local kubeconfig:
mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
Deploying Pod Network
Install a pod network so that your pods can communicate with each other. Calico is a common choice:
kubectl apply -f https://docs.projectcalico.org/manifests/calico.yaml
Joining Worker Nodes
Use the token provided by the `kubeadm init` command to join worker nodes to your cluster.
Your CentOS 7 server now has Kubernetes installed. This setup forms the foundation for deploying and managing containerized applications at scale with Kubernetes.