> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Deployment With Kubeadm Provision VMs With Vagrant

> Guide to provisioning a three-node Kubernetes cluster using Vagrant and VirtualBox, with Vagrantfile and provisioning scripts to create one master and two worker VMs

In this lesson we provision a small kube-node2 cluster: one Kubernetes master and two worker nodes. We use VirtualBox as the hypervisor and Vagrant to automate VM creation and provisioning so everyone can reproduce the same environment with a single command.

Tools used

* VirtualBox — hypervisor for running the VMs.
* Vagrant — automation tool to define, create, and provision multiple VMs from a single `Vagrantfile`.

Prerequisites

* Install VirtualBox for your OS: [https://www.virtualbox.org](https://www.virtualbox.org)
* Install Vagrant: [https://www.vagrantup.com/docs](https://www.vagrantup.com/docs)
* Download or clone the lesson repository so the `Vagrantfile` and provisioning scripts (the `ubuntu/` directory) are available locally.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/-XczbL3T0rqckZCZ/images/Certified-Kubernetes-Administrator-CKA/Install-Kubernetes-the-kubeadm-way/Deployment-With-Kubeadm-Provision-VMs-With-Vagrant/virtualbox-download-7-0-6-screenshot.jpg?fit=max&auto=format&n=-XczbL3T0rqckZCZ&q=85&s=d859bb18a6b85591589d164c1269b033" alt="A screenshot of the VirtualBox &#x22;Download VirtualBox&#x22; webpage showing version 7.0.6 platform packages and download links in a browser window. The browser UI and Windows taskbar are visible at the top and bottom of the screen." width="1920" height="1080" data-path="images/Certified-Kubernetes-Administrator-CKA/Install-Kubernetes-the-kubeadm-way/Deployment-With-Kubeadm-Provision-VMs-With-Vagrant/virtualbox-download-7-0-6-screenshot.jpg" />
</Frame>

If you obtained the lesson files from a repository, clone it:

```bash theme={null}
git clone <repository-url>
```

Then change into the repository and confirm the `Vagrantfile` and supporting folders exist:

```bash theme={null}
cd certified-kubernetes-administrator-course
ls -la
# Expected output includes: Vagrantfile  ubuntu/  resources/  README.md  etc.
```

The repository and Vagrantfile are included with the lesson materials:

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/-XczbL3T0rqckZCZ/images/Certified-Kubernetes-Administrator-CKA/Install-Kubernetes-the-kubeadm-way/Deployment-With-Kubeadm-Provision-VMs-With-Vagrant/cka-course-github-repo-screenshot.jpg?fit=max&auto=format&n=-XczbL3T0rqckZCZ&q=85&s=304489077934b68435eb219288a67852" alt="A screenshot of a GitHub repository page for the &#x22;Certified Kubernetes Administrator (CKA) Course&#x22; showing the file list (docs, images, resources, etc.) and the README content. The right sidebar displays repository stats like stars, forks, and contributors." width="1920" height="1080" data-path="images/Certified-Kubernetes-Administrator-CKA/Install-Kubernetes-the-kubeadm-way/Deployment-With-Kubeadm-Provision-VMs-With-Vagrant/cka-course-github-repo-screenshot.jpg" />
</Frame>

Open the `Vagrantfile` to review the VM configuration. The file below defines the base box and the provisioning for the master node; worker nodes are configured further down in the same file:

```ruby theme={null}
# -*- mode: ruby -*-
# Define the number of master and worker nodes
# If this number is changed, remember to update setup-hosts.sh script with the new hosts IP details in /etc/hosts of each VM.
NUM_MASTER_NODE = 1
NUM_WORKER_NODE = 2

IP_NW = "192.168.56."
MASTER_IP_START = 1
NODE_IP_START = 2

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.box_check_update = false

  # Provision Master Nodes
  (1..NUM_MASTER_NODE).each do |i|
    config.vm.define "kubemaster" do |node|
      node.vm.provider "virtualbox" do |vb|
        vb.name = "kubemaster"
        vb.memory = 2048
        vb.cpus = 2
      end
      node.vm.hostname = "kubemaster"
      node.vm.network :private_network, ip: IP_NW + "#{MASTER_IP_START + i}"
      node.vm.network "forwarded_port", guest: 22, host: "#{2710 + i}"

      node.vm.provision "setup-hosts", :type => "shell", :path => "ubuntu/vagrant/setup-hosts.sh" do |s|
        s.args = ["enp0s8"]
      end

      node.vm.provision "setup-dns", type: "shell", :path => "ubuntu/update-dns.sh"
    end
  end

  # Worker nodes and other configuration follow...
end
```

What to notice in this configuration

* The VMs use a host-only network in the `192.168.56.x` range.
* Hostnames, `/etc/hosts` entries, DNS, and additional configuration are applied by provisioning scripts under `ubuntu/`.
* SSH port forwarding uses the pattern `host_port = 2710 + i` for each defined VM.

Cluster VM details (summary)

| VM name | Role | Private IP pattern | SSH host port formula |
| - | - | - | - |
| `kubemaster` | Kubernetes master | `192.168.56.<MASTER_IP_START + i>` | `2710 + i` (e.g., `2711` for i=1) |
| `kubenode01`, `kubenode02` | Worker nodes | `192.168.56.<NODE_IP_START + i>` | `2710 + i` (incrementing per VM) |

Bringing up the VMs
First check the current Vagrant machine state:

```bash theme={null}
vagrant status
```

Before creating the machines you will see them as "not created":

```text theme={null}
Current machine states:

kubemaster               not created (virtualbox)
kubenode01               not created (virtualbox)
kubenode02               not created (virtualbox)
```

Start all VMs and run provisioning with:

```bash theme={null}
vagrant up
```

Vagrant will download the `ubuntu/bionic64` box if needed, create the VMs, set networking and resources, and run the provisioning scripts. This can take several minutes. Example provisioning output (abbreviated):

```text theme={null}
Bringing machine 'kubemaster' up with 'virtualbox' provider...
==> kubemaster: Importing base box 'ubuntu/bionic64'...
==> kubemaster: Setting the name of the VM: kubemaster
==> kubemaster: Preparing network interfaces based on configuration...
==> kubemaster: Forwarding ports...
kubemaster: 22 (guest) => 2711 (host)
==> kubemaster: Booting VM...
==> kubemaster: Waiting for machine to boot. This may take a few minutes...
kubemaster: SSH address: 127.0.0.1:2222
kubemaster: SSH username: vagrant
kubemaster: SSH auth method: private key
==> kubemaster: Machine booted and ready!
==> kubemaster: Running provisioner: setup-hosts (shell)...
==> kubemaster: Running provisioner: setup-dns (shell)...
# Similar output for kubenode01 and kubenode02
```

<Callout icon="lightbulb" color="#1CB2FE">
  If you see VirtualBox Guest Additions mismatch warnings or shared folder issues during provisioning, they are common. To resolve these, either update the guest additions inside the VMs to match your host VirtualBox version or use the `vagrant-vbguest` plugin to automate guest additions management: [https://github.com/dotless-de/vagrant-vbguest](https://github.com/dotless-de/vagrant-vbguest)
</Callout>

After `vagrant up` finishes, verify the VMs are running:

```bash theme={null}
vagrant status
```

Expected output:

```text theme={null}
Current machine states:

kubemaster               running (virtualbox)
kubenode01               running (virtualbox)
kubenode02               running (virtualbox)
```

Connecting to the VMs
Use `vagrant ssh` with the VM name to open a shell on any VM:

```bash theme={null}
vagrant ssh kubemaster
vagrant ssh kubenode01
vagrant ssh kubenode02
```

Inside a VM you can run standard commands to verify networking and system status:

```bash theme={null}
# Example session
vagrant ssh kubenode02
# vagrant@kubenode02:~$ uptime
# vagrant@kubenode02:~$ ip addr show enp0s8
# vagrant@kubenode02:~$ logout
```

When you're done with a VM shell, use `exit` or `logout` to return to your host.

Next steps
You now have three provisioned VMs (one master, two workers) reachable via `vagrant ssh`. Use these machines to follow the kubeadm-based Kubernetes installation and cluster configuration steps in the next lessons.

Useful references

* VirtualBox: [https://www.virtualbox.org](https://www.virtualbox.org)
* Vagrant documentation: [https://www.vagrantup.com/docs](https://www.vagrantup.com/docs)
* `vagrant-vbguest` plugin: [https://github.com/dotless-de/vagrant-vbguest](https://github.com/dotless-de/vagrant-vbguest)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/cka-certification-course-certified-kubernetes-administrator/module/357c2670-c16c-49ac-aa27-8af52523afde/lesson/1b4c8ff7-10f1-4f8b-a18c-cbecba04f3bb" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.