Giter VIP home page Giter VIP logo

terraform-openstack-rke's Introduction

terraform-openstack-rke

Terraform Registry Build Status

Terraform module to deploy Kubernetes with RKE on OpenStack.

Inspired by Marco Capuccini work, rewritten from scratch for Terraform 0.12+ and new terraform-rke-provider.

๐Ÿ’ฅ You can now use the next generation rke/openstack module, go to terraform-openstack-rke2 ๐Ÿ’ฅ

Table of contents

Prerequisites

  • Terraform 0.13+. For Terraform 0.12.x, use terraform/v0.12 branch.
  • OpenStack environment properly sourced.
  • A Openstack image fullfiling RKE requirements.
  • At least one Openstack floating IP.

Terraform 0.13 upgrade

terraform-openstack-rke >= 0.5 supports Terraform >= 0.13. Some changes in the way Terraform manage providers require manual operations.

terraform 0.13upgrade
terraform  state replace-provider 'registry.terraform.io/-/rke' 'registry.terraform.io/rancher/rke'
terraform init

For more informations see Upgrading to Terraform v0.13

โš ๏ธ There is some deep changes between 0.4 and 0.5 branches. This may lead to a replacement of the nodes and the rke cluster resources โš ๏ธ

Examples

Minimal example with master node as egde node and two worker nodes

# Consider using 'export TF_VAR_os_auth_url=$OS_AUTH_URL'
variable "os_auth_url"{}
# Consider using 'export TF_VAR_os_password=$OS_PASSWORD'
variable "os_password"{}

 module "rke" {
  source  = "remche/rke/openstack"
  image_name          = "ubuntu-18.04-docker-x86_64"
  public_net_name     = "public"
  master_flavor_name  = "m1.small"
  worker_flavor_name  = "m1.small"
  os_auth_url         = var.os_auth_url
  os_password         = var.os_password
}

Minimal example with two egde nodes and one worker nodes

# Consider using 'export TF_VAR_os_auth_url=$OS_AUTH_URL'
variable "os_auth_url"{}
# Consider using 'export TF_VAR_os_password=$OS_PASSWORD'
variable "os_password"{}

 module "rke" {
  source  = "remche/rke/openstack"
  image_name          = "ubuntu-18.04-docker-x86_64"
  public_net_name     = "public"
  master_flavor_name  = "m1.small"
  worker_flavor_name  = "m1.small"
  edge_count          = 2
  worker_count        = 1
  master_labels       = {"node-role.kubernetes.io/master" = "true"}
  edge_labels         = {"node-role.kubernetes.io/edge" = "true"}
  os_auth_url         = var.os_auth_url
  os_password         = var.os_password
}

Documentation

See USAGE.md for all available options.

Keypair

You can either specify a ssh key file to generate new keypair via ssh_key_file (default) or specify already existent keypair via ssh_keypair_name.

โš ๏ธ Default config will try to use ssh agent for ssh connections to the nodes. Add use_ssh_agent = false if you don't use it.

Secgroup

You can define your own rules (e.g. limiting port 22 and 6443 to admin box).

secgroup_rules      = [ { "source" = "x.x.x.x", "protocol" = "tcp", "port" = 22 },
                        { "source" = "x.x.x.x", "protocol" = "tcp", "port" = 6443 },
                        { "source" = "0.0.0.0/0", "protocol" = "tcp", "port" = 80 },
                        { "source" = "0.0.0.0/0", "protocol" = "tcp", "port" = 443}
                      ]

Nodes

Default config will deploy one master and two worker nodes. It will use Traefik (nginx not supported in this case). You can define edge nodes (see above).

You can set affinity policy for each nodes group (master, worker, edge) via {master,worker,edge}_server_affinity. Default is soft-anti-affinity.

โš ๏ธ soft-anti-affinity and soft-affinity needs Compute service API 2.15 or above.

You can use wait_for_commands to specify a list of commands to be run before invoking RKE. It can be useful when installing Docker at provision time (note that cooking your image embedding Docker with Packer is a better practice though) : wait_for_commands = ["while docker info ; [ $? -ne 0 ]; do echo wait for docker; sleep 30 ; done"]

Boot from volume

Some providers require to boot the instances from an attached boot volume instead of the nova ephemeral volume. To enable this feature, provide the variables to the config file:

boot_from_volume = true
boot_volume_size = 20

