Provisioning a k8s cluster on virtualbox with terraform

Hi,
I am newbie on terraform and trying to install a k8s cluster on my virtual box vm with terraform. I saw that it is possible to provision k8s cluster on cloud environment, but is there a way to install k8s cluster on virtual box with terraform?

Hi @yilmazmerve97,

Terraform typically manages objects in network APIs rather than local software running on a computer.

If you can find a VirtualBox provider for Terraform then you could potentially use it to start a virtual machine in VirtualBox using Terraform, but exactly what software runs in that VM is outside of Terraform’s scope; you’d need to start from a machine image which already has Kubernetes installed, and then Terraform could launch it.

If your goal is to create a small Kubernetes cluster for local development then I believe a common answer for that is minikube, but that is not a Terraform-based solution and so I can’t give any more guidance on its use here.

Hi @apparentlymart,
I got it, thank you. I tried to create a vm with virtual box provider. But i am getting following error:

[ERROR] vertex “virtualbox_vm.node[0]” error: [ERROR] Create virtualbox VM master-k8s-node: exit status 2

Error: [ERROR] Create virtualbox VM master-k8s-node: exit status 2

I did not find any answer to help me. Here is my configuration:

terraform {
  required_providers {
    virtualbox = {
      source = "terra-farm/virtualbox"
      version = "0.2.2-alpha.1"
    }
  }
}


resource "virtualbox_vm" "node" {
  count     = 1
  name      = "master-k8s-node"
  image     = "https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20180903.0.0/providers/virtualbox.box"
  cpus      = 2
  memory    = "512 mib"

  network_adapter {
    type           = "hostonly"
    host_interface = "vboxnet1"
  }
}
output "IPAddr" {
  value = element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 1)
}

output "IPAddr_2" {
  value = element(virtualbox_vm.node.*.network_adapter.0.ipv4_address, 2)
}