[K8s] Installing K8s on vSphere

Hello everyone!

In this article I will try to cover simple installation of K8s on vSphere environment. As i’ve finally started my path to containers world and need some environment to practice. Enjoy reading.

As i’ve mentioned before environment will be quite simple. We will have 1 master node and 2 worker nodes. VMs are based on CentOS 8. As it is a lab environment for practice I didnt pay much attention to the security (i.e. everything is done via root). So if you plan to do it proper way, keep this in mind.

First steps

So first of all we need to prepare 3 VMs and configure them. Turn off swap, disable SELinux, disable firewalld and remove podman (in CentOS8 it is replacement for docker) and install docker.

swapoff -a
sed -i.bak -r 's/(.+ swap .+)/#\1/' /etc/fstab
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld
dnf remove podman -y
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install docker-ce
systemctl start docker
systemctl enable docker

Add K8s Repo /etc/yum.repos.d/kubernetes.repo

name=Kubernetes baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg

And install required packages

dnf install kublet kubeadm kubectl --disableexcludes=kubernetes -y
systemctl start kubelet
systemctl enable kubelet

Enable filtering /etc/sysctl.d/k8s.conf

net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
apply sysctl --system

K8s Installation

Master Node:

We gonna use flannel as our internal network do not change the subnet use the same one as in here

kubeadm init --pod-network-cidr=

After installation was done you will get the command with token to add.

We create system variable:

export KUBECONFIG=/etc/kubernetes/admin.conf

Install flannel:

kubectl apply -f https://github.com/coreos/flannel/raw/master/Documentation/kube-flannel.yml

Worker Nodes:

To join worker nodes use the command which was shown on the screen after you deployed master node using kubeadm init:

kubeadm join --token ujm390.lpzs2nfdp09tqnzd --discovery-token-ca-cert-hash sha256:2cee695ac8f283cbf891a6b5fd9cf294085232012e2b4e65f868cceb30f86e2b

Copy admin.conf from the master node and export it to system variable:

scp root@masternodeIPaddress:/etc/kubernetes/admin.conf /etc/kubernetes/admin.conf
export KUBECONFIG=/etc/kubernetes/admin.conf

Now we can test if everything is good and run:

kubectl get nodes

This is basic installation of k8s using kubeadm.

Hope it was helpful for you!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.