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.

106 lines
2.9 KiB

  1. # Kubernetes on UpCloud with Terraform
  2. Provision a Kubernetes cluster on [UpCloud](https://upcloud.com/) 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. ## Requirements
  28. * Terraform 0.13.0 or newer
  29. ## Quickstart
  30. NOTE: Assumes you are at the root of the kubespray repo.
  31. For authentication in your cluster you can use the environment variables.
  32. ```bash
  33. export TF_VAR_UPCLOUD_USERNAME=username
  34. export TF_VAR_UPCLOUD_PASSWORD=password
  35. ```
  36. To allow API access to your UpCloud account, you need to allow API connections by visiting [Account-page](https://hub.upcloud.com/account) in your UpCloud Hub.
  37. Copy the cluster configuration file.
  38. ```bash
  39. CLUSTER=my-upcloud-cluster
  40. cp -r inventory/sample inventory/$CLUSTER
  41. cp contrib/terraform/upcloud/cluster-settings.tfvars inventory/$CLUSTER/
  42. export ANSIBLE_CONFIG=ansible.cfg
  43. cd inventory/$CLUSTER
  44. ```
  45. Edit `cluster-settings.tfvars` to match your requirement.
  46. Run Terraform to create the infrastructure.
  47. ```bash
  48. terraform init ../../contrib/terraform/upcloud
  49. terraform apply --var-file cluster-settings.tfvars \
  50. -state=tfstate-$CLUSTER.tfstate \
  51. ../../contrib/terraform/upcloud/
  52. ```
  53. You should now have a inventory file named `inventory.ini` that you can use with kubespray.
  54. You can use the inventory file with kubespray to set up a cluster.
  55. It is a good idea to check that you have basic SSH connectivity to the nodes. You can do that by:
  56. ```bash
  57. ansible -i inventory.ini -m ping all
  58. ```
  59. You can setup Kubernetes with kubespray using the generated inventory:
  60. ```bash
  61. ansible-playbook -i inventory.ini ../../cluster.yml -b -v
  62. ```
  63. ## Teardown
  64. You can teardown your infrastructure using the following Terraform command:
  65. ```bash
  66. terraform destroy --var-file cluster-settings.tfvars \
  67. -state=tfstate-$CLUSTER.tfstate \
  68. ../../contrib/terraform/upcloud/
  69. ```
  70. ## Variables
  71. * `hostname`: A valid domain name, e.g. example.com. The maximum length is 128 characters.
  72. * `template_name`: The name or UUID of a base image
  73. * `username`: a user to access the nodes
  74. * `ssh_public_keys`: List of public SSH keys to install on all machines
  75. * `zone`: The zone where to run the cluster
  76. * `machines`: Machines to provision. Key of this object will be used as the name of the machine
  77. * `node_type`: The role of this node *(master|worker)*
  78. * `cpu`: number of cpu cores
  79. * `mem`: memory size in MB
  80. * `disk_size`: The size of the storage in GB