Home > front end >  How to type "for" command control structure in gcloud CLI?
How to type "for" command control structure in gcloud CLI?

Time:01-07

I read book "2021 - Apress - Kubernetes" (page 4)

enter image description here

enter image description here

(for i in 0 1; ){ do gcloud compute instances create worker-${i} --async --boot-disk-size 200GB --can-ip-forward --image-family ubuntu-2004-lts --image-project ubuntu-os-cloud --machine-type n1-standard-1 --private-network-ip 10.240.0.2${i} --scopes compute-rw,storage-ro,service-management,servicecontrol,logging-write,monitoring --subnet kubernetes;} done

I catch error


C:\Program Files (x86)\Google\Cloud SDK>(for i in 0 1; ){ do gcloud compute instances create worker-${i} --async --boot-disk-size 200GB --can-ip-forward --image-family ubuntu-2004-lts --image-project ubuntu-os-cloud --machine-type n1-standard-1 --private-network-ip 10.240.0.2${i} --scopes compute-rw,storage-ro,service-management,servicecontrol,logging-write,monitoring --subnet kubernetes;} done
i was unexpected at this time.

C:\Program Files (x86)\Google\Cloud SDK>

How to type and run the command success? I want one line command (for easy for copy and paste, not multiple lines command)

CodePudding user response:

It is as others mentioned, the difference between *nix commands and Windows.

Something equivalent to this in PowerShell would be:

foreach ($i in 1,2) {
  gcloud compute instances create worker-$i --async --boot-disk-size 200GB --can-ip-forward --image-family ubuntu-2004-lts --image-project ubuntu-os-cloud --machine-type n1-standard-1 --private-network-ip 10.240.0.2$i --scopes compute-rw,storage-ro,service-management,servicecontrol,logging-write,monitoring --subnet kubernetes
}

If you want to follow on with the Linux based examples in the book you can make sure you have Docker running on your Windows machine, install WSL 2 (windows subsystem for linux), and finally run a gcloud-sdk docker image based on a linux distribution.

e.g. docker run --rm -it gcr.io/google.com/cloudsdktool/cloud-sdk:slim

CodePudding user response:

I've not tried this but you should be able to use the Windows' shell's for command instead. You'll want:

for %i in (0 1) do gcloud compute instances create ...

And you'll need to replace occurrences of ${i} with %i

  •  Tags:  
  • Related