You can unassign a static external IP address by deleting the instance or deleting the access config attached to the instance that is using the address. Unassigning an IP address removes it from the resource but keeps the IP address reserved to your project.
To delete an instance's access config and unassign a static external IP address, follow these steps:
-
Get the name of the access config to delete. To get the name, perform a gcloud compute instances describe request:
gcloud compute instances describe [INSTANCE_NAME]
where [INSTANCE_NAME] is the name of the instance.
The access config appears in the following format:
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: external-nat
natIP: 130.211.181.55
type: ONE_TO_ONE_NAT
-
Delete the access config.
Use the instances delete-access-config sub-command:
gcloud compute instances delete-access-config [INSTANCE_NAME] \
--access-config-name "[ACCESS_CONFIG_NAME]"
where:
-
Check that your static external IP address is now available and marked as RESERVED instead of IN_USE.
gcloud compute addresses list
For example:
NAME REGION ADDRESS STATUS
example-address [REGION] 130.211.160.207 RESERVED
example-address-new [REGION] 130.211.114.137 RESERVED
-
Now that your static external IP address is available, you can choose to assign it to another instance.
Hope this helped!!
To know more about Google Cloud, It is recommended to go for Google Cloud Certification training today.
Thank you!