DEV Community

collabnix for collabnixcommunity

Posted on

Installing Kubernetes on CentOS 7, RHEL 7 and Fedora 25+ using Kubeadm

Alt Text

Installing Kubernetes with Kubeadm on CentOS 7/RHEL 7/Fedora 25+

Installing kubeadm, kubectl & kubelet

  1. Copy paste the below snippet one by one in your CLI terminal - This is for both Master and Worker Nodes
cat <<EOF > /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
exclude=kubelet kubeadm kubectl
EOF
Enter fullscreen mode Exit fullscreen mode

Setting up SELinux in permissive mode (effectively disabling it)

setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
yum install -y kubelet kubeadm kubectl --disableexcludes=kubernetes
systemctl enable --now kubelet
Enter fullscreen mode Exit fullscreen mode

Initialize kubeadm - This is only for Master

kubeadm init
Enter fullscreen mode Exit fullscreen mode

Setting up kubeconfig - This is only for Master Node

  mkdir -p $HOME/.kube
  cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
  chown $(id -u):$(id -g) $HOME/.kube/config
Enter fullscreen mode Exit fullscreen mode

Copy token from kubeadmn init snippet - This you should copy from Master. This you will get from Master node only

kubeadm join <control-plane-host>:<control-plane-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
Enter fullscreen mode Exit fullscreen mode

Installing Network Plugin - This is only for Master Node

kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"
Enter fullscreen mode Exit fullscreen mode

Join Worker Nodes - This is only for Worker Nodes

kubeadm join --token <token> <control-plane-host>:<control-plane-port> --discovery-token-ca-cert-hash sha256:<hash>
Enter fullscreen mode Exit fullscreen mode

Note:

Please do not run Master node snippet commands on Worker Nodes.

References

  1. https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/install-kubeadm/#installing-kubeadm-kubelet-and-kubectl
  2. https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#initializing-your-control-plane-node

Top comments (0)