check-circle-line exclamation-circle-line close-line

<

You can use Tanzu Kubernetes Grid to deploy multiple management clusters from the same bootstrap environment, to both vSphere and Amazon EC2.

You can manage all of the management clusters from the same Tanzu Kubernetes Grid CLI instance, and switch between the contexts of the different management clusters by using the tkg set management-cluster command. By default, all context information about your management clusters is stored in a file named .kube-tkg/config on the machine on which you run the Tanzu Kubernetes Grid CLI.

You can use the tkg add management-cluster command to add management clusters that someone else created from a different machine, so that you can manage those clusters from your Tanzu Kubernetes Grid CLI instance.

Prerequisites

You have deployed at least two management clusters, to either vSphere or Amazon EC2, or both.

List Management Clusters and Change Context

  1. On the bootstrap environment machine on which you ran tkg init, run the tkg get management-cluster command to see the list of management clusters that you have deployed.

    tkg get management-cluster
    

    If you deployed two management clusters, named my-vsphere-mgmt-cluster and my-aws-mgmt-cluster, you will see the following output:

    MANAGEMENT-CLUSTER-NAME     CONTEXT-NAME                                    
    my-vsphere-mgmt-cluster *   my-vsphere-mgmt-cluster-admin@my-vsphere-mgmt-cluster
    my-aws-mgmt-cluster         my-aws-mgmt-cluster-admin@my-aws-mgmt-cluster
    

    The management cluster that is the current context of the Tanzu Kubernetes Grid CLI is marked with an asterisk (*). By default, the Tanzu Kubernetes Grid CLI and kubectl contexts are automatically set to the management cluster that you deployed most recently.

  2. To show the details of a specific management cluster, run tkg get management-cluster with the --name option.

    tkg get management-cluster --name my-aws-mgmt-cluster
    
    MANAGEMENT-CLUSTER-NAME     CONTEXT-NAME                                    
    my-aws-mgmt-cluster         my-aws-mgmt-cluster-admin@my-aws-mgmt-cluster
    
  3. To change the context of the Tanzu Kubernetes Grid CLI to a different management cluster, run the tkg set management-cluster command.

    tkg set management-cluster my-aws-mgmt-cluster
    

Add Existing Management Clusters to Your Tanzu Kubernetes Grid CLI Instance

To add a management cluster that someone else created to your list of managed management clusters, use the tkg add management-cluster command.

  1. Obtain the .kube-tkg/config of the management cluster that you want to add, and save it on your bootstrap environment.

    IMPORTANT: If you are likely to share a management cluster with other users, it is strongly recommended to run tkg init with the --kubeconfig option when you deploy that management cluster. This saves the kubeconfig for the management cluster in a separate file, rather than in the default .kube-tkg/config file. This allows you to share individual management clusters more easily.

  2. Set an environment variable to point to the kubeconfig of the new management cluster.

    export KUBECONFIG=~/<path>/mgmt-cluster.kubeconfig
    
  3. Set the context of kubectl to the new management cluster.

    kubectl config use-context mgmt-cluster-admin@mgmt-cluster
    
  4. Add the new cluster to your Tanzu Kubernetes Grid instance.

    tkg add management-cluster
    

    The tkg add management-cluster automatically adds the current kubeconfig to your .kube-tkg/config file. Alternatively, you can specify tkg add management-cluster with the --kubeconfig option, to add a kubeconfig that is not the current one to your .kube-tkg/config file.

    tkg add management-cluster --kubeconfig <path>/mgmt-cluster.kubeconfig
    
  5. Run tkg get management-cluster to see the newly added cluster in your list of management clusters.
  6. Set the context of the Tanzu Kubernetes Grid CLI to the new cluster.

    tkg set management-cluster new-cluster
    

Export Management Cluster Details to a File

You can export the details of your management clusters in either JSON or YAML format. You can save the JSON or YAML to a file so that you can use it in scripts to run bulk operations on management clusters.

  1. To export cluster details as JSON, run tkg get management-cluster with the --output option, specifying json.

    tkg get management-cluster --output json
    

    The output shows the management cluster information as JSON:

    [
        {
          "name": "my-aws-mgmt-cluster",
          "context": "my-aws-mgmt-cluster-admin@my-aws-mgmt-cluster",
          "file": "/root/.kube/config",
          "isCurrentContext": false
        },
        {
          "name": "my-vsphere-mgmt-cluster",
          "context": "my-vsphere-mgmt-cluster-admin@my-vsphere-mgmt-cluster",
          "file": "/root/.kube-tkg/config",
          "isCurrentContext": true
        }
    ]
    
  2. To export management cluster details as YAML, run tkg get management-cluster with the --output option, specifying yaml.

    tkg get management-cluster --output yaml
    

    The output shows the management cluster information as YAML:

    - name: my-aws-mgmt-cluster
      context: my-aws-mgmt-cluster-admin@my-aws-mgmt-cluster
      file: /root/.kube/config
      isCurrentContext: false
    - name: my-vsphere-mgmt-cluster
      context: my-vsphere-mgmt-cluster-admin@my-vsphere-mgmt-cluster
      file: /root/.kube-tkg/config
      isCurrentContext: true
    
  3. Save the output as a file.

    tkg get management-cluster --output json > clusters.json
    
    tkg get management-cluster --output yaml > clusters.yaml
    

Scale Management Clusters

After you deploy a management cluster, you can scale it up or down by increasing or reducing the number of node VMs that it contains. To scale a management cluster, use the tkg scale cluster command. You change the number of management cluster control plane nodes by specifying the --controlplane-machine-count option. You change the number of management cluster worker nodes by specifying the --worker-machine-count option. Because management clusters run in the tkg-system namespace rather than the default namespace, you must also specify the --namespace option when you scale a management cluster.

  1. Run tkg set management-cluster before you run tkg scale cluster, to make sure that the management cluster to scale is the current context of the Tanzu Kubernetes Grid CLI.
  2. To scale a production management cluster that you originally deployed with 3 control plane nodes and 5 worker nodes to 5 and 10 nodes respectively, run the following command:

    tkg scale cluster management_cluster_name --controlplane-machine-count 5 --worker-machine-count 10 --namespace tkg-system

If you initially deployed a development management cluster with one control plane node and you scale it up to 3 control plane nodes, Tanzu Kubernetes Grid automatically enables stacked HA on the control plane.

IMPORTANT: Do not change context or edit the .kube-tkg/config file while Tanzu Kubernetes Grid operations are running.

What to Do Next

You can use Tanzu Kubernetes Grid to start deploying Tanzu Kubernetes clusters to different Tanzu Kubernetes Grid instances. For information, see Deploying Tanzu Kubernetes Clusters and Managing their Lifecycle.

If you have vSphere 7.0, you can also deploy and manage Tanzu Kubernetes clusters in vSphere with Kubernetes. For information, see Use the Tanzu Kubernetes Grid CLI with a vSphere with Kubernetes Supervisor Cluster .