Skip to content

Terraform provider plugin for deploy kubernetes cluster by RKE(Rancher Kubernetes Engine)

License

Notifications You must be signed in to change notification settings

rancher/terraform-provider-rke

Repository files navigation

terraform-provider-rke

Go Report Card Build Status

Terraform RKE providers can easily deploy Kubernetes clusters with Rancher Kubernetes Engine.

Compatible Versions

  • Terraform: v0.11+
  • RKE: v0.1.8 (Kubernetes 1.8, 1.9 and 1.10)

Installation

Usage

Target Node Requirements

It is same as the requirements of RKE.

Examples

Minimal example

resource rke_cluster "cluster" {
  nodes = [
    {
      address = "1.2.3.4"
      user    = "rancher"
      role    = ["controlplane", "worker", "etcd"]
    },
  ]
}

###############################################################################
# If you need kubeconfig.yml for using kubectl, please uncomment follows.
###############################################################################
//resource "local_file" "kube_cluster_yaml" {
//  filename = "${path.root}/kube_config_cluster.yml"
//  content = "${rke_cluster.cluster.kube_config_yaml}"
//}

###############################################################################
# If you need cluster.yml for using rke, please uncomment follows.
###############################################################################
//resource "local_file" "rke_cluster_yaml" {
//  filename = "${path.root}/cluster.yml"
//  content = "${rke_cluster.cluster.rke_cluster_yaml}"
//}

###############################################################################
# You can also use an output.
###############################################################################
// output "rke_cluster_yaml" {
//  sensitive = true
//  value = "${rke_cluster.cluster.rke_cluster_yaml}"
//}
  • default k8s version: v1.10.3-rancher2
  • default network plugin: canal

Dynamic multiple nodes example

variable "node_addrs" {
  type    = "list"
  default = ["192.2.0.1", "192.2.0.2"]
}

data rke_node_parameter "nodes" {
  count   = "${length(var.node_addrs)}"

  address = "${var.node_addrs[count.index]}"
  user    = "ubuntu"
  role    = ["controlplane", "worker", "etcd"]
  ssh_key = "${file("~/.ssh/id_rsa")}"
}

resource rke_cluster "cluster" {
  nodes_conf = ["${data.rke_node_parameter.nodes.*.json}"]
}

###############################################################################
# If you need kubeconfig.yml for using kubectl, please uncomment follows.
###############################################################################
//resource "local_file" "kube_cluster_yaml" {
//  filename = "${path.root}/kube_config_cluster.yml"
//  content = "${rke_cluster.cluster.kube_config_yaml}"
//}

With cloud provider

With Kubernetes provider

You can use RKE provider and Kubernetes provider together.

resource rke_cluster "cluster" {
  nodes = [
    {
      address = "1.2.3.4"
      user    = "ubuntu"
      role    = ["controlplane", "worker", "etcd"]
      ssh_key = "${file("~/.ssh/id_rsa")}"
    },
  ]
}

provider "kubernetes" {
  host     = "${rke_cluster.cluster.api_server_url}"
  username = "${rke_cluster.cluster.kube_admin_user}"

  client_certificate     = "${rke_cluster.cluster.client_cert}"
  client_key             = "${rke_cluster.cluster.client_key}"
  cluster_ca_certificate = "${rke_cluster.cluster.ca_crt}"
  # load_config_file = false
}

resource "kubernetes_namespace" "example" {
  metadata {
    name = "terraform-example-namespace"
  }
}

Deploying Rancher 2.0 using terraform-provider-rke

You can view examples to deploying Rancher 2.0

Full example

You can view full example of tffile, here.

License

terraform-provider-rke Copyright (C) 2018 Kazumichi Yamamoto.

This project is published under Apache 2.0 License.

Author

About

Terraform provider plugin for deploy kubernetes cluster by RKE(Rancher Kubernetes Engine)

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages