You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.6 KiB

  1. # Kubernetes on vSphere with Terraform
  2. Provision a Kubernetes cluster on [vSphere](https://www.vmware.com/products/vsphere.html) using Terraform and Kubespray.
  3. ## Overview
  4. The setup looks like following.
  5. ```text
  6. Kubernetes cluster
  7. +-----------------------+
  8. | +--------------+ |
  9. | | +--------------+ |
  10. | | | | |
  11. | | | Master/etcd | |
  12. | | | node(s) | |
  13. | +-+ | |
  14. | +--------------+ |
  15. | ^ |
  16. | | |
  17. | v |
  18. | +--------------+ |
  19. | | +--------------+ |
  20. | | | | |
  21. | | | Worker | |
  22. | | | node(s) | |
  23. | +-+ | |
  24. | +--------------+ |
  25. +-----------------------+
  26. ```
  27. ## Warning
  28. This setup assumes that the DHCP is disabled in the vSphere cluster and IP addresses have to be provided in the configuration file.
  29. ## Requirements
  30. * Terraform 0.13.0 or newer
  31. *0.12 also works if you modify the provider block to include version and remove all `versions.tf` files*
  32. ## Quickstart
  33. NOTE: *Assumes you are at the root of the kubespray repo*
  34. Copy the sample inventory for your cluster and copy the default terraform variables.
  35. ```bash
  36. CLUSTER=my-vsphere-cluster
  37. cp -r inventory/sample inventory/$CLUSTER
  38. cp contrib/terraform/vsphere/default.tfvars inventory/$CLUSTER/
  39. cd inventory/$CLUSTER
  40. ```
  41. Edit `default.tfvars` to match your setup. You MUST set values specific for you network and vSphere cluster.
  42. ```bash
  43. # Ensure $EDITOR points to your favorite editor, e.g., vim, emacs, VS Code, etc.
  44. $EDITOR default.tfvars
  45. ```
  46. For authentication in your vSphere cluster you can use the environment variables.
  47. ```bash
  48. export TF_VAR_vsphere_user=username
  49. export TF_VAR_vsphere_password=password
  50. ```
  51. Run Terraform to create the infrastructure.
  52. ```bash
  53. terraform init ../../contrib/terraform/vsphere
  54. terraform apply \
  55. -var-file default.tfvars \
  56. -state=tfstate-$CLUSTER.tfstate \
  57. ../../contrib/terraform/vsphere
  58. ```
  59. You should now have a inventory file named `inventory.ini` that you can use with kubespray.
  60. You can now copy your inventory file and use it with kubespray to set up a cluster.
  61. You can type `terraform output` to find out the IP addresses of the nodes.
  62. It is a good idea to check that you have basic SSH connectivity to the nodes. You can do that by:
  63. ```bash
  64. ansible -i inventory.ini -m ping all
  65. ```
  66. Example to use this with the default sample inventory:
  67. ```bash
  68. ansible-playbook -i inventory.ini ../../cluster.yml -b -v
  69. ```
  70. ## Variables
  71. ### Required
  72. * `machines`: Machines to provision. Key of this object will be used as the name of the machine
  73. * `node_type`: The role of this node *(master|worker)*
  74. * `ip`: The IP address of the machine
  75. * `netmask`: The netmask to use (to be used on the right hand side in CIDR notation, e.g., `24`)
  76. * `network`: The name of the network to attach the machines to
  77. * `gateway`: The IP address of the network gateway
  78. * `vsphere_datacenter`: The identifier of vSphere data center
  79. * `vsphere_compute_cluster`: The identifier of vSphere compute cluster
  80. * `vsphere_datastore`: The identifier of vSphere data store
  81. * `vsphere_server`: This is the vCenter server name or address for vSphere API operations.
  82. * `ssh_public_keys`: List of public SSH keys to install on all machines
  83. * `template_name`: The name of a base image (the OVF template be defined in vSphere beforehand)
  84. ### Optional
  85. * `folder`: Name of the folder to put all machines in (default: `""`)
  86. * `prefix`: Prefix to use for all resources, required to be unique for all clusters in the same project (default: `"k8s"`)
  87. * `inventory_file`: Name of the generated inventory file for Kubespray to use in the Ansible step (default: `inventory.ini`)
  88. * `dns_primary`: The IP address of primary DNS server (default: `8.8.4.4`)
  89. * `dns_secondary`: The IP address of secondary DNS server (default: `8.8.8.8`)
  90. * `firmware`: Firmware to use (default: `bios`)
  91. * `hardware_version`: The version of the hardware (default: `15`)
  92. * `master_cores`: The number of CPU cores for the master nodes (default: 4)
  93. * `master_memory`: The amount of RAM for the master nodes in MB (default: 4096)
  94. * `master_disk_size`: The amount of disk space for the master nodes in GB (default: 20)
  95. * `worker_cores`: The number of CPU cores for the worker nodes (default: 16)
  96. * `worker_memory`: The amount of RAM for the worker nodes in MB (default: 8192)
  97. * `worker_disk_size`: The amount of disk space for the worker nodes in GB (default: 100)
  98. * `vapp`: Boolean to set the template type to vapp. (Default: false)
  99. * `interface_name`: Name of the interface to configure. (Default: ens192)
  100. An example variables file can be found `default.tfvars`