Printing IPs from running VM instances in Google Cloud - list

i am writing a script that helps me to extract external IPs from running instances in Google cloud.
For this purpose im using the "list" command
gcloud compute instances list
How can I print the external IPs from all running instances?
Thanks!
Seb

Related

Vertex AI Managed Notebook, get subnet/IP

How can I find IP for vertex AI managed notebook instance? The service is differing from user managed notebooks in certain sense. The creation of an instance doesn't create a compute instance, so it's all managed by itself.
My purpose is to whitelist the set of IPs in Mongo atlas. Set of IPs being of all the notebooks in that region. I'm using google-managed networks in this case.
I've a few doubts here:
Since within managed nb, I can change CPU consumption, will this reinstantiate a new cluster, with entirely new IP, or it will be 1 from among a group of IPs?
Is it possible to add a custom init script?
If you want to connect to a database service on GCP, create a network (or use the default) and instantiate the notebook using this network (Advanced options) and create the white list for this entire network . It's required because the managed notebook creates a peering network on the network you will use, you can check you in VPC Network ➞ VPC Network Peering.
If you want an external IP, it will not work. Google managed notebooks does not use external ips, they basically access the internet via NAT gateways (does not matter if you use google or own managed networks) so you will not be able to do what you want. Move for user managed notebooks (where you can assign a fixed external ip) or white list any IP on your Mongo db service if you are not in a production environment.
About yous doubts:
Since within managed nb, I can change CPU consumption, will this instantiate a new cluster, with entirely new IP, or it will be 1 from among a group of IPs
For the internal network it may change when you restart or recreate the notebook instance. For an external network, it does not exists and explained.
Is it possible to add a custom init script?
Basically not. But you can provide custom docker images for the notebook.

Connect Google Cloud Run with Google Compute Engine or GKE

Is there a way to connect Google Cloud Run with a service running in a Compute Engine instance in an specific port?
With Google Cloud Run I want to run a WebApp that needs to connect with a service running in Compute Engine or Google Kubernetes Engine. It's that possible?
Thanks in advance!
Yep, this is possible. You need to create a VPC Serverless connector and use it to connect to the internal IPs of the VMs in GCE or any resource in the VPC.

Re-Allocate Elastic IP to Compute Engine for Google Cloud

I'm seeing that AWS EC2 can be achieved this objective by using a profile and script attaches to the Launch Configuration or Launch Template.
AWS EC2 User Data script to allocate Elastic IP
I'm curious if anybody try to do this on Google Cloud yet ?
If so, please share.
Thanks

google cloud connectl local computer to network

Is there a way to connect a local computer to google cloud network?
I have a server building ios apps on a mac mini, and would like to be able to call/make builds from google cloud VM - and copy files from local/on prem. to Google Cloud VM.
You can reach your goal in a few ways:
Enable ssh access to your mac mini to run commands remotely on it and use on of the options described in the documentation Transferring files to instances
to transfer files between cloud and premises.
Enable ssh access to your mac mini to run commands remotely and use cloud storage bucket mounted with Cloud Storage FUSE to the VM instance to upload/downlowad files between cloud and premises.
Use Google Cloud VPN to connect your on-premises network to the cloud.
In case of GKE cluster, you can find cluster CIDR range which contains IPs of Pods with the command:
gcloud container clusters describe my-cluster | grep clusterIpv4Cidr
to use it while configuring VPN.

Can not connect between Cloud Run and Compute engine using Internal IP

I have a service which runs on Cloud Run, and a MYSQL, MongoDB databases on Compute Engine. Currently, I'm using public IP for connect between them, I want to use internal IP for improving performance, but i cant find solution for this problem, Please help me some ideas, Thanks.
Now is supported. You can use VPC network connector (Beta):
This feature is in a pre-release state and might change or have
limited support. For more information, see the product launch stages.
This page shows how to use Serverless VPC Access to connect a Cloud
Run (fully managed) service directly to your VPC network, allowing
access to Compute Engine VM instances, Memorystore instances, and any
other resources with an internal IP address.
To use Serverless VPC Access in a Cloud Run (fully managed) service,
you first need to create a Serverless VPC Access connector to handle
communication to your VPC network. After you create the connector, you
set your Cloud Run (fully managed) service configuration to use that
connector.
Here how to create: Creating a Serverless VPC Access connector and here an overview about it: Serverless VPC Access example
According to official documentation Connecting to instances using advanced methods
If you have an isolated instance that doesn't have an external IP
address (such as an instance that is intentionally isolated from
external networks), you can still connect to it by using its internal
IP address on a Google Cloud Virtual Private Cloud (VPC) network
However, if you check the services not yet supported for Cloud Run, you will find:
Virtual Private Cloud Cloud Run (fully managed) cannot connect to VPC
network.
Services not yet supported
You can now do that by running this command upon deployment:
gcloud run deploy SERVICE --image gcr.io/PROJECT_ID/IMAGE --vpc-connector CONNECTOR_NAME
If you already have a Cloud Run deployment, you can update it by running the command:
cloud run services update SERVICE --vpc-connector CONNECTOR_NAME
More information about that here
Connecting from Cloud Run Managed to VPC private addresses is not yet supported.
This feature is in development and is called Serverless VPC Access. You can read more here.
If you have a Compute Engine instance running in the same VPC with a public IP address, you can create an SSH tunnel to connect to private IP addresses through the public instance. This requires creating the tunnel in your own code, which is easy to do.