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.

143 lines
5.8 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. The nodes uses a private network for node to node communication and a public interface for all external communication.
  28. ## Requirements
  29. * Terraform 0.13.0 or newer
  30. ## Quickstart
  31. NOTE: Assumes you are at the root of the kubespray repo.
  32. For authentication in your cluster you can use the environment variables.
  33. ```bash
  34. export TF_VAR_UPCLOUD_USERNAME=username
  35. export TF_VAR_UPCLOUD_PASSWORD=password
  36. ```
  37. 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.
  38. Copy the cluster configuration file.
  39. ```bash
  40. CLUSTER=my-upcloud-cluster
  41. cp -r inventory/sample inventory/$CLUSTER
  42. cp contrib/terraform/upcloud/cluster-settings.tfvars inventory/$CLUSTER/
  43. export ANSIBLE_CONFIG=ansible.cfg
  44. cd inventory/$CLUSTER
  45. ```
  46. Edit `cluster-settings.tfvars` to match your requirement.
  47. Run Terraform to create the infrastructure.
  48. ```bash
  49. terraform init ../../contrib/terraform/upcloud
  50. terraform apply --var-file cluster-settings.tfvars \
  51. -state=tfstate-$CLUSTER.tfstate \
  52. ../../contrib/terraform/upcloud/
  53. ```
  54. You should now have a inventory file named `inventory.ini` that you can use with kubespray.
  55. You can use the inventory file with kubespray to set up a cluster.
  56. It is a good idea to check that you have basic SSH connectivity to the nodes. You can do that by:
  57. ```bash
  58. ansible -i inventory.ini -m ping all
  59. ```
  60. You can setup Kubernetes with kubespray using the generated inventory:
  61. ```bash
  62. ansible-playbook -i inventory.ini ../../cluster.yml -b -v
  63. ```
  64. ## Teardown
  65. You can teardown your infrastructure using the following Terraform command:
  66. ```bash
  67. terraform destroy --var-file cluster-settings.tfvars \
  68. -state=tfstate-$CLUSTER.tfstate \
  69. ../../contrib/terraform/upcloud/
  70. ```
  71. ## Variables
  72. * `prefix`: Prefix to add to all resources, if set to "" don't set any prefix
  73. * `template_name`: The name or UUID of a base image
  74. * `username`: a user to access the nodes, defaults to "ubuntu"
  75. * `private_network_cidr`: CIDR to use for the private network, defaults to "172.16.0.0/24"
  76. * `ssh_public_keys`: List of public SSH keys to install on all machines
  77. * `zone`: The zone where to run the cluster
  78. * `machines`: Machines to provision. Key of this object will be used as the name of the machine
  79. * `node_type`: The role of this node *(master|worker)*
  80. * `plan`: Preconfigured cpu/mem plan to use (disables `cpu` and `mem` attributes below)
  81. * `cpu`: number of cpu cores
  82. * `mem`: memory size in MB
  83. * `disk_size`: The size of the storage in GB
  84. * `additional_disks`: Additional disks to attach to the node.
  85. * `size`: The size of the additional disk in GB
  86. * `tier`: The tier of disk to use (`maxiops` is the only one you can choose atm)
  87. * `firewall_enabled`: Enable firewall rules
  88. * `firewall_default_deny_in`: Set the firewall to deny inbound traffic by default. Automatically adds UpCloud DNS server and NTP port allowlisting.
  89. * `firewall_default_deny_out`: Set the firewall to deny outbound traffic by default.
  90. * `master_allowed_remote_ips`: List of IP ranges that should be allowed to access API of masters
  91. * `start_address`: Start of address range to allow
  92. * `end_address`: End of address range to allow
  93. * `k8s_allowed_remote_ips`: List of IP ranges that should be allowed SSH access to all nodes
  94. * `start_address`: Start of address range to allow
  95. * `end_address`: End of address range to allow
  96. * `master_allowed_ports`: List of port ranges that should be allowed to access the masters
  97. * `protocol`: Protocol *(tcp|udp|icmp)*
  98. * `port_range_min`: Start of port range to allow
  99. * `port_range_max`: End of port range to allow
  100. * `start_address`: Start of address range to allow
  101. * `end_address`: End of address range to allow
  102. * `worker_allowed_ports`: List of port ranges that should be allowed to access the workers
  103. * `protocol`: Protocol *(tcp|udp|icmp)*
  104. * `port_range_min`: Start of port range to allow
  105. * `port_range_max`: End of port range to allow
  106. * `start_address`: Start of address range to allow
  107. * `end_address`: End of address range to allow
  108. * `loadbalancer_enabled`: Enable managed load balancer
  109. * `loadbalancer_plan`: Plan to use for load balancer *(development|production-small)*
  110. * `loadbalancers`: Ports to load balance and which machines to forward to. Key of this object will be used as the name of the load balancer frontends/backends
  111. * `port`: Port to load balance.
  112. * `target_port`: Port to the backend servers.
  113. * `backend_servers`: List of servers that traffic to the port should be forwarded to.
  114. * `server_groups`: Group servers together
  115. * `servers`: The servers that should be included in the group.
  116. * `anti_affinity_policy`: Defines if a server group is an anti-affinity group. Setting this to "strict" or yes" will result in all servers in the group being placed on separate compute hosts. The value can be "strict", "yes" or "no". "strict" refers to strict policy doesn't allow servers in the same server group to be on the same host. "yes" refers to best-effort policy and tries to put servers on different hosts, but this is not guaranteed.