Skip to content

Instantly share code, notes, and snippets.

@nirbhabbarat
Last active January 23, 2023 17:29
Show Gist options
  • Save nirbhabbarat/344dcac9c2b0760ffb92ed5c7503069a to your computer and use it in GitHub Desktop.
Save nirbhabbarat/344dcac9c2b0760ffb92ed5c7503069a to your computer and use it in GitHub Desktop.
install kubernetes on centos 7 vagrant

Create CentOS 7

vagrant init centos/7
vagrant up

Disable SELinux & setup firewall rules

hostnamectl set-hostname 'k8s-master'
exec bash
setenforce 0
sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
firewall-cmd --permanent --add-port=6443/tcp
firewall-cmd --permanent --add-port=2379-2380/tcp
firewall-cmd --permanent --add-port=10250/tcp
firewall-cmd --permanent --add-port=10251/tcp
firewall-cmd --permanent --add-port=10252/tcp
firewall-cmd --permanent --add-port=10255/tcp
firewall-cmd --reload
modprobe br_netfilter
echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables
swapoff -a

Configure Kubernetes Repository

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[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
EOF

Install Kubeadm and Docker

yum install kubeadm docker -y
systemctl restart docker && systemctl enable docker
systemctl  restart kubelet && systemctl enable kubelet

KubeAdmin init

kubeadm init

Setup Kube Config

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

Deploy pod network to the cluster

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

Let pods get scheduled in master as well # not for production setup

kubectl taint nodes $(hostname) node-role.kubernetes.io/master:NoSchedule-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment