Set hostname in container for CloudRun - google-cloud-platform

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]

Related

Can we run an application that is configured to run on multi-node AWS EC2 K8s cluster using kops into local kubernetes cluster (using kubeadm)?

Can we run an application that is configured to run on multi-node AWS EC2 K8s cluster using kops (project link) into local Kubernetes cluster (setup using kubeadm)?
My thinking is that if the application runs in k8s cluster based on AWS EC2 instances, it should also run in local k8s cluster as well. I am trying it locally for testing purposes.
Heres what I have tried so far but it is not working.
First I set up my local 2-node cluster using kubeadm
Then I modified the installation script of the project (link given above) by removing all the references to EC2 (as I am using local machines) and kops (particularly in their create_cluster.py script) state.
I have modified their application yaml files (app requirements) to meet my localsetup (2-node)
Unfortunately, although most of the application pods are created and in running state, some other application pods are unable to create and therefore, I am not being able to run the whole application on my local cluster.
I appreciate your help.
It is the beauty of Docker and Kubernetes. It helps to keep your development environment to match production. For simple applications, written without custom resources, you can deploy the same workload to any cluster running on any cloud provider.
However, the ability to deploy the same workload to different clusters depends on some factors, like,
How you manage authorization and authentication in your cluster? for example, IAM, IRSA..
Are you using any cloud native custom resources - ex, AWS ALBs used as LoadBalancer Services
Are you using any cloud native storage - ex, your pods rely on EFS/EBS volumes
Is your application cloud agonistic - ex using native technologies like Neptune
Can you mock cloud technologies in your local - ex. Using local stack to mock Kinesis, Dynamo
How you resolve DNS routes - ex, Say you are using RDS n AWS. You can access it using a route53 entry. In local you might be running a mysql instance and you need a DNS mechanism to discover that instance.
I did a google search and looked at the documentation of kOps. I could not find any info about how to deploy to local, and it only supports public cloud providers.
IMO, you need to figure out a way to set up your local EKS cluster, and if there are any usage of cloud native technologies, you need to figure out an alternative way about doing the same in your local.
The true answer, as Rajan Panneer Selvam said in his response, is that it depends, but I'd like to expand somewhat on his answer by saying that your application should run on any K8S cluster given that it provides the services that the application consumes. What you're doing is considered good practice to ensure that your application is portable, which is always a factor in non-trivial applications where simply upgrading a downstream service could be considered a change of environment/platform requiring portability (platform-independence).
To help you achieve this, you should be developing a 12-Factor Application (12-FA) or one of its more up-to-date derivatives (12-FA is getting a little dated now and many variations have been suggested, but mostly they're all good).
For example, if your application uses a database then it should use DB independent SQL or no-sql so that you can switch it out. In production, you may run on Oracle, but in your local environment you may use MySQL: your application should not care. The credentials and connection string should be passed to the application via the usual K8S techniques of secrets and config-maps to help you achieve this. And all logging should be sent to stdout (and stderr) so that you can use a log-shipping agent to send the logs somewhere more useful than a local filesystem.
If you run your app locally then you have to provide a surrogate for every 'platform' service that is provided in production, and this may mean switching out major components of what you consider to be your application but this is ok, it is meant to happen. You provide a platform that provides services to your application-layer. Switching from EC2 to local may mean reconfiguring the ingress controller to work without the ELB, or it may mean configuring kubernetes secrets to use local-storage for dev creds rather than AWS KMS. It may mean reconfiguring your persistent volume classes to use local storage rather than EBS. All of this is expected and right.
What you should not have to do is start editing microservices to work in the new environment. If you find yourself doing that then the application has made a factoring and layering error. Platform services should be provided to a set of microservices that use them, the microservices should not be aware of the implementation details of these services.
Of course, it is possible that you have some non-portable code in your system, for example, you may be using some Oracle-specific PL/SQL that can't be run elsewhere. This code should be extracted to config files and equivalents provided for each database you wish to run on. This isn't always possible, in which case you should abstract as much as possible into isolated services and you'll have to reimplement only those services on each new platform, which could still be time-consuming, but ultimately worth the effort for most non-trival systems.

Create Google Cloud Virtual Machine from PHP

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.

Custom DNS resolver for Google Cloud Dataflow pipeline

I am trying to access Kafka and 3rd-party services (e.g., InfluxDB) running in GKE, from a Dataflow pipeline.
I have a DNS server for service discovery, also running in GKE. I also have a route in my network to access the GKE IP range from Dataflow instances, and this is working fine. I can manually nslookup from the Dataflow instances using my custom server without issues.
However, I cannot find a proper way to set up an additional DNS server when running my Dataflow pipeline. How could I achieve that, so that KafkaIO and similar sources/writers can resolve hostnames against my custom DNS?
sun.net.spi.nameservice.nameservers is tricky to use, because it must be called very early on, before the name service is statically instantiated. I would call java -D, but Dataflow is going to run the code itself directly.
In addition, I would not want to just replace the systems resolvers but merely append a new one to the GCP project-specific resolvers that the instance comes pre-configured with.
Finally, I have not found any way to use a startup script like for a regular GCE instance with the Dataflow instances.
I can't think of a way today of specifying a custom DNS in a VM other than editing /etc/resolv.conf[1] file in the box. I don't know if it is possible to share the default network. If it is machines are available at hostName.c.[PROJECT_ID].internal, which may serve your purpose if hostName is stable [2].
[1] https://cloud.google.com/compute/docs/networking#internal_dns_and_resolvconf [2] https://cloud.google.com/compute/docs/networking

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.

Communication between instances in Cloud Foundry

Is there a possibility to communicate between multiple instances of an application deployed to Cloud Foundry?
I checked the Cloud Foundry API but I couldn't find any mention of this subject.
I already tried Hazelcast but unfortunately, my Cloud Foundry provider doesn't support Multicasting, so I would have to know the IP addresses of every other instance in order to connect.
I think I can't be the only one interested in this.
I recommend you use a messaging service (like RabbitMQ) to communicate between instances of applications. You can also store shared information in a database service or any remote location outside the file system.
It is generally not a good practice to build applications that require this type of communication in the cloud. Each instance should ideally be able to run independently and be stateless.
If you can programmatically access the ip addresses, you can build up the Hazelcast Config object and use that to setup your cluster. You can then rely on tcp-ip discovery.
pseudo code:
List<String> ipAddresses = cloudfoundry.getIps()
Config config = new Config();
config.getJoinConfig().getIpDiscovery().addMembers(ipAddresses)
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
You can even load your existing Hazelcast XML configuration and enhance it on the fly using the XmlConfigBuilder.
There might be occasions where the instances need to communicate amongst themselves instead of using an external component to gain efficiency or avoid dependency. One possibility is to use gorouter itself with specific instance id in http with below header.
X-Cf-App-Instance=app-uuid:instanceno-integer
Other option which I am yet to explore is explained in this link
https://ict.swisscom.ch/2018/05/container-networking-with-cloud-foundry/