Set up a custom domain for a workload
This tutorial shows how to set up your custom domain and prepare a certificate 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
If you use a cluster not managed by Gardener, install the External DNS Management and Certificate Management components manually in a dedicated Namespace.
This tutorial is based on a sample HttpBin service deployment and a sample Function. To deploy or create those workloads, follow the Create a workload tutorial.
Steps
Follow these steps to set up your custom domain and prepare a certificate required to expose a workload.
Create a Secret containing credentials for your DNS cloud service provider account in your Namespace.
See the official External DNS Management documentation, choose your DNS cloud service provider, and follow the relevant guidelines to create a secret in your Namespace. Then export the following value as an environment variable:
Click to copyexport SECRET={SECRET_NAME}Create a DNSProvider and a DNSEntry custom resource (CR).
- Export the following values as environment variables and run the command provided.
As the SPEC_TYPE, use the relevant provider type. See the official Gardener examples of the DNSProvider CR.
Click to copyexport SPEC_TYPE={PROVIDER_TYPE}export DOMAIN_TO_EXPOSE_WORKLOADS={DOMAIN_NAME}NOTE:
DOMAIN_NAME
is the domain that you own, for example, mydomain.comClick 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- Export the following values as environment variables and run the command provided:
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 may need to replace the
ip
with thehostname
, for example, in AWS, setjsonpath='{.status.loadBalancer.ingress[0].hostname}'
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:- $IPEOFCreate an Issuer CR.
Export the following values as environment variables and run the command provided.
Click to copyexport EMAIL={YOUR_EMAIL_ADDRESS}Click to copycat <<EOF | kubectl apply -f -apiVersion: cert.gardener.cloud/v1alpha1kind: Issuermetadata:name: letsencrypt-stagingnamespace: $NAMESPACEspec:acme:server: https://acme-staging-v02.api.letsencrypt.org/directoryemail: $EMAILautoRegistration: trueprivateKeySecretRef:name: letsencrypt-staging-secretnamespace: $NAMESPACEdomains:include:- $DOMAIN_TO_EXPOSE_WORKLOADS- "*.$DOMAIN_TO_EXPOSE_WORKLOADS"EOFCreate a Certificate CR.
Export the following values as environment variables and run the command provided.
Click to copyexport TLS_SECRET={TLS_SECRET_NAME} # The name of the TLS Secret that will be created in this step, for example, httpbin-tls-credentialsexport ISSUER={ISSUER_NAME} # The name of the Issuer CR, for example,letsencrypt-stagingClick to copycat <<EOF | kubectl apply -f -apiVersion: cert.gardener.cloud/v1alpha1kind: Certificatemetadata:name: httpbin-certnamespace: istio-systemspec:secretName: $TLS_SECRETcommonName: $DOMAIN_TO_EXPOSE_WORKLOADSissuerRef:name: $ISSUERnamespace: $NAMESPACEEOFNOTE: Run the following command to check the certificate status:
kubectl get certificate httpbin-cert -n istio-system
Create a Gateway CR. Run:
NOTE: Skip this step if you're creating mTLS gateway.
Click to copycat <<EOF | kubectl apply -f -apiVersion: networking.istio.io/v1alpha3kind: Gatewaymetadata:name: httpbin-gatewaynamespace: $NAMESPACEspec:selector:istio: ingressgateway # Use Istio Ingress Gateway as defaultservers:- port:number: 443name: httpsprotocol: HTTPStls:mode: SIMPLEcredentialName: $TLS_SECREThosts:- "*.$DOMAIN_TO_EXPOSE_WORKLOADS"EOF