Terraform RKE providers can easily deploy Kubernetes clusters with Rancher Kubernetes Engine.
- Terraform: v0.11+(includes v0.12)
- RKE: v0.2.8
Current master is focusing on RKE v0.2.x. If you use RKE v0.1.x, please see rke/v0.1.x branch.
- Install Terraform v0.11+(includes v0.12)
- Add the
terraform-provider-rke
plugin binary In~/.terraform.d/plugins/
Note: Following examples are compatible with Terraform v0.12.
It is same as the requirements of RKE.
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 = format("%s/%s" , 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 = format("%s/%s", 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.14.6-rancher1-1
- default network plugin:
canal
variable "nodes" {
type = list(object({
address = string,
user = string,
}))
default = [
{
address = "192.2.0.1"
user = "ubuntu"
},
{
address = "192.2.0.2"
user = "ubuntu"
},
]
}
resource rke_cluster "cluster" {
dynamic nodes {
for_each = var.nodes
content {
address = nodes.value.address
user = nodes.value.user
role = ["controlplane", "worker", "etcd"]
ssh_key = file("~/.ssh/id_rsa")
}
}
}
###############################################################################
# If you need kubeconfig.yml for using kubectl, please uncomment follows.
###############################################################################
//resource "local_file" "kube_cluster_yaml" {
// filename = format("%s/%s" , path.root, "kube_config_cluster.yml")
// content = rke_cluster.cluster.kube_config_yaml
//}
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"
}
}
You can view examples to deploying Rancher 2.0
You can view full example of tffile, here.
terraform-provider-rke
Copyright (C) 2018-2019 Kazumichi Yamamoto.
This project is published under Apache 2.0 License.
- Kazumichi Yamamoto (@yamamoto-febc)