Import Existing Cluster built on Harvester VM

Rancher allows you to import existing Harvester VMs in which you installed Kubernetes.

Deployment

Prerequisites

  • The Kubernetes cluster is built on top of Harvester VMs.

Deploy Guest Clusters on Harvester VMs

  1. Generate the csi-driver cloud-config file using the generate_addon_csi.sh script, which is available in the harvester/harvester-csi-driver repository.

    Example:

    1. ./generate_addon_csi.sh <serviceaccount name> <namespace> RKE2

    The generated output will be similar to the following one:

    1. ########## cloud-config ############
    2. apiVersion: v1
    3. clusters:
    4. - cluster: <token>
    5. server: https://<YOUR HOST HARVESTER VIP>:6443
    6. name: default
    7. contexts:
    8. - context:
    9. cluster: default
    10. namespace: default
    11. user: rke2-guest-01-default-default
    12. name: rke2-guest-01-default-default
    13. current-context: rke2-guest-01-default-default
    14. kind: Config
    15. preferences: {}
    16. users:
    17. - name: rke2-guest-01-default-default
    18. user:
    19. token: <token>
    20. ########## cloud-init user data ############
    21. write_files:
    22. - encoding: b64
    23. content: YXBpVmVyc2lvbjogdjEKY2x1c3RlcnM6Ci0gY2x1c3RlcjoKICAgIGNlcnRpZmljYXRlLWF1dGhvcml0eS1kYXRhOiBMUzB0TFMxQ1JVZEpUaUJEUlZKVVNVWkpRMEZVUlMwdExTMHRDazFKU1VKbFZFTkRRVklyWjBGM1NVSkJaMGxDUVVSQlMwSm5aM0ZvYTJwUFVGRlJSRUZxUVd0TlUwbDNTVUZaUkZaUlVVUkVRbXg1WVRKVmVVeFlUbXdLWTI1YWJHTnBNV3BaVlVGNFRtcG5NVTE2VlhoT1JGRjNUVUkwV0VSVVNYcE5SRlY1VDFSQk5VMVVRVEJOUm05WVJGUk5lazFFVlhsT2FrRTFUVlJCTUFwTlJtOTNTa1JGYVUxRFFVZEJNVlZGUVhkM1dtTnRkR3hOYVRGNldsaEtNbHBZU1hSWk1rWkJUVlJaTkU1VVRURk5WRkV3VFVSQ1drMUNUVWRDZVhGSENsTk5ORGxCWjBWSFEwTnhSMU5OTkRsQmQwVklRVEJKUVVKSmQzRmFZMDVTVjB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TzFEanllbWdvNG9OSEpzekp1VWliRGxxTVZiMS1oQUxYSjZXR1Z2RURxSTlna1JlSWtkX3JqS2tyY3lYaGhaN3lTZ3o3QQo=
    24. owner: root:root
    25. path: /var/lib/rancher/rke2/etc/config-files/cloud-provider-config
    26. permissions: '0644'
  2. Generate the cloud-provider cloud-config using the generate_addon.sh script, which is available in the harvester/cloud-provider-harvester repository.

    Example:

    1. ./generate_addon.sh <serviceaccount name> <namespace>

    The generated output will be similar to the following one: The output will look as follows:

    1. ########## cloud config ############
    2. apiVersion: v1
    3. clusters:
    4. - cluster:
    5. certificate-authority-data: <CACERT>
    6. server: https://HARVESTER-ENDPOINT/k8s/clusters/local
    7. name: local
    8. contexts:
    9. - context:
    10. cluster: local
    11. namespace: default
    12. user: harvester-cloud-provider-default-local
    13. name: harvester-cloud-provider-default-local
    14. current-context: harvester-cloud-provider-default-local
    15. kind: Config
    16. preferences: {}
    17. users:
    18. - name: harvester-cloud-provider-default-local
    19. user:
    20. token: <TOKEN>
    21. ########## cloud-init user data ############
    22. write_files:
    23. - encoding: b64
    24. content: <CONTENT>
    25. owner: root:root
    26. path: /etc/kubernetes/cloud-config
    27. permissions: '0644'
  3. Create VM with two cloud-config files.

    VM with cloud-config

  4. Install RKE2 in the VM.

    1. sudo mkdir -p /etc/rancher/rke2
    2. echo "cni: calico
    3. disable-kube-proxy: false
    4. etcd-expose-metrics: false" | sudo tee /etc/rancher/rke2/config.yaml
    5. curl -sfL https://get.rke2.io | sudo sh -
    6. sudo systemctl enable rke2-server.service
    7. sudo systemctl start rke2-server.service
  5. Verify that RKE2 is running in the VM.

    1. sudo /var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml get nodes
  6. Import the VM into Rancher.

    On the Rancher UI, go to Cluster Management > Clusters > Import Existing > Generic > Create.

    Import Exisging Cluster

    1. # Run the command in the VM
    2. curl --insecure -sfL https://192.168.0.181:6443/v3/import/g5p2g2gtxw4564nktdl4nr5cwwvtwqp9zxd6dmhm5nc7vpnxmr9cfk_c-m-mzf28skd.yaml | sudo /var/lib/rancher/rke2/bin/kubectl --kubeconfig /etc/rancher/rke2/rke2.yaml apply -f -
  7. Install the Harvester Cloud Provider.

    On the RKE2 Cluster Dashboard, go to Apps > Charts > Harvester Cloud Provider > Install.

  8. Install the Harvester CSI Driver.

    On the RKE2 Cluster Dashboard, go to Apps > Charts > Harvester CSI Driver > Install.