Top 10 Tanzu CLI Handy Commands

Tanzu CLI is a command-line utility that helps to interact with Tanzu Kubernetes Clusters. This is not a replacement of kubectl, this is complimentary. I have found tanzu cli very useful when working with TKGm clusters provisioning and lifecycle management. 
VMware provides multiple plugins for Tanzu cli to perform different operations, You can use below command to validate the installed plugins.

Tanzu plugins

Here are some of the handy commands that i think you will need either during building the TKGm Clusters or their lifecycle management.

Top 10 Tanzu Commands

Below commands will work for TKGm clusters. for vSphere with Tanzu, mostly kubectl is used and i will write a separate post.

  1. Create Tanzu Management Cluster using UI and CLI
Launch an interactive UI to create management cluster
$ tanzu management-cluster create --ui
Create management cluster using configuration file
$ tanzu management-cluster create --file <location of cluster config file>

2. View the list of management clusters

$ tanzu management-cluster get
tanzu management cluster detail

3. Login to Tanzu Management Cluster. By default, it picks up the cluster from default kubeconfig file. You can specify different options with login command.

$ tanzu login
? Select a server [Use arrows to move, type to filter]
> tkg-cluster-mgmt ()
+ new server
For more options, run tanzu login --help

4. Create Tanzu Workload Clusters

Options while creating workload cluster
$ tanzu cluster create --help

Create a cluster
tanzu cluster create CLUSTER_NAME [flags]
-d, --dry-run Does not create cluster, but show the deployment YAML instead
-f, --file string Configuration file from which to create a cluster
-h, --help help for create
--tkr string TanzuKubernetesRelease(TKR) to be used for creating the workload cluster
Global Flags:
--log-file string Log file path
-v, --verbose int32 Number for the log level verbosity(0-9)
Here is the simple command you can run to create cluster
$ tanzu cluster create --file <workload cluster config file path>

5. List Tanzu workload clusters

$ tanzu cluster list
tkg-cluster-wk01 default running 3/3 6/6 v1.20.5+vmware.1 <none> prod
tkg-cluster-wk02 default running 3/3 3/3 v1.20.5+vmware.1 <none> prod

If you have deployed workload clusters on different namespaces and want to filter one those, run below command

$ tanzu cluster list — namespace default

6. Scaling worker nodes in a Tanzu workload cluster

$ tanzu cluster scale <Cluster name> -w <number of nodes you want to scale up or down>
After running above command, you can monitor the scaling on VCenter as well as you can run tanzu cluster list command.

7. Upgrading workload cluster: You may need to upgrade k8s version on workload cluster and provide required version for application testing.

$ tanzu cluster upgrade <cluster-name>

In case you want to upgrade to specific release version, first run the below command and see the available releases.

$ kubectl get tkr
v1.17.16---vmware.2-tkg.1 v1.17.16+vmware.2-tkg.1 False 30d
v1.17.16---vmware.2-tkg.2 v1.17.16+vmware.2-tkg.2 False 30d
v1.17.16---vmware.3-tkg.1 v1.17.16+vmware.3-tkg.1 True 30d
v1.18.16---vmware.1-tkg.1 v1.18.16+vmware.1-tkg.1 False 30d
v1.18.16---vmware.1-tkg.2 v1.18.16+vmware.1-tkg.2 False 30d
v1.18.16---vmware.3-tkg.1 v1.18.16+vmware.3-tkg.1 True 30d
v1.18.17---vmware.1-tkg.1 v1.18.17+vmware.1-tkg.1 False 30d
v1.18.17---vmware.2-tkg.1 v1.18.17+vmware.2-tkg.1 True 30d
v1.19.8---vmware.1-tkg.1 v1.19.8+vmware.1-tkg.1 False 30d
v1.19.8---vmware.1-tkg.2 v1.19.8+vmware.1-tkg.2 False 30d
v1.19.8---vmware.3-tkg.1 v1.19.8+vmware.3-tkg.1 True 30d
v1.19.9---vmware.1-tkg.1 v1.19.9+vmware.1-tkg.1 False 30d
v1.19.9---vmware.2-tkg.1 v1.19.9+vmware.2-tkg.1 True 30d
v1.20.4---vmware.1-tkg.1 v1.20.4+vmware.1-tkg.1 False 30d
v1.20.4---vmware.1-tkg.2 v1.20.4+vmware.1-tkg.2 False 30d
v1.20.4---vmware.3-tkg.1 v1.20.4+vmware.3-tkg.1 True 30d
v1.20.5---vmware.1-tkg.1 v1.20.5+vmware.1-tkg.1 False 30d
v1.20.5---vmware.2-fips.1-tkg.1 v1.20.5+vmware.2-fips.1-tkg.1 False 4d13h
v1.20.5---vmware.2-tkg.1 v1.20.5+vmware.2-tkg.1 True 30d
You can choose one of the compatible release name.
for more detail, run below command:
$ tanzu cluster upgrade --help

8. Export admin kubeconfig file and access management cluster from other system

$ tanzu management-cluster kubeconfig get --export-file <location where you want to store the file> --admin
$ tanzu management-cluster kubeconfig get --admin --export-file /tmp/mgmt_cluster_admin_kubeconfig

9. Register Tanzu management cluster with Tanzu Mission Control (TMC)

$ tanzu management-cluster register --tmc-registration-url "TMC-REGISTRATION-URL"
You can get TMC registration URL from TMC console and replace here.

10. Finally, Deleting Tanzu Clusters

Delete Tanzu workload cluster
$ tanzu cluster delete <cluster-name> --namespace=<namespace where cluster is deployed>
If, your cluster is on default namespace, you can ignore --namespace parameter.
Delete Tanzu management cluster
$ tanzu management-cluster delete
In case, you want to force the management-cluster deployment, use --force

Based on my experience, i have been using above commands frequently, But, there are many more commands that you can find them here:

Thanks for your time here, Will come with many more informational posts on Tanzu portfolio.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s