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

<

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, and setting the sizes of the nodes.

tkg config cluster my-cluster --plan dev --controlplane-machine-count 3 --worker-machine-count 10 --namespace my_namespace --controlplane-size large --worker-size extra-large

NOTE: The options to set the size of the nodes, as well as the general --size option, are available in Tanzu Kubernetes Grid 1.1.2 and later.

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 --namespace my_namespace --controlplane-size large --worker-size extra-large

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 or tkg create cluster with the --dry-run option, Tanzu Kubernetes Grid sends the YAML file for the cluster to stdout, so that you can save it for repeated future use.

Tanzu Kubernetes Grid 1.1.2 and Later

In Tanzu Kubernetes Grid 1.1.2 and later, you can use the tkg create cluster command with the --manifest option to deploy a cluster from the saved YAML file.

  1. Run tkg config cluster or tkg create cluster with the --dry-run option to create a cluster configuration and save it to a YAML file.

    tkg config cluster manifest-test --plan dev --controlplane-machine-count 3 --worker-machine-count 10 > manifest-test.yaml
    
    tkg create cluster manifest-test --plan dev --controlplane-machine-count 3 --worker-machine-count 10 --dry-run > manifest-test.yaml
    
  2. To deploy a cluster from the saved YAML file, run tkg create cluster with the --manifest option.

    If you specify the --manifest option, no other options are required, as the configuration is taken from the YAML file.

    tkg create cluster manifest-test --manifest manifest-test.yaml
    

Tanzu Kubernetes Grid 1.1.0

In Tanzu Kubernetes Grid 1.1.0, 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.

    yq r -d'*' my-cluster.yaml stringData.calicoYaml > postcreation_steps.yaml

  3. Make sure that kubectl is set to 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 available, set kubectl to 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.