Loadbalancer

If enable_loadbalancer = true this module will create a layer 4 loadbalancer using LBaaS or LBaaSv2 in front of the master nodes or the edge nodes if there are any. It creates appropriate TCP listeners and monitors for HTTP (:80), HTTPS (:443) and Kubernetes API (:6443).

To use Octavia instead of Neutron Networking as LBaaS, use

use_octavia = true

Kubernetes version

You can specify kubernetes version with kubernetes_version variables. Refer to RKE supported version.

Cloud provider

The module will deploy Openstack Cloud Provider. It will create the Kubernetes Storageclasses for Cinder. If you have many Cinder storage type, you can specify it in storage_types variable.

You can disable cloud provider via cloud_provider variable.

Reverse Proxy

The module will deploy Traefik by default but you can use nginx-ingress instead. Note that nginx is not supported when master node is the edge node.

User Add-Ons

You can specify you own User Add_Ons with addons_include variable.

Usage with RancherOS

RancherOS needs a node config drive to be configured. You can also provide a cloud config file :

image_name          = "rancheros-1.5.5-x86_64"
system_user         = "rancher"
nodes_config_drive  = "true"
user_data_file      = "rancher.yml"

โš ๏ธ Interpolating provider variables from module output is not the recommended way to achieve integration. See here and here.

Use of a data sources is recommended.

(Not recommended) You can use this module to populate Terraform Kubernetes Provider :

provider "kubernetes" {
  host     = module.rke.rke_cluster.api_server_url
  username = module.rke.rke_cluster.kube_admin_user

  client_certificate     = module.rke.rke_cluster.client_cert
  client_key             = module.rke.rke_cluster.client_key
  cluster_ca_certificate = module.rke.rke_cluster.ca_crt
}

Recommended way needs two apply operations, and setting the proper terraform_remote_state data source :

provider "kubernetes" {
  host     = data.terraform_remote_state.rke.outputs.cluster.api_server_url
  username = data.terraform_remote_state.rke.outputs.cluster.kube_admin_user
  client_certificate     = data.terraform_remote_state.rke.outputs.cluster.client_cert
  client_key             = data.terraform_remote_state.rke.outputs.cluster.client_key
  cluster_ca_certificate = data.terraform_remote_state.rke.outputs.cluster.ca_crt
  load_config_file = "false"
}

terraform-openstack-rke's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

terraform-openstack-rke's Issues

Receiving errors

Hi, I'm trying to install RKE but I'm receiving some errors.

Openstack version: "Train"

terraform.tvars:

edge_count    = 1
worker_count  = 1
master_count = 1

master_labels = { "node-role.kubernetes.io/master" = "true" }
edge_labels   = { "node-role.kubernetes.io/edge" = "true" }
public_net_name = "provider"
master_flavor_name = "a.large"
worker_flavor_name = "a.large"
edge_flavor_name = "a.large"

cluster_name = "rke"
ssh_keypair_name = "local"
nodes_net_cidr = "10.13.0.0/24"
dns_servers = ["8.8.8.8"]
dns_domain = "arkan.cloud."

use_ssh_agent = false

image_name = "ubuntu-18.04-minimal-cloudimg-amd64"
user_data_file = "rancher.yml"
acme_email = "[email protected]"

rancher.yml

#cloud-config

ssh_authorized_keys:
    - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCYQykR9v8sGtHV0fl1Otm8N3nGFUYg8iO5IhODQO1zHtIAB8/px0JSu8g1EifbXzvx3GUUYDW2lNBbUYPOP1Os27M6lYz68qYKxMjLXraEHt9jNe7aUVIyNu2iGc3ZAgSrkRabw7P05ijLdH3A6MscQnc4tqLE92a3z/QGcANvtymJvpkvhuE3iUz92NxyR9AHaj9ejGbzJ2vu9kISVx2cUEvymW6x8zGh/agljsIXcp/KYUVr/MvpfVrdk7tUrLg3vAN5+273pWRGNTrtEdwhxBvSAYyU/p/C66G7ZHAILKj45rm0kpNqCNeQh2UiwmDbFEqQmtSZsEHKwRNCbdAx arkan@DESKTOP-8FQ42NL

packages:
    - docker.io

# create the docker group
groups:
    - docker

# Add default auto created user to docker group
system_info:
    default_user:
        groups: [docker]

Debug with Errors

