rancher / terraform-provider-rke

Terraform provider plugin for deploy kubernetes cluster by RKE(Rancher Kubernetes Engine)
Mozilla Public License 2.0
340 stars 151 forks source link

bump Go to 1.20 and RKE to v1.5.7 to support k8s 1.28 #451

Closed jiaqiluo closed 6 months ago

jiaqiluo commented 6 months ago

Issue:

https://github.com/rancher/terraform-provider-rke/issues/447

Problem

We would like to support k8s 1.28

Solution

Bump the RKE module to v1.5.7 and Go to 1.20 to match the version used in RKE( see the go.mod file in RKE v1.5.7)

Note: those replaces directives are there to get rid of the "unknown revision v0.0.0" error caused by the k8s.io/kubernetes module. (upstream Issue: https://github.com/kubernetes/kubernetes/issues/79384)

Testing

By using the binary compiled from the branch, I could create a 3-node RKE1 cluster with k8s v1.28.7-rancher1-1 successfully.

Below is the sample Terraform configuration I used:

# main.tf

terraform {
  required_providers {
    rke = {
      source = "rancher/rke"
      version = "1.4.4"  # overridden by global configuration, local binary is used instead
    }
  }
}

# Configure the RKE provider
provider "rke" {
  debug = true
  log_file = "./logfile.txt"
}
resource rke_cluster "cluster" {
  enable_cri_dockerd = "true"
  kubernetes_version = "v1.28.7-rancher1-1"
  nodes {
    address = ""
    internal_address = ""
    user    = "ubuntu"
    role    = ["controlplane"]
    ssh_key = file("")
  }
  nodes {
    address = ""
    internal_address = ""
    user    = "ubuntu"
    role    = ["etcd"]
    ssh_key = file("")
  }
  nodes {
    address = ""
    internal_address = ""
    user    = "ubuntu"
    role    = ["worker"]
    ssh_key = file("")
  }
}

resource "local_file" "kube_cluster_yaml" {
  filename = "${path.root}/kube_config_cluster.yml"
  content  = rke_cluster.cluster.kube_config_yaml
}

The cluster:

> export KUBECONFIG=./kube_config_cluster.yml; k get node 
NAME            STATUS   ROLES          AGE   VERSION
3.101.36.30     Ready    etcd           12m   v1.28.7
54.219.67.206   Ready    worker         12m   v1.28.7
54.67.104.53    Ready    controlplane   12m   v1.28.7

>  k version                                             
Client Version: v1.29.3
Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3
Server Version: v1.28.7

> k get pods -A          
NAMESPACE       NAME                                      READY   STATUS      RESTARTS   AGE
ingress-nginx   ingress-nginx-admission-create-vxmzh      0/1     Completed   0          12m
ingress-nginx   ingress-nginx-admission-patch-xcb6q       0/1     Completed   1          12m
ingress-nginx   nginx-ingress-controller-4wn7x            1/1     Running     0          12m
kube-system     calico-kube-controllers-5b564d9b7-m4bmg   1/1     Running     0          13m
kube-system     canal-hjnjv                               2/2     Running     0          13m
kube-system     canal-ppxj8                               2/2     Running     0          13m
kube-system     canal-tp4c6                               2/2     Running     0          13m
kube-system     coredns-6477d9c45-xmtfb                   1/1     Running     0          13m
kube-system     coredns-autoscaler-bd6b85b4c-rsnmv        1/1     Running     0          13m
kube-system     metrics-server-657c74b5d8-m6mgg           1/1     Running     0          12m
kube-system     rke-coredns-addon-deploy-job-zgpts        0/1     Completed   0          13m
kube-system     rke-ingress-controller-deploy-job-tqfcn   0/1     Completed   0          12m
kube-system     rke-metrics-addon-deploy-job-v4brw        0/1     Completed   0          12m
kube-system     rke-network-plugin-deploy-job-pb9nc       0/1     Completed   0          13m