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.

137 lines
3.9 KiB

  1. # Kubernetes on Openstack with Terraform
  2. Provision a Kubernetes cluster with [Terraform](https://www.terraform.io) on
  3. Openstack.
  4. ## Status
  5. This will install a Kubernetes cluster on an Openstack Cloud. It is tested on a
  6. OpenStack Cloud provided by [BlueBox](https://www.blueboxcloud.com/) and
  7. should work on most modern installs of OpenStack that support the basic
  8. services.
  9. There are some assumptions made to try and ensure it will work on your openstack cluster.
  10. * floating-ips are used for access
  11. * you already have a suitable OS image in glance
  12. * you already have both an internal network and a floating-ip pool created
  13. * you have security-groups enabled
  14. ## Requirements
  15. - [Install Terraform](https://www.terraform.io/intro/getting-started/install.html)
  16. ## Terraform
  17. Terraform will be used to provision all of the OpenStack resources required to
  18. run Docker Swarm. It is also used to deploy and provision the software
  19. requirements.
  20. ### Prep
  21. #### OpenStack
  22. Ensure your OpenStack credentials are loaded in environment variables. This is
  23. how I do it:
  24. ```
  25. $ source ~/.stackrc
  26. ```
  27. You will need two networks before installing, an internal network and
  28. an external (floating IP Pool) network. The internet network can be shared as
  29. we use security groups to provide network segregation. Due to the many
  30. differences between OpenStack installs the Terraform does not attempt to create
  31. these for you.
  32. By default Terraform will expect that your networks are called `internal` and
  33. `external`. You can change this by altering the Terraform variables `network_name` and `floatingip_pool`.
  34. A full list of variables you can change can be found at [variables.tf](variables.tf).
  35. All OpenStack resources will use the Terraform variable `cluster_name` (
  36. default `example`) in their name to make it easier to track. For example the
  37. first compute resource will be named `example-kubernetes-1`.
  38. #### Terraform
  39. Ensure your local ssh-agent is running and your ssh key has been added. This
  40. step is required by the terraform provisioner:
  41. ```
  42. $ eval $(ssh-agent -s)
  43. $ ssh-add ~/.ssh/id_rsa
  44. ```
  45. Ensure that you have your Openstack credentials loaded into Terraform
  46. environment variables. Likely via a command similar to:
  47. ```
  48. $ echo Setting up Terraform creds && \
  49. export TF_VAR_username=${OS_USERNAME} && \
  50. export TF_VAR_password=${OS_PASSWORD} && \
  51. export TF_VAR_tenant=${OS_TENANT_NAME} && \
  52. export TF_VAR_auth_url=${OS_AUTH_URL}
  53. ```
  54. # Provision a Kubernetes Cluster on OpenStack
  55. ```
  56. terraform apply -state=contrib/terraform/openstack/terraform.tfstate contrib/terraform/openstack
  57. openstack_compute_secgroup_v2.k8s_master: Creating...
  58. description: "" => "example - Kubernetes Master"
  59. name: "" => "example-k8s-master"
  60. rule.#: "" => "<computed>"
  61. ...
  62. ...
  63. Apply complete! Resources: 9 added, 0 changed, 0 destroyed.
  64. The state of your infrastructure has been saved to the path
  65. below. This state is required to modify and destroy your
  66. infrastructure, so keep it safe. To inspect the complete state
  67. use the `terraform show` command.
  68. State path: contrib/terraform/openstack/terraform.tfstate
  69. ```
  70. Make sure you can connect to the hosts:
  71. ```
  72. $ ansible -i contrib/terraform/openstack/hosts -m ping all
  73. example-k8s_node-1 | SUCCESS => {
  74. "changed": false,
  75. "ping": "pong"
  76. }
  77. example-etcd-1 | SUCCESS => {
  78. "changed": false,
  79. "ping": "pong"
  80. }
  81. example-k8s-master-1 | SUCCESS => {
  82. "changed": false,
  83. "ping": "pong"
  84. }
  85. ```
  86. if it fails try to connect manually via SSH ... it could be somthing as simple as a stale host key.
  87. Deploy kubernetes:
  88. ```
  89. $ ansible-playbook --become -i contrib/terraform/openstack/hosts cluster.yml
  90. ```
  91. # clean up:
  92. ```
  93. $ terraform destroy
  94. Do you really want to destroy?
  95. Terraform will delete all your managed infrastructure.
  96. There is no undo. Only 'yes' will be accepted to confirm.
  97. Enter a value: yes
  98. ...
  99. ...
  100. Apply complete! Resources: 0 added, 0 changed, 12 destroyed.
  101. ```