Import a Google GKE Cluster

This tutorial demonstrates how to import a GKE cluster through the direct connection method. If you want to use the agent connection method, refer to Agent Connection.

Prerequisites

  • You have a Kubernetes cluster with KubeSphere installed, and prepared this cluster as the host cluster. For more information about how to prepare a host cluster, refer to Prepare a host cluster.
  • You have a GKE cluster to be used as the member cluster.

Import a GKE Cluster

Step 1: Deploy KubeSphere on your GKE cluster

You need to deploy KubeSphere on your GKE cluster first. For more information about how to deploy KubeSphere on GKE, refer to Deploy KubeSphere on GKE.

Step 2: Prepare the GKE member cluster

  1. To manage the member cluster from the host cluster, you need to make jwtSecret the same between them. Therefore, get it first by executing the following command on your host cluster.

    1. kubectl -n kubesphere-system get cm kubesphere-config -o yaml | grep -v "apiVersion" | grep jwtSecret

    The output is similar to the following:

    1. jwtSecret: "QVguGh7qnURywHn2od9IiOX6X8f8wK8g"
  2. Log in to the KubeSphere console on GKE as admin. Click Platform in the upper-left corner and then select Cluster Management.

  3. Go to CRDs, enter ClusterConfiguration in the search bar, and then press Enter on your keyboard. Click ClusterConfiguration to go to its detail page.

  4. Click Import a Google GKE Cluster - 图1 on the right and then select Edit YAML to edit ks-installer.

  5. In the YAML file of ks-installer, change the value of jwtSecret to the corresponding value shown above and set the value of clusterRole to member.

    1. authentication:
    2. jwtSecret: QVguGh7qnURywHn2od9IiOX6X8f8wK8g
    1. multicluster:
    2. clusterRole: member

    Note

    Make sure you use the value of your own jwtSecret. You need to wait for a while so that the changes can take effect.

Step 3: Create a new kubeconfig file

  1. Run the following commands on your GKE Cloud Shell Terminal:

    1. TOKEN=$(kubectl -n kubesphere-system get secret $(kubectl -n kubesphere-system get sa kubesphere -o jsonpath='{.secrets[0].name}') -o jsonpath='{.data.token}' | base64 -d)
    2. kubectl config set-credentials kubesphere --token=${TOKEN}
    3. kubectl config set-context --current --user=kubesphere
  2. Retrieve the new kubeconfig file by running the following command:

    1. cat ~/.kube/config

    The output is similar to the following:

    1. apiVersion: v1
    2. clusters:
    3. - cluster:
    4. certificate-authority-data: L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lyMHZsKy9WZjYrCitBanVNNFoyOURtVXFHVC80OHBaR1RoaDlsZDQxUGZKNjl4eXFvME1wUlIyYmJuTTRCL2NVT1VlTE5VMlV4VWUKSGRlYk1oQUp4Qy9Uaks2SHpmeExkTVdzbzVSeVAydWZEOFZob2ZaQnlBVWczajdrTFgyRGNPd1lzNXNrenZ0LwpuVUlhQURLaXhtcFlSSWJ6MUxjQmVHbWROZ21iZ0hTa3MrYUxUTE5NdDhDQTBnSExhMER6ODhYR1psSi80VmJzCjNaWVVXMVExY01IUHd5NnAwV2kwQkpQeXNaV3hZdFJyV3JFWUhZNVZIanZhUG90S3J4Y2NQMUlrNGJzVU1ZZ0wKaTdSaHlYdmJHc0pKK1lNc3hmalU5bm5XYVhLdXM5ZHl0WG1kRGw1R0hNU3VOeTdKYjIwcU5RQkxhWHFkVmY0PQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
    5. server: https://130.211.231.87
    6. name: gke_grand-icon-307205_us-central1-c_cluster-3
    7. contexts:
    8. - context:
    9. cluster: gke_grand-icon-307205_us-central1-c_cluster-3
    10. user: gke_grand-icon-307205_us-central1-c_cluster-3
    11. name: gke_grand-icon-307205_us-central1-c_cluster-3
    12. current-context: gke_grand-icon-307205_us-central1-c_cluster-3
    13. kind: Config
    14. preferences: {}
    15. users:
    16. - name: gke_grand-icon-307205_us-central1-c_cluster-3
    17. user:
    18. auth-provider:
    19. config:
    20. cmd-args: config config-helper --format=json
    21. cmd-path: /usr/lib/google-cloud-sdk/bin/gcloud
    22. expiry-key: '{.credential.token_expiry}'
    23. token-key: '{.credential.access_token}'
    24. name: gcp
    25. - name: kubesphere
    26. user:
    27. token: eyJhbGciOiJSUzI1NiIsImtpZCI6InNjOFpIb3RrY3U3bGNRSV9NWV8tSlJzUHJ4Y2xnMDZpY3hhc1BoVy0xTGsifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJrdWJlc3BoZXJlLXN5c3RlbSIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VjcmV0Lm5hbWUiOiJrdWJlc3BoZXJlLXRva2VuLXpocmJ3Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6Imt1YmVzcGhlcmUiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC51aWQiOiIyMGFmZGI1Ny01MTBkLTRjZDgtYTAwYS1hNDQzYTViNGM0M2MiLCJzdWIiOiJzeXN0ZW06c2VydmljZWFjY291bnQ6a3ViZXNwaGVyZS1zeXN0ZW06a3ViZXNwaGVyZSJ9.ic6LaS5rEQ4tXt_lwp7U_C8rioweP-ZdDjlIZq91GOw9d6s5htqSMQfTeVlwTl2Bv04w3M3_pCkvRzMD0lHg3mkhhhP_4VU0LIo4XeYWKvWRoPR2kymLyskAB2Khg29qIPh5ipsOmGL9VOzD52O2eLtt_c6tn-vUDmI_Zw985zH3DHwUYhppGM8uNovHawr8nwZoem27XtxqyBkqXGDD38WANizyvnPBI845YqfYPY5PINPYc9bQBFfgCovqMZajwwhcvPqS6IpG1Qv8TX2lpuJIK0LLjiKaHoATGvHLHdAZxe_zgAC2cT_9Ars3HIN4vzaSX0f-xP--AcRgKVSY9g

Step 4: Import the GKE member cluster

  1. Log in to the KubeSphere console on your host cluster as admin. Click Platform in the upper-left corner and then select Cluster Management. On the Cluster Management page, click Add Cluster.

  2. Enter the basic information based on your needs and click Next.

  3. In Connection Method, select Direct connection. Fill in the new kubeconfig file of the GKE member cluster and then click Create.

  4. Wait for cluster initialization to finish.