How to add TKGM management and workload clusters to TMC using tmc CLI
+++ author = "Shubham Sharma" title = "How to add TKGM management and workload clusters to TMC using tmc CLI" menuTitle = "How to add TKGM management and workload clusters to TMC using tmc CLI" date = "2022-08-17" description = "How to add TKGM management and workload clusters to TMC using tmc CLI" series = ["TMC"] codeMaxLines = 15 +++
In this post, we will cover how to register a TKG management cluster using tmc
CLI. Once the management cluster is registered we will add the workload cluster present in this setup as a managed cluster to TMC. To install and set up the tmc
CLI check out this post.
Environment Information¶
- TKG v1.6.0
- Management cluster -
uoom-mgmt-rp06
- Workload Cluster -
wuoom-wld-rp06
tanzu version
version: v0.25.0
buildDate: 2022-08-25
sha: 6288c751-dirty
tanzu cluster list --include-management-cluster
NAME NAMESPACE STATUS CONTROLPLANE WORKERS KUBERNETES ROLES PLAN TKR
wuoom-wld-rp06 default running 1/1 2/2 v1.23.8+vmware.2 <none> dev v1.23.8---vmware.2-tkg.1
uoom-mgmt-rp06 tkg-system running 1/1 1/1 v1.23.8+vmware.2 management dev v1.23.8---vmware.2-tkg.1
Registering management cluster¶
Login to TMC¶
export TMC_CONTEXT_NAME="tmc-ctx"
export TMC_API_TOKEN=<CSP token>
tmc login --no-configure --name "${TMC_CONTEXT_NAME}"
Identify or create cluster group¶
- Identify the cluster group where you want to categorize this management cluster using
tmc clustergroup list
- Alternatively, you can create a new cluster group
Register management cluster¶
Registering the management cluster requires the following arguments
- Management cluster name -
${MANAGEMENT_CLUSTER_NAME}
- Cluster group name -
${CLUSTER_GROUP}
- Path to kubeconfig -
"${HOME}"/.kube/config
- Provisioner name -
TKG
export MANAGEMENT_CLUSTER_NAME='uoom-mgmt-rp06'
export CLUSTER_GROUP='oom-group'
tmc managementcluster register "${MANAGEMENT_CLUSTER_NAME}" -c "${CLUSTER_GROUP}" --kubeconfig "${HOME}"/.kube/config -p TKG -v 4
Output of the above execution¶
tmc managementcluster register "${MANAGEMENT_CLUSTER_NAME}" -c "${CLUSTER_GROUP}" --kubeconfig "${HOME}"/.kube/config -p TKG -v 4
√ management cluster "uoom-mgmt-rp06" created successfully
i applying registration link on the management cluster
┤ √ TMC resources applied to the cluster successfully
└ √ management cluster registered to TMC
Verifying health and status¶
- To check if the management cluster registered successfully and the health of the management cluster
tmc managementcluster get "${MANAGEMENT_CLUSTER_NAME}" --output json | jq .status.conditions
{
"READY": {
"type": "READY",
"status": "TRUE",
"severity": "INFO",
"reason": "phase: READY, health: HEALTHY",
"message": "management cluster is connected to TMC and healthy"
}
}
Adding workload cluster as a managed cluster¶
After registering the management cluster if we query it for workload clusters we don't get any data back. The reason is that the workload cluster in this environment is neither managed nor attached to TMC.
The tmc
CLI provides an easy way to achieve this. To add the workload cluster as a managed cluster you just need the following info
- Management Cluster name
- Provisioner name - This is the namespace under which your workload cluster is present. Ex -
-p default
- Cluster group
- Workload cluster name
export MANAGEMENT_CLUSTER_NAME='uoom-mgmt-rp06'
export CLUSTER_GROUP='oom-group'
export WORKLOAD_CLUSTER_NAME='wuoom-wld-rp06'
tmc managementcluster provisioner tanzukubernetescluster manage -m "${MANAGEMENT_CLUSTER_NAME}" -p default --cluster-group "${CLUSTER_GROUP}" "${WORKLOAD_CLUSTER_NAME}" -v 4
Successful completion of the above command results in √ wuoom-wld-rp06 will be managed by tanzu mission control
message.
Now the cluster is visible within TMC
tmc cluster list --management-cluster-name "${MANAGEMENT_CLUSTER_NAME}"
NAME MANAGEMENTCLUSTER PROVISIONER LABELS
wuoom-wld-rp06 uoom-mgmt-rp06 default tmc.cloud.vmware.com/creator:sharmashubh
Verifying the workload cluster health¶
tmc cluster get "${WORKLOAD_CLUSTER_NAME}" --management-cluster-name "${MANAGEMENT_CLUSTER_NAME}" -p default -o json | jq .status.conditions
{
"Agent-READY": {
"type": "READY",
"status": "TRUE",
"severity": "INFO",
"reason": "phase: COMPLETE, health: HEALTHY",
"message": "cluster is connected to TMC and healthy"
},
"WCM-Ready": {
"type": "Ready",
"status": "TRUE",
"severity": "INFO"
},
"WCM-VersionIsLatest": {
"type": "VersionIsLatest",
"status": "TRUE",
"severity": "INFO"
}
}