How to delete orphan NSX-T objects using PKS cleanup script
search cancel

How to delete orphan NSX-T objects using PKS cleanup script

book

Article ID: 298726

calendar_today

Updated On:

Products

VMware Tanzu Kubernetes Grid Integrated Edition

Issue/Introduction

You may need to run the pks_cleanup script if either of the following situations occur: 
 

  • The pks delete-cluster operation fails to remove all cluster objects.
  • A cluster deployment fails and you need to delete NSX-T objects that were created during the failed deployment. 


Environment

Product Version: 1.1
OS: Ubuntu

Resolution

Installing the Cleanup Script 

Run the following commands to download the script, make it executable, and rename it: 

wget https://storage.googleapis.com/pks-releases/pks_cleanup_linux 
sudo chmod +x pks_cleanup_linux 
sudo mv pks_cleanup_linux /usr/local/bin/pks_cleanup 

To verify installation, run pks_cleanup --help 


Expected Results:

Cleanup script examples 

The following example commands demonstrate how to use the pks_cleanup script to delete NSX-T resources for a sample cluster. The sample cluster is for illustrative purposes only. Your cluster details and UUIDs will be different. 


Let's assume we have a PKS cluster identified as k81s with the following details: 

ubuntu@ubuntu:~$ pks cluster k8s1 

Name: k8s1 
Plan Name: Plan 1 
UUID: 18ef47d8-d4ac-4d6c-9d77-301860c3a98f 
Last Action: CREATE 
Last Action State: succeeded 
Last Action Description: Instance provisioning failed 
Kubernetes Master Host: k8s1 
Kubernetes Master Port: 8443 
Worker Nodes: 1 
Kubernetes Master IP(s): 192.168.150.100 

The --cluster flag accepts the format pks-[cluster UUID]. For this example, the --cluster value is pks-18ef47d8- d4ac-4d6c-9d77-301860c3a98f

To view the resources created by NCP that will be removed, run the following command: 

 
  • pks_cleanup --mgr-ip=192.168.111.46 --cluster=pks-18ef47d8-d4ac-4d6c-9d77-301860c3a98f 

To delete all resources created by NCP, run the following command: 

 
  • pks_cleanup --mgr-ip=192.168.111.46 --cluster=pks-18ef47d8-d4ac-4d6c-9d77-301860c3a98f -r=false 

To delete NSX-T resources created by both NCP and PKS, run the following command: 

 
  • pks_cleanup --mgr-ip=192.168.111.46 --cluster=pks-18ef47d8-d4ac-4d6c-9d77-301860c3a98f -r=false --pks --floating-ip-pool-id=5a35b05c-70d4-4337-9f8e-b8b8533476c7 --ip-block-id=d5aab712-4b83- 4690-a16f-f6a3583c9056 


Options:

Cleanup scripts command usage

The following table displays pks_cleanup [flags]:

Flags 

Input 

Description 

-t, --ca-cert 

String 

NSX-T ca certificate 

-c, --cluster 

String 

Name of the target cluster in the format pks-[cluster UUID] 

--floating-ip-pool-id 

String 

UUID of the floating IP pool configured for the cluster 

-h, --help 

String 

Help for the script 

--ip-block-id 

String 

UUID of the IP block configured for the cluster 

-m, --mgr-ip 

String 

NSX-T Manager IP address 

-n, --nsx-cert 

String 

NSX certificate path 

-k, --nsx-key 

String 

NSX client private key path 

-p, --password 

String 

NSX Manager password; ignored if nsx-cert is set 

--pks 

N/A 

Removes NSX-T resources created by PKS Requires floating-ip-pool-id and ip-block-id 

-r, --read-only 

boolean 

Read only mode (default true) 

-u, --username 

String 

NSX Manager username (default "admin"); ignored if nsx-cert is set 

 

Cleanup Script Details 

The pks_cleanup script flags are categorized as follows: 
 

  • Environmental parameters 
  • Authentication parameters 
  • PKS parameters 
  • Deletion parameters 

Environmental Parameters 

--cluster pks-[cluster UUID] 


The --cluster input parameter is the cluster identifier which must be in the format pks-[cluster UUID]


--mgr-ip [nsx-t manager ip] 

The IP address of the NSX-T Manager host. 


Authentication Parameters 

--username (default is “admin”) 


--password (default is “Admin!23Admin”) 


To authenticate with the NSX-T Manager using basic authentication, provide the flags ---username  and --password. You must supply valid authentication credentials if different from the default. 


--nsx-cert /path/to/client/cert 


--nsx-key /path/to/client/key 


To authenticate with NSX-T Manager using a client certificate, provide the paths to both the client certificate and key using the flags --nsx-cert and --nsx-key


--ca-cert /path/to/ca/cert 


To enable server certificate validation, provide the path to a valid CA certificate in --ca-cert


PKS Parameters 

By default, the pks_cleanup script only deletes NSX-T resources created by NCP. If you also want to delete NSX-T resources created by PKS (such as the load balancer for the cluster master VMs), provide the --pks flag. 


The --pks flag requires both the --floating-ip-pool-id and --ip-block-id flags. Each expects the UUID of the corresponding resource. 


Deletion Parameters 

By default the pks_cleanup script is read-only. This means that when you run the script it simply prints to stdout the resources to be deleted—it does not actually delete them. To delete the resources, you must pass the --read-only=false (or -r=false) flag. Note that the equals sign without spaces is required.