copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2021-09-13 |
application, deploy app, deploy app multiple regions, multiple regions, custom domain name, domain name, TLS, load-balancer, Cloud Internet Services |
codeengine |
{:DomainName: data-hd-keyref="APPDomain"} {:DomainName: data-hd-keyref="DomainName"} {:android: data-hd-operatingsystem="android"} {:api: .ph data-hd-interface='api'} {:apikey: data-credential-placeholder='apikey'} {:app_key: data-hd-keyref="app_key"} {:app_name: data-hd-keyref="app_name"} {:app_secret: data-hd-keyref="app_secret"} {:app_url: data-hd-keyref="app_url"} {:audio: .audio} {:authenticated-content: .authenticated-content} {:beta: .beta} {:c#: .ph data-hd-programlang='c#'} {:c#: data-hd-programlang="c#"} {:cli: .ph data-hd-interface='cli'} {:codeblock: .codeblock} {:curl: #curl .ph data-hd-programlang='curl'} {:curl: .ph data-hd-programlang='curl'} {:deprecated: .deprecated} {:dotnet-standard: .ph data-hd-programlang='dotnet-standard'} {:download: .download} {:external: .external target="_blank"} {:external: target="_blank" .external} {:faq: data-hd-content-type='faq'} {:fuzzybunny: .ph data-hd-programlang='fuzzybunny'} {:generic: data-hd-operatingsystem="generic"} {:generic: data-hd-programlang="generic"} {:gif: data-image-type='gif'} {:go: .ph data-hd-programlang='go'} {:help: data-hd-content-type='help'} {:hide-dashboard: .hide-dashboard} {:hide-in-docs: .hide-in-docs} {:important: .important} {:ios: data-hd-operatingsystem="ios"} {:java: #java .ph data-hd-programlang='java'} {:java: .ph data-hd-programlang='java'} {:java: data-hd-programlang="java"} {:javascript: .ph data-hd-programlang='javascript'} {:javascript: data-hd-programlang="javascript"} {:middle: .ph data-hd-position='middle'} {:navgroup: .navgroup} {:new_window: target="_blank"} {:node: .ph data-hd-programlang='node'} {:note: .note} {:objectc: .ph data-hd-programlang='Objective C'} {:objectc: data-hd-programlang="objectc"} {:org_name: data-hd-keyref="org_name"} {:php: .ph data-hd-programlang='PHP'} {:php: data-hd-programlang="php"} {:pre: .pre} {:preview: .preview} {:python: .ph data-hd-programlang='python'} {:python: data-hd-programlang="python"} {:release-note: data-hd-content-type='release-note'} {:right: .ph data-hd-position='right'} {:route: data-hd-keyref="route"} {:row-headers: .row-headers} {:ruby: .ph data-hd-programlang='ruby'} {:ruby: data-hd-programlang="ruby"} {:runtime: architecture="runtime"} {:runtimeIcon: .runtimeIcon} {:runtimeIconList: .runtimeIconList} {:runtimeLink: .runtimeLink} {:runtimeTitle: .runtimeTitle} {:screen: .screen} {:script: data-hd-video='script'} {:service: architecture="service"} {:service_instance_name: data-hd-keyref="service_instance_name"} {:service_name: data-hd-keyref="service_name"} {:shortdesc: .shortdesc} {:space_name: data-hd-keyref="space_name"} {:step: data-tutorial-type='step'} {:step: data-tutorial-type='step'} {:subsection: outputclass="subsection"} {:support: data-reuse='support'} {:swift: #swift .ph data-hd-programlang='swift'} {:swift: .ph data-hd-programlang='swift'} {:swift: data-hd-programlang="swift"} {:table: .aria-labeledby="caption"} {:term: .term} {:terraform: .ph data-hd-interface='terraform'} {:tip: .tip} {:tooling-url: data-tooling-url-placeholder='tooling-url'} {:topicgroup: .topicgroup} {:troubleshoot: data-hd-content-type='troubleshoot'} {:tsCauses: .tsCauses} {:tsResolve: .tsResolve} {:tsSymptoms: .tsSymptoms} {:tutorial: data-hd-content-type='tutorial'} {:ui: .ph data-hd-interface='ui'} {:unity: .ph data-hd-programlang='unity'} {:url: data-credential-placeholder='url'} {:user_ID: data-hd-keyref="user_ID"} {:vbnet: .ph data-hd-programlang='vb.net'} {:video: .video}
{: #deploy-multiple-regions}
Deploying your {{site.data.keyword.codeenginefull}} application across multiple regions can make it resilient to regional failures. Note that this example uses {{site.data.keyword.cis_full_notm}}, but you can use alternate providers. {: shortdesc}
Before you begin, you must have a custom domain name for your application, such as ibmcloud-test.net
. When you register your domain name with {{site.data.keyword.cis_short}}, you are delegating control of your domain name to {{site.data.keyword.cis_short}}. This domain name is used by your {{site.data.keyword.codeengineshort}} application.
{: #deploy-setup-cis}
If you do not have a {{site.data.keyword.cis_short}} instance set up, provision an instance{: external}.
{: #deploy-domain-name}
From the {{site.data.keyword.cis_short}} overview page,
-
Click Add Domain.
-
Connect to your domain by entering your custom domain name.
-
Set up your DNS records by uploading them in BIND format.
-
Delegate your domain management.
For more information about adding a domain, see Getting started with {{site.data.keyword.cis_full_notm}}.
{: #deploy-app-regions}
Deploy your application in multiple regions. You must deploy it in each region that you want to use. For more information about deploying your application, see Deploying applications. Record the URL endpoints for each deployment. To find your endpoint for an app, run
ibmcloud ce app get --name NAME
{: pre}
{: #deploy-config-load-balancer}
After your applications successfully deploy in multiple regions and are in a ready state, configure the {{site.data.keyword.cis_short}} load-balancer for your application global endpoint.
-
Go to the Reliability page in the {{site.data.keyword.cis_short}} console.
-
Select Origin pools and click Create.
Name your pool and then add each {{site.data.keyword.codeengineshort}} application endpoint. For example, if your application endpoint for your app that you created in
eu-de
iscustom-app.1a2b3c4d.eu-de.codeengine.appdomain.cloud
, then entereude
as your origin name,custom-app.1a2b3c4d.eu-de.codeengine.appdomain.cloud
as your origin address, and set the weight to1
. Ensure that this origin is enabled. Click Add + to enter additional application endpoints until all of the endpoints of the applications that you deployed in Step 3 are added. Click Save. -
Select Load balancers and click Create.
Name your load balancer and turn Enable and Proxy on. Under Geo Routes, click Add route and add the pool that you created in the previous step. Click Add.
-
From Create a load balancer, click Create.
For more information, see Configuring a global load balancer.
{: #deploy-cis-tls}
Transport Layer Security (TLS) certificates are used to encrypt traffic between CIS edge servers and your users. You must provide a TLS certificate for the appropriate hostnames for your application. You can choose a {{site.data.keyword.cis_short}}-provided TLS certificate or you can provide your own.
To provide your own TLS certificate,
-
Go to the Security page in the {{site.data.keyword.cis_short}} console.
-
Select TLS.
-
Under Mode, select End to End CA Signed.
-
From Edge certificates, click Upload. You can then upload your own certificate or create a certificate with {{site.data.keyword.cis_short}}. Note that your certificate might not be ready for up to 24 hours.
To order a free certificate from {{site.data.keyword.cis_short}},
-
Go to the Security page in the {{site.data.keyword.cis_short}} console.
-
Select Origin.
-
Click Order +.
-
Provide a Certificate Signing Request (CSR) or select a private key type for {{site.data.keyword.cis_short}} to generate a key and CSR.
-
Specify your certificate hostnames and an expiration date.
-
Click Order.
For more information about generating an origin certificate or about installing other types of certificates, see Ordering an origin certificate.
{: #deploy-edge-function}
Configure and deploy a {{site.data.keyword.cis_short}} Edge Function to act as a load-balancer for your application instances.
-
Go to the Edge Function page in the {{site.data.keyword.cis_short}} console.
-
Select Action->Create.
-
Copy in your JavaScript code that manages the load-balancing logic that you want to implement. Click Save.
-
Select Trigger->Create.
-
Create a trigger that maps your application hostname with an action. For example, specify
ibmcloud-test.net/*
as your trigger URL and then select that action that you created in the previous step. Click Save.
For more information, see Working with Edge functions.
For example, the following action code can be used to fail over across the HTTP endpoints of the applications that you deployed in Step 3.
addEventListener('fetch', (event) => {
const mutable_request = new Request(event.request);
event.respondWith(redirectAndLog(mutable_request));
});
async function redirectAndLog(request) {
const response = await redirectOrPass(request);
return response;
}
async function getSite(request, site) {
const url = new URL(request.url);
// let our servers know what origin the request came from
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
request.headers.set('X-Forwarded-Host', url.hostname);
request.headers.set('host', site);
url.hostname = site;
url.protocol = "https:";
response = fetch(url.toString(), request);
console.log('Got getSite Request to ' + site, response);
return response;
}
async function redirectOrPass(request) {
const urlObject = new URL(request.url);
let response = null;
try {
console.log('Got MAIN request', request);
response = await getSite(request, 'custom-app.1a2b3c4d.us-south.codeengine.appdomain.cloud');
console.log('Got MAIN response', response.status);
if (!response.ok && !response.redirected) {
console.log('Got FALLBACK request', response);
response = await getSite(request, 'custom-app.1a2b3c4d.eu-de.codeengine.appdomain.cloud');
console.log('Got Inside ', response);
}
return response;
} catch (error) {
// if no action found, play the regular request
console.log('Got Error', error);
return await fetch(request);
}
}
{: codeblock}
Now your applications are highly available and deployed with a custom domain name.