conditional cloud provider

Some infrastructure dont play well with kubernetes integration. Make the openstack_cloud_provider conditionnal.

Octavia support

It would be great to support Octavia. We should then provision a LB for master HA and take advantage of Octavia Kubernetes cloud provider support.

Install fails because no docker engine is installed

I tested the script, but unfortunately the install fails, because no docker engine is installed. I tried with

wait_for_commands = [
"sudo apt update",
"sudo apt upgrade -y",
"sudo curl https://releases.rancher.com/install-docker/19.03.sh | sh"
]

but without any success, because the worker nodes have no direct internet connection. Only private IP. How do I do that?

On new installation get version conflict ..?

I keep getting:

Error: Failed to instantiate provider "rke" to obtain schema: Incompatible API version with plugin. Plugin version: 4, Client versions: [5]

What I've done:

  • upgrade terrafom to 1.12
  • Install terraform-provider-rke v1.0.0-rc4
  • terraform init
  • terraform plan -> this gives me the error above
$ tf providers
.
โ”œโ”€โ”€ provider.openstack
โ””โ”€โ”€ module.rke
    โ”œโ”€โ”€ module.edge
    โ”‚   โ”œโ”€โ”€ provider.null
    โ”‚   โ””โ”€โ”€ provider.openstack (inherited)
    โ”œโ”€โ”€ module.keypair
    โ”‚   โ””โ”€โ”€ provider.openstack (inherited)
    โ”œโ”€โ”€ module.master
    โ”‚   โ”œโ”€โ”€ provider.null
    โ”‚   โ””โ”€โ”€ provider.openstack (inherited)
    โ”œโ”€โ”€ module.network
    โ”‚   โ””โ”€โ”€ provider.openstack (inherited)
    โ”œโ”€โ”€ module.rke
    โ”‚   โ”œโ”€โ”€ provider.local
    โ”‚   โ”œโ”€โ”€ provider.null
    โ”‚   โ”œโ”€โ”€ provider.openstack
    โ”‚   โ””โ”€โ”€ provider.rke
    โ”œโ”€โ”€ module.secgroup
    โ”‚   โ””โ”€โ”€ provider.openstack (inherited)
    โ””โ”€โ”€ module.worker
        โ”œโ”€โ”€ provider.null
        โ””โ”€โ”€ provider.openstack (inherited)
$ tf version
tf version
Terraform v0.12.24
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.openstack v1.26.0
+ provider.rke v1.1
+ provider.rke v1.4

[bug] Error when enabling loadbalancer

Hello,
first of all let me thank you very much for sharing this awesome module!

I have a small issue when using the latest release of the module (0.6.0) and Terraform 0.14.2 when setting enable_loadbalancer to true.

The simplest way to demonstrate it is to start from the first example of the README, after sourcing my openrc file, terraform init then terraform apply.
The config is:

variable "os_auth_url" {}
variable "os_password" {}

module "rke" {
  source             = "remche/rke/openstack"
  image_name         = "ubuntu-20.04-docker-x86_64" #An actual image in my Openstack project
  public_net_name    = "public"
  master_flavor_name = "m1.small"
  worker_flavor_name = "m1.small"
  os_auth_url        = var.os_auth_url
  os_password        = var.os_password

  enable_loadbalancer = true
}

Will result in the following output:

Error: Unsupported attribute

  on .terraform/modules/rke/output.tf line 33, in output "loadbalancer_floating_ip":
  33:   value       = var.enable_loadbalancer ? module.loadbalancer.floating_ip : ""
    |----------------
    | module.loadbalancer is tuple with 1 element

This value does not have any attributes.

I have done some experiment on my own and the culprit seems to be the fact that the module loadbalancer is conditionally instantiated (through count = var.enable_loadbalancer ? 1 : 0) and that confuses somehow Terraform that doesn't recognize the output within the module.

Unfortunately I wasn't able to devise a reasonable fix to the issue, otherwise I would have opened a PR myself.

Do you have any idea on how we can workaround this problem? (for the time being I'm using the module from a local clone where I've removed the output :D )

Thank you!

add taint

add custom taints to nodes group.

fails when not using ssh-agent

When I set

  use_ssh_agent      = false
  ssh_keypair_name   = "thatcher" # existing key on openstack

The module fails with the error:

