apiVersion: serving.knative.dev/v1alpha1
kind: DomainMapping
metadata:
name: <domain_name> (1)
namespace: <namespace> (2)
spec:
ref:
name: <target_name> (3)
kind: <target_type> (4)
apiVersion: serving.knative.dev/v1
Knative services are automatically assigned a default domain name based on your cluster configuration. For example, <service_name>.<namespace>.example.com
.
You can customize the domain for your Knative service by mapping a custom domain name that you own to a Knative service, by creating a DomainMapping
resource for the service. You can also create multiple DomainMapping
resources to map multiple domains and subdomains to a single service.
To map a custom domain name to a custom resource (CR), you must create a DomainMapping
CR that maps to an Addressable target CR, such as a Knative service or a Knative route.
The OpenShift Serverless Operator and Knative Serving are installed on your cluster.
Install the OpenShift CLI (oc
).
You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in Red Hat OpenShift Service on AWS.
You have created a Knative service and control a custom domain that you want to map to that service.
Your custom domain must point to the IP address of the Red Hat OpenShift Service on AWS cluster. |
Create a YAML file containing the DomainMapping
CR in the same namespace as the target CR you want to map to:
apiVersion: serving.knative.dev/v1alpha1
kind: DomainMapping
metadata:
name: <domain_name> (1)
namespace: <namespace> (2)
spec:
ref:
name: <target_name> (3)
kind: <target_type> (4)
apiVersion: serving.knative.dev/v1
1 | The custom domain name that you want to map to the target CR. |
2 | The namespace of both the DomainMapping CR and the target CR. |
3 | The name of the target CR to map to the custom domain. |
4 | The type of CR being mapped to the custom domain. |
apiVersion: serving.knative.dev/v1alpha1
kind: DomainMapping
metadata:
name: example-domain
namespace: default
spec:
ref:
name: example-service
kind: Service
apiVersion: serving.knative.dev/v1
apiVersion: serving.knative.dev/v1alpha1
kind: DomainMapping
metadata:
name: example-domain
namespace: default
spec:
ref:
name: example-route
kind: Route
apiVersion: serving.knative.dev/v1
Apply the DomainMapping
CR as a YAML file:
$ oc apply -f <filename>
You can use the kn
CLI to create a DomainMapping
custom resource (CR) that maps to an Addressable target CR, such as a Knative service or a Knative route.
The --ref
flag specifies an Addressable target CR for domain mapping.
If a prefix is not provided when using the --ref
flag, it is assumed that the target is a Knative service in the current namespace. The examples in the following procedure show the prefixes for mapping to a Knative service or a Knative route.
The OpenShift Serverless Operator and Knative Serving are installed on your cluster.
You have created a Knative service or route, and control a custom domain that you want to map to that CR.
Your custom domain must point to the DNS of the Red Hat OpenShift Service on AWS cluster. |
You have installed the kn
CLI tool.
You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in Red Hat OpenShift Service on AWS.
Map a domain to a CR in the current namespace:
$ kn domain create <domain_mapping_name> --ref <target_name>
$ kn domain create example-domain-map --ref example-service
Map a domain to a Knative service in a specified namespace:
$ kn domain create <domain_mapping_name> --ref <ksvc:service_name:service_namespace>
$ kn domain create example-domain-map --ref ksvc:example-service:example-namespace
Map a domain to a Knative route:
$ kn domain create <domain_mapping_name> --ref <kroute:route_name>
$ kn domain create example-domain-map --ref kroute:example-route
You can use the Administrator or Developer perspective of the Red Hat OpenShift Service on AWS web console to create a custom domain mapping for a Knative service.
If you have cluster or dedicated administrator permissions, you can create a DomainMapping
custom resource (CR) by using the Administrator perspective in the Red Hat OpenShift Service on AWS web console.
You have logged in to the web console.
You are in the Administrator perspective.
You have installed the OpenShift Serverless Operator.
You have installed Knative Serving.
You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in Red Hat OpenShift Service on AWS.
You have created a Knative service and control a custom domain that you want to map to that service.
Your custom domain must point to the IP address of the Red Hat OpenShift Service on AWS cluster. |
Navigate to CustomResourceDefinitions and use the search box to find the DomainMapping custom resource definition (CRD).
Click the DomainMapping CRD, then navigate to the Instances tab.
Click Create DomainMapping.
Modify the YAML for the DomainMapping
CR so that it includes the following information for your instance:
apiVersion: serving.knative.dev/v1alpha1
kind: DomainMapping
metadata:
name: <domain_name> (1)
namespace: <namespace> (2)
spec:
ref:
name: <target_name> (3)
kind: <target_type> (4)
apiVersion: serving.knative.dev/v1
1 | The custom domain name that you want to map to the target CR. |
2 | The namespace of both the DomainMapping CR and the target CR. |
3 | The name of the target CR to map to the custom domain. |
4 | The type of CR being mapped to the custom domain. |
apiVersion: serving.knative.dev/v1alpha1
kind: DomainMapping
metadata:
name: custom-ksvc-domain.example.com
namespace: default
spec:
ref:
name: example-service
kind: Service
apiVersion: serving.knative.dev/v1
Access the custom domain by using a curl
request. For example:
$ curl custom-ksvc-domain.example.com
Hello OpenShift!
You can use the Developer perspective of the Red Hat OpenShift Service on AWS web console to map a DomainMapping
custom resource (CR) to a Knative service.
You have logged in to the web console.
You are in the Developer perspective.
The OpenShift Serverless Operator and Knative Serving are installed on your cluster. This must be completed by a cluster administrator.
You have created a project or have access to a project with the appropriate roles and permissions to create applications and other workloads in Red Hat OpenShift Service on AWS.
You have created a Knative service and control a custom domain that you want to map to that service.
Your custom domain must point to the IP address of the Red Hat OpenShift Service on AWS cluster. |
Navigate to the Topology page.
Right-click on the service that you want to map to a domain, and select the Edit option that contains the service name. For example, if the service is named example-service
, select the Edit example-service option.
In the Advanced options section, click Show advanced Routing options.
If the domain mapping CR that you want to map to the service already exists, you can select it from the Domain mapping drop-down.
If you want to create a new domain mapping CR, type the domain name into the box, and select the Create option. For example, if you type in example.com
, the Create option is Create "example.com".
Click Save to save the changes to your service.
Navigate to the Topology page.
Click on the service that you have created.
In the Resources tab of the service information window, you can see the domain you have mapped to the service listed under Domain mappings.