Create Google Cloud Virtual Machine from PHP - google-cloud-platform

I'm new in cloud environment (Google Cloud)..
Currently I have more than 10 different products of php application software.
I have website where users can register and create their own subdomain name...
Every time users register on my website, I create the VM manually and point the subdomain to the VM manually...
When users registering on my website is increasing, it become very hard to manually add the VM and point the DNS one-by-one
What in my mind is can we automate the process? if possible how to do that?
What is the best method for this?I heard about container and kubernetes...
all information, help and suggestion is appreciated...thank you

you can use code as infrastructure like terraform is there.
you can run terraform php.
Refer more about it here : https://github.com/aol/terraform-php
Where you can set everything and it will also spin up VM behalf of you known as code as infra.

Related

What is correct way to deploy single tenant app on GCP?

we have an application with FastApi backend, next.js frontend, postgresql database and cloud storage. There is possibility that in future we will add some new service to this.
For CI/CD we are using github with github actions.
Our goal is to deploy instance per client (organization), so they will be isolated, and each will have its own subdomain like client1.ourdomain.com, client2.ourdomain.com etc.
We are using Google Cloud Platform. What would be best way to deploy and manage it later?
In future we will be creating an app to manage our clients, will it be possible to turn off, or create those environments from app?
For development purpose we have virtual machine on gcp with docker-compose to run all this.
I thought about using cloud run for fastapi, cloud run for nextjs, postgres on gcp and google cloud storage. Is it correct approach?
Please be aware that your question is not easy to answer, because your are talking about how to handle tenancy.
A good tenancy management depends on your requirements, and the way you want to evolve and maintain your software does have big impact on that.
According to the few information you shared, organizing your clients by projects looks the way you want. That way allows you to isolate your client's resources (including accounts/billing and so on) by implementing the right IAM policies.
Also, your can later deploy a dedicated "admin" project to manage the others from an admin app.
If you have manly programming/developer skills in your team, I would suggest to talk to a GCP architect/engineer to figure out what's the right architecture to create, and to adopt a IAC approach to create your client's projects and deploys so that your app is easy to replicate and maintain across clients.

GCP API - How could you determine that a VM was created via Marketplace?

I'm trying to make an API call in Python (inside a Cloud Function) to do some various things and as part of the information I'd like to pass along is whether the VM was created from something in the Marketplace.
The use case is this: The user is in the GCP Console in Compute Engine. They click on Marketplace in the left column of the display which then brings up VMs to choose from. The user picks one (say "Ubuntu 20.4 LTS (Focal)"). The display shows information about the VM with a "Launch" button. When they click that, they are then taken to the "Create an instance" page and they continue making choices and eventually create the VM.
This creates a log entry that the client's security group checks inside of a cloud function. When I look at the log entry for beta.compute.instances.insert, I don't see anything about it being created via Marketplace. If I make an API call to get the instance, there's nothing in the object returned that shows that either. Anyone know of any way to determine this?
It depends on what you mean by "via Marketplace". In general, the Marketplace offer is usually a Deployment Manager template and an image in a public project (public projects are available only to partners publishing to Marketplace). So if you deploy a Marketplace VM solution you will have:
a VM with source image in some project outside your org; but this will also match VMs created manually using that image (does it match your "via Marketplace" definition?) and VMs created from custom images your individual users have access to. Hint: your service account assigned to function will also have access to all public images, but usually not to images shared between users.
Deployment Manager deployment - that's a nice one as such deployments have some marketplace-specific labels. The problem is that deployment metadata can be deleted without deleting the deployed resources. And there's the case you mentioned with some marketplace listings being just redirections to deploying a single VM.
I'm afraid there's no way to detect if an Ubuntu VM was deployed after visiting Marketplace, or after clicking add VM button or using CLI or terraform - for the GCE it was simply an API call to insert a new instance.

Set hostname in container for CloudRun

