Smooth Sailing: A Step-by-Step Guide to Effortlessly Set Up a Kubernetes Cluster on CentOS virtual machines.

Smooth Sailing: A Step-by-Step Guide to Effortlessly Set Up a Kubernetes Cluster on CentOS virtual machines.

In today's fast-paced digital landscape, orchestrating and managing containerized applications has become a necessity rather than a luxury. Kubernetes, the industry-standard container orchestration platform, empowers developers to effortlessly deploy, scale, and manage applications. However, for those new to the world of Kubernetes, setting up a cluster might seem like a daunting task. Fear not! In this guide, we'll take you on a journey to create your very own Kubernetes cluster on CentOS, unraveling the complexity and making the process as easy as a stroll in the park.

Let's start with setting up a virtual machine with static IPs

  1. Downloaded and installed Oracle VirtualBox on your host machine.

  2. Downloaded the CentOS 7 ISO file from the official CentOS website.

Step 1: Installing VirtualBox:

  1. Launch the VirtualBox installer and follow the on-screen instructions to install the application.

  2. Once installed, open VirtualBox.

Step 2: Creating a New Virtual Machine:

  1. Click the "New" button in the VirtualBox Manager window.

  2. Choose a name for your VM (e.g., "CentOS7_VM").

  3. Select the desired ISO file you want to run the virtual machine and click Next leaving others settings as default.

  4. Allocate memory (RAM) for your VM. A minimum of 1024MB is recommended.

  5. Choose "Create a virtual hard disk now" and click "Create."

Step 3: Configuring Virtual Hard Disk:

  1. Select "VDI (VirtualBox Disk Image)" as the hard disk file type.

  2. Choose "Dynamically allocated" for storage on physical hard disk.

  3. Allocate a suitable amount of storage space (at least 20GB).

  4. Click "Create" to create the virtual hard disk.

Step 4: Installing CentOS 7:

  1. In the VirtualBox Manager, right-click your newly created VM and select "Settings."

  2. Under "Storage," add the CentOS 7 ISO file to the optical drive.

  3. Start the VM by clicking "Start."

  4. In the CentOS boot menu, choose "Install CentOS 7" and follow the installation wizard:

    • Select language, keyboard layout, and installation source (use the attached ISO).

    • Configure network settings and set a root password.

    • Choose the installation destination (use default settings).

    • Customize software selection if desired (minimal install recommended).

    • Begin the installation process.

Step 5: Post-Installation Setup:

  1. After installation, click the "Reboot" button and remove the installation media (ISO) from the VM.

  2. CentOS 7 will boot into the newly installed system.

  3. Log in using the root credentials you set during installation.

Step 7: Basic Configuration and Updates:

  1. Update CentOS: Run sudo yum update in the terminal to update installed packages.

  2. Install additional software using yum package manager.

Step 8: Setting up a static IP for vm:

  1. Got to file /etc/sysconfig/network-scripts/ifcfg-enp0s3:

    sudo vi /etc/sysconfig/network-scripts/ifcfg-enp0s3

    edit the configuration to











    IPADDR=<YourIPaddress> # to 192.168.199






    You can change the GATEWAY from to to get to 192.168.299 range.

  2. After configuring the file run the below command to enable, restart the Network

    sudo systemctl enable network

    sudo systemctl restart network

Congratulations! You've successfully created a CentOS 7 virtual machine on Oracle VirtualBox with static IP.

setting up a multi-node Kubernetes cluster in Centos 7.

  1. Set hostname and update /etc/hosts file for local name resolution.

hostnamectl set-hostname k8smaster

repeat the same in the worker machines.

  1. sudo vi /etc/fstab and comment the entire line naming swap and execute sudo swapoff -a

  2. Disable Firewalld

     sudo systemctl disable firewalld

Repeat this in master and worker machines.

  1. Configure IP tables

     sudo /etc/sysctl.d/k8s.conf
     net.bridge.bridge-nf-call-ip6tables = 1
     net.bridge.bridge-nf-call-iptables = 1
     sudo sysctl --system

    Repeat this in master and worker machines

  2. Add Kubernetes Repo in yum.repos.d.

    Repeat this in master and worker machines

     sudo nano /etc/yum.repos.d/kubernetes.repo
  3. Set SElinux to enforcing mode

    Repeat this in master and worker machines

    #disable SE linux

     sudo setenforce 0
     sudo sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
  4. Add Docker repo

    Repeat this in master and worker

    sudo yum install -y yum-utils

  5. Install Docker:

     sudo yum-config-manager \
         --add-repo \

    sudo yum install docker-ce docker-ce-cli docker-compose-plugin

    Repeat this in master and worker.

  6. Create a overlay2 docker configuration file.

sudo nano /etc/docker/daemon.json 

  "exec-opts": ["native.cgroupdriver=systemd"],
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m"
  "storage-driver": "overlay2"

Repeat this in master and worker machines.

  1. Modify containerd's config file

    sudo nano /etc/containerd/config.toml

    and modify disabled_plugins = ["cri"] to enabled_plugins = ["cri"] (Below is the complete file)

     #   Copyright 2018-2022 Docker Inc.
     #   Licensed under the Apache License, Version 2.0 (the "License");
     #   you may not use this file except in compliance with the License.
     #   You may obtain a copy of the License at
     #   Unless required by applicable law or agreed to in writing, software
     #   distributed under the License is distributed on an "AS IS" BASIS,
     #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     #   See the License for the specific language governing permissions and
     #   limitations under the License.
     enabled_plugins = ["cri"]
     #root = "/var/lib/containerd"
     #state = "/run/containerd"
     #subreaper = true
     #oom_score = 0
     #  address = "/run/containerd/containerd.sock"
     #  uid = 0
     #  gid = 0
     #  address = "/run/containerd/debug.sock"
     #  uid = 0
     #  gid = 0
     #  level = "info"

    Repeat this in master and worker.

  2. Install with docker Version

     sudo systemctl daemon-reload
     sudo systemctl enable docker
     sudo systemctl start docker

    Repeat this in master and worker.

  3. Install Kubeadm

     sudo yum install -y kubeadm kubelet kubectl

    Repeat this in master and worker machines.

  4. Check status of docker.

    sudo systemctl status docker

  5. Now Init Kubeadm

    Here after do only in master

    sudo kubeadm init

  6. To start using your cluster, you need to run the following as a regular user:
    mkdir -p $HOME/.kube
    sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config
    Alternatively, if you are the root user, you can run:
    export KUBECONFIG=/etc/kubernetes/admin.conf

  7. Add Pod Network

     kubectl apply -f
  8. When you run this it generates the join nodes command copy it and paste in worker node.

  9. Now Check the status of nodes (Do it in the master machine)

     kubectl get nodes

    it will display the master and worker with the status Ready


You've taken your virtual environment to the next level by successfully setting up a Kubernetes cluster on your CentOS 7 virtual machine within Oracle VirtualBox. Kubernetes offers powerful container orchestration capabilities, enabling you to manage and deploy applications efficiently. Whether you're exploring DevOps practices, testing microservices, or learning about containerization, your Kubernetes cluster provides a valuable playground for innovation and experimentation. As you delve into the world of Kubernetes, remember that continuous learning and hands-on experience will be your best allies on this exciting journey. Happy clustering!