Skip to content
Geek and I
Go back

Kubernetes VMware vSphere infrastructure - Phase 2

Updated:
Mike Horwath4 min read

Terraform

Here is where I share my Terraform HCL for deploying the machines that will become my Kubernetes cluster.

This is a follow-up post to phase 1, where I showed how I built my VMware VM template for deployment within my vSphere cluster.

Table of Contents

Open Table of Contents

Requirements

A couple of things to have set up or documented before success:

I used Ubuntu 22.04 LTS as my base and built out my VM Template using a minimal install, and my scripts are based on the apt system toolset. If you use a different distribution, you must update scripts accordingly.

Required changes

In the variables.tf and data.tf files, you must update values to match your configuration.

File: variables.tf

File: data.tf

Here are the files, and I’ll provide links in the next section to download.

data.tf
# This file needs editing before it will pass any checks and plans
# The name of your datacenter
# Change 'Default' to the correct name
data "vsphere_datacenter" "datacenter" {
name = "Default"
}
# Find the template/vm for cloning
# change 'ubuntu2204-template-20230801' to the correct name
data "vsphere_virtual_machine" "k8s" {
name = "ubuntu2204-template-20230801"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
# The name of your resource pool
# change 'Default' to the correct name
data "vsphere_resource_pool" "pool" {
name = "Default/Resources"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
# VLANing baby - you may have just one
# change 'vSwitch70' to the correct name
data "vsphere_network" "exterior" {
name = "vSwitch70"
datacenter_id = data.vsphere_datacenter.datacenter.id
}
# NFS network
# change 'vSwitch91' to the correct name
# data "vsphere_network" "interior" {
# name = "vSwitch91"
# datacenter_id = data.vsphere_datacenter.datacenter.id
# }
# Your folder within vSphere
# change 'Kubernetes' to your VM and Template folder destination
data "vsphere_folder" "k8s" {
path = "Kubernetes"
}
variables.tf
# Your VM username for login over ssh
variable "vm_username" {
type = string
default = "linux-user"
}
#####
# Tuple field order per node:
# hostname
# domain name
# ipv4 primary IP
# ipv4 primary netmask (CIDR prefix)
# ipv4 primary gateway
# ipv6 primary IP
# ipv6 primary netmask
# ipv6 primary gateway
# (reserved / unused)
# datastore-xxxxx ID (manual placement)
# ipv4 secondary IP (NFS network on another VLAN)
# ipv4 secondary netmask
# ipv6 secondary IP
# ipv6 secondary netmask
#####
### The worker's block ###
variable "k8s_instance_workers" {
type = list(tuple([string, string, string, number, string, string, number, string, number, string, string, number, string, number]))
default = [
["worker1", "example.com", "192.168.7.65", 22, "192.168.7.254", "fc00:beef:c0ff:70::65", 64, "fc00:beef:c0ff:70::ffff", 0, "datastore-12346", "192.168.8.65", 22, "fc00:beef:c0ff:91::65", 64],
["worker2", "example.com", "192.168.7.66", 22, "192.168.7.254", "fc00:beef:c0ff:70::66", 64, "fc00:beef:c0ff:70::ffff", 0, "datastore-12347", "192.168.8.66", 22, "fc00:beef:c0ff:91::66", 64],
["worker3", "example.com", "192.168.7.67", 22, "192.168.7.254", "fc00:beef:c0ff:70::67", 64, "fc00:beef:c0ff:70::ffff", 0, "datastore-12346", "192.168.8.67", 22, "fc00:beef:c0ff:91::67", 64],
]
}
### The etcd/control-plane block ###
variable "k8s_instance_etcd" {
type = list(tuple([string, string, string, number, string, string, number, string, number, string, string, number, string, number]))
default = [
["cp1", "example.com", "192.168.7.124", 22, "192.168.7.254", "fc00:beef:c0ff:70::129", 64, "fc00:beef:c0ff:70::ffff", 0, "datastore-40746", "192.168.8.129", 22, "fc00:beef:c0ff:91::129", 64],
["cp2", "example.com", "192.168.7.130", 22, "192.168.7.254", "fc00:beef:c0ff:70::130", 64, "fc00:beef:c0ff:70::ffff", 0, "datastore-40747", "192.168.8.130", 22, "fc00:beef:c0ff:91::130", 64],
["cp3", "example.com", "192.168.7.131", 22, "192.168.7.254", "fc00:beef:c0ff:70::131", 64, "fc00:beef:c0ff:70::ffff", 0, "datastore-32784", "192.168.8.131", 22, "fc00:beef:c0ff:91::131", 64],
]
}

Individual files

Each of these links will download the different files you need to have in the same directory you will be operating Terraform out of.

Tar file

This tar file will extract a folder named deploy-kubez with the HCL files and the provisioning script.

Summary

And onwards to the next phase, using kubespray to deploy Kubernetes into your systems!



Related Posts

Previous Post
Kubernetes home-lab via SBCs
Next Post
Kubernetes VMware VSphere Infrastructure – Phase 3