Set up a custom domain for a workload
This tutorial shows how to set up a custom domain and prepare a certificate required for exposing a workload. It uses Gardener External DNS Management and Certificate Management components.
NOTE: Skip this tutorial if you use a Kyma domain instead of your custom domain.
Prerequisites
- Deploy a sample HttpBin service and a sample Function.
- If you use a cluster not managed by Gardener, install the External DNS Management and Certificate Management components manually in a dedicated Namespace.
Steps
Create a Secret containing credentials for the DNS cloud service provider account in your Namespace.
- Choose your DNS cloud service provider and create a Secret in your Namespace. To learn how to do it, follow the guidelines provided in the External DNS Management documentation.
Export the name of the created Secret as an environment variable:
Click to copyexport SECRET={SECRET_NAME}
Create a
DNSProvider
custom resource (CR).Export the following values as environment variables.
NOTE: As the
SPEC_TYPE
, use the relevant provider type. TheDOMAIN_NAME
value specifies the name of a domain that you own, for example,mydomain.com
.Click to copyexport SPEC_TYPE={PROVIDER_TYPE}export DOMAIN_TO_EXPOSE_WORKLOADS={DOMAIN_NAME}To create a
DNSProvider
CR, run:Click to copycat <<EOF | kubectl apply -f -apiVersion: dns.gardener.cloud/v1alpha1kind: DNSProvidermetadata:name: dns-providernamespace: $NAMESPACEannotations:dns.gardener.cloud/class: gardenspec:type: $SPEC_TYPEsecretRef:name: $SECRETdomains:include:- $DOMAIN_TO_EXPOSE_WORKLOADSEOF
Create a
DNSEntry
CR.Export the following values as environment variables:
Click to copyexport IP=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}') # Assuming only one LoadBalancer with external IPNOTE: For some cluster providers you need to replace the
ip
with thehostname
, for example, in AWS, setjsonpath='{.status.loadBalancer.ingress[0].hostname}'
.To create a
DNSEntry
CR, run:Click to copycat <<EOF | kubectl apply -f -apiVersion: dns.gardener.cloud/v1alpha1kind: DNSEntrymetadata:name: dns-entrynamespace: $NAMESPACEannotations:dns.gardener.cloud/class: gardenspec:dnsName: "*.$DOMAIN_TO_EXPOSE_WORKLOADS"ttl: 600targets:- $IPEOF
Create a Certificate CR.
Export the following values as environment variables:
NOTE: The
TLS_SECRET
is the name of the TLS Secret, for examplehttpbin-tls-credentials
.Click to copyexport TLS_SECRET={TLS_SECRET_NAME}To create a Certificate CR, run:
Click to copycat <<EOF | kubectl apply -f -apiVersion: cert.gardener.cloud/v1alpha1kind: Certificatemetadata:name: httpbin-certnamespace: istio-systemspec:secretName: $TLS_SECRETcommonName: $DOMAIN_TO_EXPOSE_WORKLOADSEOFNOTE: While using the default configuration, certificates with the Let's Encrypt Issuer are valid for 90 days and automatically renewed 30 days before their validity expires. For more information, read the documentation on Gardener Certificate Management and Gardener extensions for certificate services.
To check the certificate status, run:
Click to copykubectl get certificate httpbin-cert -n istio-system
Visit the Gardener external DNS management documentation to see more examples of custom resources for services and ingresses.