{"id":39662,"date":"2023-09-12T16:39:00","date_gmt":"2023-09-12T16:39:00","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=39662"},"modified":"2025-01-13T12:15:22","modified_gmt":"2025-01-13T12:15:22","slug":"knative-tutorials-how-to-change-ksvc-dns-url","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/knative-tutorials-how-to-change-ksvc-dns-url\/","title":{"rendered":"Knative Tutorials: How to change ksvc DNS \/ URL?"},"content":{"rendered":"\n<p>The URL format for Knative Service (KService or ksvc) objects in Kubernetes is typically determined by the DNS configuration and domain suffixes within your Kubernetes cluster. The format <code>http:\/\/&lt;service-name&gt;.&lt;namespace&gt;.svc.cluster.local<\/code> is the default URL structure for services within a Kubernetes cluster, where:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>&lt;service-name&gt;<\/code> is the name of your Knative service.<\/li>\n\n\n\n<li><code>&lt;namespace&gt;<\/code> is the namespace where the service is deployed.<\/li>\n\n\n\n<li><code>svc.cluster.local<\/code> is the default DNS suffix for services within the cluster.<\/li>\n<\/ul>\n\n\n\n<p>If you want to use a custom domain name like <code>http:\/\/devops.default.example.com<\/code> instead of the default URL, you need to configure DNS and customize the Knative Service accordingly.<\/p>\n\n\n\n<p>Here are the steps to configure a custom domain for your Knative Service:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Configure DNS<\/strong>:To use a custom domain like <code>example.com<\/code>, you need to configure your DNS to point to the IP address of your Kubernetes cluster&#8217;s load balancer or the external IP of your Ingress controller. This typically involves creating a DNS A or CNAME record in your DNS provider&#8217;s control panel. Ensure that the custom domain resolves to the correct IP address.<\/li>\n\n\n\n<li><strong>Ingress Configuration<\/strong>:If you&#8217;re using an Ingress controller to expose your Knative services to the external network, you&#8217;ll need to configure the Ingress resource to map the custom domain to your Knative Service. Here&#8217;s an example of an Ingress resource YAML that routes traffic from <code>example.com<\/code> to your Knative Service:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"893\" height=\"667\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-298.png\" alt=\"\" class=\"wp-image-39663\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-298.png 893w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-298-300x224.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-298-768x574.png 768w\" sizes=\"auto, (max-width: 893px) 100vw, 893px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Apply this Ingress configuration to your cluster to route traffic from your custom domain to the Knative Service.<\/li>\n\n\n\n<li><strong>Knative Service Configuration<\/strong>:Ensure that the Knative Service resource (<code>KService<\/code> or <code>ksvc<\/code>) specifies the correct hostname in its configuration. You can set the <code>hostname<\/code> field in the <code>spec<\/code> section of your Knative Service YAML to match your custom domain:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"893\" height=\"555\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-299.png\" alt=\"\" class=\"wp-image-39664\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-299.png 893w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-299-300x186.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2023\/09\/image-299-768x477.png 768w\" sizes=\"auto, (max-width: 893px) 100vw, 893px\" \/><\/figure>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Make sure to replace <code>devops.default.example.com<\/code> with your actual custom domain.<\/li>\n\n\n\n<li><strong>Verify Configuration<\/strong>:After making these changes, ensure that your custom domain (<code>http:\/\/devops.default.example.com<\/code>) is working as expected. You may need to wait for DNS propagation, which can take some time depending on your DNS provider.<\/li>\n<\/ol>\n\n\n\n<p>By following these steps, you can configure a custom domain for your Knative Service, allowing it to be accessed using the desired URL format.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example<\/h2>\n\n\n\n<p><br>The <code>http:\/\/devops.default.svc.cluster.local<\/code> URL is the Kubernetes internal DNS name for the <code>devops<\/code> Knative Service. The <code>default<\/code> is the namespace where the Knative Service is created, and <code>svc<\/code> is the Kubernetes service subdomain. <code>cluster.local<\/code> is the Kubernetes cluster domain.<\/p>\n\n\n\n<p>The <code>http:\/\/devops.default.example.com<\/code> URL is an external DNS name for the <code>devops<\/code> Knative Service. The <code>example.com<\/code> is the domain name of the Kubernetes cluster.<\/p>\n\n\n\n<p>The Kubernetes cluster administrator can configure the external DNS name for a Knative Service. The external DNS name is used by clients outside of the Kubernetes cluster to access the Knative Service.<\/p>\n\n\n\n<p>In your case, the Kubernetes cluster administrator has not configured an external DNS name for the <code>devops<\/code> Knative Service. Therefore, the only way to access the Knative Service is to use the internal DNS name.<\/p>\n\n\n\n<p>To access the <code>devops<\/code> Knative Service from outside of the Kubernetes cluster, you can use a service mesh, such as Istio, to create an external DNS name for the Knative Service.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The URL format for Knative Service (KService or ksvc) objects in Kubernetes is typically determined by the DNS configuration and domain suffixes within your Kubernetes cluster. The format http:\/\/&lt;service-name&gt;.&lt;namespace&gt;.svc.cluster.local is the default URL structure for services within a Kubernetes cluster, where: If you want to use a custom domain name like http:\/\/devops.default.example.com instead of the&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[8921],"tags":[],"class_list":["post-39662","post","type-post","status-publish","format-standard","hentry","category-knative"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/39662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=39662"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/39662\/revisions"}],"predecessor-version":[{"id":39666,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/39662\/revisions\/39666"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=39662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=39662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=39662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}