Register, Attach Kubernetes cluster in TMC using CLI

Reading Time: 3 mins

VMware Tanzu Mission Control is a centralised management platform for consistently operating and securing your Kubernetes infrastructure and modern applications across multiple teams and clouds. In this post, you will explore on attaching a kubernetes clusters (TKG deployed on Azure) into TMC using TMC CLI.

Generate API token from TMC Console

Follow the below steps to get API Token from TMC console

  • Token Name: Provide your name followed by demo
  • Define Scopes: All Roles

Note: Copy the token and save it for later use

Install TMC CLI

# Install jq

sudo apt install jq -y

# Install TMC

sudo curl -L -o /usr/local/bin/tmc $(curl -s https://tanzupaorg.tmc.cloud.vmware.com/v1alpha/system/binaries | jq -r 'getpath(["versions",.latestVersion]).linuxX64')

# Change permissions

sudo chmod 755 /usr/local/bin/tmc
## Authenticate to TMC

tmc login -n capv-demo --no-configure

# Provide API Token

# Login context name(leave to default) - Press Enter

## Configure:

tmc system context configure -l "log" -m capv-mgmt

## List the available management cluster

tmc managementcluster list

Register management cluster using TMC CLI

  •    Create Cluster group with name as capv-demo-cg
tmc clustergroup create --name capv-demo-cg --description "Demo of TMC CLI"
  • List the cluster groups and verify if the created capv-demo-cg is shown in the list
tmc clustergroup list
  • Register the management cluster (created in previous section) capv-mgmt into TMC
tmc managementcluster register capv-mgmt -k ~/.kube/config -p TKG -c capv-demo-cg

Wait for the registration to complete, ETA: 2 mins

  •  List the management clusters and verify if registered management cluster capv-mgmt is shown in the list
tmc managementcluster list

# Check resources in vmware-system-tmc namespace, Don’t worry if some pods are in creating state, it generally takes few minutes to complete.

kubectl get all -n vmware-system-tmc

# It takes few mins to turn healthy

tmc managementcluster get capv-mgmt
  • Check in TMC Console to know the status of management cluster

In TMC Console: Navigate to TMC console > Administration > Management clusters > click on capv-mgmt

 

Attach workload cluster using TMC CLI

  • Get credentials and export the config file
tanzu cluster kubeconfig get capv-workload --admin --export-file ~/.kube/config-tkg

# Read the kubeconfig file

cat ~/.kube/config-tkg

# Verify the context of workload cluster

kubectl config get-contexts --kubeconfig /home/azureuser/.kube/config-tkg

# Check the nodes in workload cluster

kubectl get nodes -A --kubeconfig /home/azureuser/.kube/config-tkg

# Check the pods in workload cluster

kubectl get pods -A --kubeconfig /home/azureuser/.kube/config-tkg
  • Attach the workload cluster capv-workload using TMC CLI, wait for the process to complete.
tmc cluster attach -g capv-demo-cg -n capv-workload -m capv-mgmt -p TKG --kubeconfig ~/.kube/config-tkg
  • Check in TMC Console to know the status of attached workload cluster.

In TMC Console: Navigate to TMC console > Clusters > click on clustername: capv-workload

Validate the workload cluster

tmc cluster validate --kubeconfig ~/.kube/config-tkg