Configure an IBM Cloud Code Engine application to use custom domains

IBM Cloud Code Engine is a fully managed, serverless platform that runs your containerized workloads, including web apps, microservices, event-driven functions or batch jobs. Code Engine even builds container images for you from your source code.

All these workloads can seamlessly work together because they are all hosted within the same Kubernetes infrastructure. The Code Engine experience is designed so that you could focus on writing code and not worry about the infrastructure that is needed to host it.


Appropriate permissions to use the IBM Cloud Code Engine service. See here for how to manage these.

An application running on IBM Cloud Code Engine. You can deploy the test application from here.

Access to modify DNS of a public domain/hostname. If you own a domain or purchased one, you will most likely have access to manage DNS for that domain. In the example, we have used IBM Cloud Internet Services that support CNAME flattening feature to enable us to use root domain.

A TLS/SSL certificate signed by a public certificate authority.

In this example, the test application is deployed on IBM Cloud Code Engine. The original hostname looks something similar to this We’ll expose this application using two custom domains:

Step-by-step instructions

Refer this document and the below steps to create the TLS certificates for both domains and use them to expose this test application. You can use Let’s Encrypt CA as an example to request TLS certificates for these custom domains. However, you can also use a TLS certificate from any of the public certificate authorities.

We’ll follow these steps to accomplish our goals:

Generate CSR for TLS certificate and get it signed from CA.

Add your domain to Code Engine application UI.

Create CNAME record in DNS for your domain name.

1. Generate CSR for TLS certificate and get it signed from CA

To generate a valid signed TLS certificate from Let’s Encrypt CA, you can use the Certbot client to generate the CSR and get it signed from CA. First, you need to install the Certbot using these instructions.

Use the following command to start the process for the certificate generation:

certbot certonly –manual –preferred-challenges dns –email [email protected] –server –agree-tos –domain

certbot certonly –manual –preferred-challenges dns –email [email protected] –server –agree-tos –domain

Then, it should ask you for the domain ownership verification step:

[email protected]:~# certbot certonly –manual –preferred-challenges dns –email [email protected] –server –agree-tos –domain
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Please deploy a DNS TXT record under the name:

with the following value:


Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox:
Look for one or more bolded line(s) below the line ‘;ANSWER’. It should show the
value(s) you’ve just added.

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
Press Enter to Continue

Let’s add the verification TXT records for both domains in the DNS as per the below: TXT Fq2wbN9mUSfnWZkGXyaEgVaOm-_9RB4cv4zJEp44Sbg TXT DfjSDFFDbN9vccdSDnjnkSNSNKx-_9vccdSDnZvccdSDn

Now, you need to create a TXT record with the above value in your domain’s DNS servers. The DNS servers for your domain might have been provided by your domain registrar or these can be hosted somewhere else. After you add this DNS record, you can verify it using dig or nslookup:

% dig txt +short

After you press Enter or Return, you should see something like the following:

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/
Key is saved at: /etc/letsencrypt/live/
This certificate expires on 2023-07-20.
These files will be updated when the certificate renews.

– This certificate will not be renewed automatically. Autorenewal of –manual certificates requires the use of an authentication hook script (–manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate’s expiry date.

– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –
If you like Certbot, please consider supporting our work by:
* Donating to ISRG / Let’s Encrypt:
* Donating to EFF:
– – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – – –

You got two files:


This is your TLS certificate with full root-ca chain certificates. The contents should be something like this:



This is the private key for your TLS certificate. The content of the private key file should be something like the following:


2. Add your domain to Code Engine application UI

Since you have TLS certificate and key available, you can now proceed to add the custom domain to the IBM Cloud Code Engine application from the IBM Cloud console.

Go here and follow Projects > Your project name > Applications > Application name > Domain mappings tab

Select the application for which you want to use a custom domain.

Select Domain mappings from the top bar menu.

Here, you need to click on the blue button named Create under the section titled Custom domain mappings.

A new setup wizard should open like the screenshot above. You need to paste the contents from the file fullchain.pem in the text box titled Certificate chain and file privkey.pem to the text box titled Private key.

Under the section titled Domain name and target application, type the actual custom domain hostname:

Domain name: Type “” in this editable text field.

CNAME Target: Pref-filled text should be there, which we need to create a CNAME record for this domain name. CNAME CNAME custom.

3. Create a CNAME record in DNS for your domain name

This is an important step. Let’s create a CNAME record in your domain’s DNS servers pointing to the value from the CNAME target box.

After you have created the CNAME record, proceed by selecting the Create button to finish creating the custom domain name mapping. This should take few minutes to be fully activated in the system.

If you want to use your root domain ( instead of a subdomain like, you may want to use the CNAME flattening feature of IBM Cloud Internet Services. For more details refer to the links below.

How can I use Cloud Internet Services (CIS) with custom domain mapping?

Root record CNAME flattening

Getting started with IBM Cloud Internet Services

If everything goes fine, you should be able to access your application using your custom domain:

% curl -k
Hello World from:
. ___ __ ____ ____
./ __)/ ( ( __)
( (__( O )) D ( ) _)
.____ __ _ ___ __ __ _ ____
( __)( ( / __)( )( ( ( __)
.) _) / /( (_ )( / / ) _)
(____)_)__) ___/(__)_)__)(____)

Some Env Vars:
z=Set env var ‘SHOW’ to see all variables

Congratulations, we have successfully exposed our IBM Cloud Code Engine application via custom domains.

Learn more

For more information on related IBM Cloud services please refer to the links below.

IBM Cloud Code Engine docs

IBM Cloud Internet Services

Configuring a highly available application to set up a Global Load Balancer

Updating a custom domain mapping with the CLI to renew TLS certificates of existing domain mappings

Get started with IBM Cloud Code Engine

Get started with IBM Cloud Code Engine

The post Configure an IBM Cloud Code Engine application to use custom domains appeared first on IBM Blog.

Leave a Reply

Your email address will not be published. Required fields are marked *