How to use CLI for Managed instance groups ?
We have been using the cloud console to manage the managed instance groups. Let us now learn how to use the command line interface to manage the instance groups. It is important to note that we need to set the project id before we can execute any of these commands mentioned below. Else, you will receive an error. You can use the below command to set the project id.
gcloud config set project <project name>
gcloud compute instance-groups managed list // This will list the managed instance group list
gcloud compute instance-groups managed create <instance group name> --zone <zone name> --template <instance template name> --size <number of virtual machines in instance group> //This will create a new instance group using the specified instance template
gcloud compute instance-groups managed list // This will display the list of managed instance groups in the project.
You can also set autoscaling for the group by using the below command.
gcloud compute instance-groups managed set-autoscaling <instance group name> --max-num-replicas=<number // This lets us set autoscaling
You can also other options that can be set for autoscaling such as on/off/only scale out etc…
Similarly, you can resize the instance group or replace the instance in a group using the below command.
gcloud compute instance-groups managed resize <instance group name> --size =<new size> //this will resize the existing group.
gcloud compute instance-groups managed recreate-instances <instance group name> --instances=<instance name> // This will replace the existing instance with a new one
gloud compute instance-groups managed update-instances <instance group name> --instances=<instance name>