"rke" Failed initializing cluster err:Error while reading SSH key file: "file name too long", it also prints the full content of my RSA key. It is somehow trying to use the content of my SSH key as the filename.

setting the variable ssh_key_file doesn't seem to make a difference.

When I switched to using ssh-agent ssh-add, no arguments this error went away.

Code quality checks fail

Since recent terraform_quality_gate change, code-quality action fails.
dallinwright/terraform_quality_gate#5

use_ssh_agent

I was trying to make this Terraform module to work on, but I got a little confused about the use_ssh_agent. What exactly does it do?

The default is set to true, but that means you can't provide a private SSH key to access your newly provisioned nodes:

private_key = var.use_ssh_agent ? null : file(var.ssh_key_file)

I was only getting timeouts with the default value:

Error: timeout - last error: Error connecting to bastion: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

When setting the use_ssh_agent on false, I could get connection.

Adding a worker doesn't add a node in RKE cluster

This might be a bug in the RKE provider, however since I am not using that directly I figured it makes sense to report it here (first). Using the following config:

data "openstack_images_image_v2" "ubuntu" {
  name = "Ubuntu-18.04"
  most_recent = true
}

resource "openstack_compute_keypair_v2" "keypair" {
  name = "my-application-keypair-${var.environment}"
}

module "rke" {
  cluster_name       = "my-application-${var.environment}"
  source             = "remche/rke/openstack"
  version            = "0.5.4"
  image_name         = data.openstack_images_image_v2.ubuntu.name
  public_net_name    = "external"
  master_flavor_name = "m1.medium"
  worker_flavor_name = "m1.large"
  os_auth_url        = "https://myopenstackprovider.com:5000"
  os_password        = var.os_password
  edge_count         = 0
  worker_count       = 4
  master_count       = 1
  use_ssh_agent      = true
  ssh_keypair_name   = openstack_compute_keypair_v2.keypair.name
  master_labels      = { "node-role.kubernetes.io/master" = "true" }
  edge_labels        = { "node-role.kubernetes.io/edge" = "true" }
  user_data_file     = "cloud-init.yaml"
  system_user        = "ubuntu"
  nodes_config_drive = true
  deploy_traefik = true
  deploy_nginx = false
}

When I increase worker_count to 5 and do terraform apply -auto-approve, it spins up a new instance on my Openstack provider, however the instance does not register as a node with the RKE cluster that is already running on the existing instances. This used to be the case when I still used 0.4.2 of this provider, but is no longer the case with 0.5.4. I've tested on two separate existing clusters, both successfully create the new instance on Openstack but fail to recognize the new node. In both cases, the apply gets interrupted with:

time="2020-10-05T14:00:49+02:00" level=error msg="Failed to upgrade hosts: my-application-staging-worker-004 with error [Failed to verify healthcheck: Failed to check http://localhost:10248/healthz for service [kubelet] on host [192.168.42.42]: Get http://localhost:10248/healthz: Unable to access the service on localhost:10248. The service might be still starting up. Error: ssh: rejected: connect failed (Connection refused), log: F1005 12:00:45.096391   25275 server.go:274] failed to run Kubelet: could not init cloud provider \"openstack\": Authentication failed]"                                                                                                                                                                 

Failed running cluster err:[workerPlane] Failed to upgrade Worker Plane: [Failed to verify healthcheck: Failed to check http://localhost:10248/healthz for service [kubelet] on host [192.168.42.42]: Get http://localhost:10248/healthz: Unable to access the service on localhost:10248. The service might be still starting up. Error: ssh: rejected: connect failed (Connection refused), log: F1005 12:00:45.096391   25275 server.go:274] failed to run Kubelet: could not init cloud provider "openstack": Authentication failed]                                   
========================================                                                    

on .terraform/modules/rke/modules/rke/main.tf line 54, in resource "rke_cluster" "cluster":             
54: resource "rke_cluster" "cluster" {

However, in both cases just retrying terraform apply -auto-approve eventually results in Apply complete! Resources: 1 added, 0 changed, 0 destroyed..

Terraform v0.13.2
+ provider registry.terraform.io/hashicorp/local v1.4.0
+ provider registry.terraform.io/hashicorp/null v2.1.2
+ provider registry.terraform.io/rancher/rke v1.1.2
+ provider registry.terraform.io/terraform-provider-openstack/openstack v1.32.0
+ provider registry.terraform.io/terraform-providers/openstack v1.32.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.