I want the hostname in my Managed CloudRun service to be MyServiceName.RevisionName.InstanceId or anything better than "localhost" which I am getting now.
Is this possible ?
Cloud Run is a serverless managed compute platform, meaning that it is precisely built to abstract away all the infrastructure management. The container instances on which Cloud Run services run are ephemeral, meaning that your Cloud Run services will not be mapped to a specific static instance ID. Setting the hostname as you describe on your question will not be possible.
Depending on the nature of the application you can follow one of two possible ways:
Follow one of the suggestions already given on the comments (generate and save an UUID as a variable to the running container's scope so it can serve as an identifier during the container's lifespan). Which I assume would be the best workaround given the simplicity of creating UUIDs. Here are some examples on how to generate UUIDs programatically using Python, JavaScript, and C# given by the Stackoverflow community.
Migrate the container application from Cloud Run services to a Compute Engine VM instance with a custom hostname.
The metadata server provides some attributes to uniquely identify your service instance and correlate it to logs and other information sources.
See cloud run specific attributes and the [metadata server docs](https://cloud.google.com/compute/docs/storing-retrieving-metadata]

Website with Google cloud compute

Total NOOB question. I want to setup a website on google cloud compute platform with:
static IP/IP range(external API requirement)
simple front-end
average to low traffic with a maximum of few thousand requests a
day.
separate database instance.
I went through the documentation of services offered Google and Amazon. Not fully sure what is the best way to go about it. Understand that there is no right answer.
A viable solution is:
Spawn up an n1-standard instance on GCP (I prefer to use Debian)
Get a static IP, which is free if you don't let it dangling.
Depending upon your DB type choose Cloud SQL for structured data or Cloud Datastore for unstructured data
Nginx is a viable option for web-server. Get started here
Rest is upon you. What kind of stack are you using to build your app? How are you gonna deploy your code to instance? You might later wanna use Docker and k8s to get flexibility between cloud providers and scaling needs.
The easiest way of creating the website you want would be Google App Engine with the Datastore as DB. However it doesn't support static IP's, this is due to a design choice. Is this absolutely mandatory?
App Engine does not currently provide a way to map static IP addresses
to an application. In order to optimize the network path between an
end user and an App Engine application, end users on different ISPs or
geographic locations might use different IP addresses to access the
same App Engine application. DNS might return different IP addresses
to access App Engine over time or from different network locations.

Create Basic Landing Page to allow a user to start/stop an AWS Windows EC2 instance

I would like to create a landing page using Beanstalk/EC2 (beanstalk for PHP or .NET) that is a simple HTML landing page with a Start and Stop button, allowing a non-technical person to spin start/stop a specific AWS EC2 instance (Windows Server 2012) in the same VPC.
Is it possible for me to start/stop the separate EC2 Windows instance from my beanstalk web app?
Would I need to setup anything specifically on the EC2 Windows instance to enable this to work?
Would I need to setup anything special on the Beanstalk instance to enable what I've described to work?
Thanks again for any pointers anyone can provide.
Is it possible for me to start/stop the separate EC2 Windows instance from my beanstalk web app? Yes
Would I need to setup anything specifically on the EC2 Windows instance to enable this to work? No
Would I need to setup anything special on the Beanstalk instance to enable what I've described to work? No
So how do you achieve this?
1. If you wanted a frontend GUI, you could use nodeJS. This is a good resource for that: https://aws.amazon.com/sdk-for-browser/
2. Your backend will have AWS CLI installed and handle all the API calls. This is a good resource for that: https://aws.amazon.com/cli/
3. You can always automate a pipeline structure using Jenkins and the many AWS plugins. So say you want to give the user parameters to select from without building anything fancy. Jenkins will do this for you with the AWS plugin and the parameter plugin.
So there are many ways to handle this. To decide which works best for you make sure you have the business requirements well defined and then maybe setup an agile like structure were you have an epic and user stories.
Hope that helped. Happy hacking!!!