You can use the Tanzu Kubernetes Grid CLI to create YAML files for Tanzu Kubernetes clusters without actually creating the clusters. If you are experienced with creating and editing YAML files to use for deploying Kubernetes clusters, you can modify the generated YAML files to customize your clusters.

To generate a YAML file for a cluster configuration, run the tkg config cluster command with the same options as you would specify when running tkg create cluster. For more information about the tkg create cluster options, see Create Tanzu Kubernetes Clusters.

For example, the following command uses all of the possible tkg config cluster options, including identifying the namespace in which to run the cluster.

tkg config cluster my-cluster --plan=dev --controlplane-machine-count 3 --worker-machine-count 10 --namespace=my_namespace

If you are satisfied with the displayed configuration file, run the tkg create cluster command with the same options, to create the cluster.

tkg create cluster my-cluster --plan=dev --controlplane-machine-count 3 --worker-machine-count 10

NOTE: Running the tkg config cluster command works in the same way as specifying --dry-run option with tkg create cluster. For more information about the --dry-run option, see Preview the YAML for a Tanzu Kubernetes Cluster.

Deploy a Cluster from a Saved YAML File

When you run tkg config cluster, Tanzu Kubernetes Grid sends the YAML file for the cluster to stdout, so that you can save it for repeated future use.

To deploy a cluster from a saved YAML file, you must use kubectl rather than the Tanzu Kubernetes Grid CLI. When you use kubectl to deploy a cluster from a saved YAML file, the post-creation steps to automatically enable Calico in the cluster are not run. Consequently, there are additional steps that you must perform manually, to enable Calico networking in the cluster.

  1. Run tkg config cluster to create a cluster configuration and save it to a YAML file.

    tkg config cluster my-cluster --plan=dev --controlplane-machine-count 3 --worker-machine-count 10 > my-cluster.yaml

  2. Use a tool such as yq to extract the Calico YAML information from the generated configuration file, and save it as a new YAML file.

    cat my-cluster.yaml | yq r -d7 - stringData.calicoYaml > postcreation_steps.yaml

  3. Make sure that kubectl is set to the context of the management cluster on which you ran tkg config cluster.

    kubectl config use-context my-mgmt-cluster-admin@my-mgmt-cluster   

  4. Use kubectl apply to deploy the Tanzu Kubernetes cluster from the YAML that you generated with tkg config cluster.

    kubectl apply -f my-cluster.yaml

  5. When the cluster is ready, set kubectl to the context of the newly created cluster.

    kubectl config use-context my-cluster-admin@my-cluster

  6. Run kubectl apply on the YAML that you created with yq, to enable Calico in the cluster.

    kubectl apply -f postcreation_steps.yaml
    

The Tanzu Kubernetes cluster is running, and Calico is enabled in the cluster.

check-circle-line exclamation-circle-line close-line
Scroll to top icon