Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand routing Management and Ingress in Knative Serving

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article shares with you about how to understand routing management and Ingress in Knative Serving. Xiaobian thinks it is quite practical, so share it with you. I hope you can gain something after reading this article. Let's not say much. Let's take a look at it together with Xiaobian.

By default, Kinetic generates a domain name for each Service, and Istio Gateway determines which Kinetic Service the current request should be forwarded to based on the domain name. The default domain name used by Knative is example.com, which is not available as an online service. In this article, I'll first explain how to modify the default primary domain name, and then I'll go further to explain how to add custom domain names and how to associate them to different Knative Services based on path.

Default domain name for Kinetic Serving example.com

First, you need to deploy a Knative Service. You can refer to Knative's initial experience: Serving Hello World. If you already have a Knative cluster, save the following directly to helloworld.yaml: Then execute kubectl apply -f helloworld.yaml to deploy the hello service to the helloworld namespace.

---apiVersion: v1kind: Namespacemetadata: name: helloworld---apiVersion: serving.knative.dev/v1alpha1kind: Servicemetadata: name: hello namespace: helloworldspec: template: metadata: labels: app: hello annotations: autoscaling.knative.dev/target: "10" spec: containers: - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/simple-app:132e07c14c49 env: - name: TARGET value: "World! "

Now let's take a look at the domain name configuration automatically generated by Kinetic Service:

└─# kubectl -n helloworld get ksvcNAME URL LATESTCREATED LATESTREADY READY REASONhello http://hello.helloworld.example.com hello-wsnvc hello-wsnvc True

The service is now accessible by specifying Host using curl.

Get the Istio Gateway IP first

└─# kubectl get svc istio-ingressgateway --namespace istio-system --output jsonpath="{.status.loadBalancer.ingress[*]['ip']}"47.95.191.136

Visit Hello Services

└─# curl -H "Host: hello.helloworld.example.com" http://47.95.191.136/Hello World!!

If you want to access the hello service in your browser, you need to do host binding first, pointing the domain name hello.helloworld.example.com to www.example.com. 47.95.191.136 This method cannot provide external services.

Use custom primary domain names

Let me introduce how to change the default example.com to our own domain name, assuming our own domain name is serverless.kuberun.com, now execute kubectl edit cm config-domain --namespace knative-serving as shown in the figure below, add serverless.kuberun.com to ConfigMap, and then save exit to complete the configuration of the custom primary domain name.

Take a look at the domain name of Kinetic Service, which is already in effect as shown below.

└─# kubectl -n helloworld get ksvcNAME URL LATESTCREATED LATESTREADY READY REASONhello http://hello.helloworld.serverless.kuberun.com hello-wsnvc hello-wsnvc True

Universal Domain Name Resolution

The default rule for generating domain names is servicename.namespace.use-domain. So different namespaces generate different subdomains, and each Kinetic Service generates a unique subdomain. In order to ensure that all Service services can be accessed on the public network, a generic domain name resolution is required. Parse *. serverless.kuberun.com to Istio Gateway www.example.com. 47.95.191.136 If you purchased a domain name on Alibaba Cloud, you can configure domain name resolution as follows:

You can now visit http://hello.helloworld.serverless.kuberun.com/directly through your browser to see helloworld services directly:

##Custom Service Domain Names

Just now we assigned a primary domain name to Knative so that Service generates its own unique domain name based on the primary domain name. However, the automatically generated domain name is not very friendly. For example, the domain name helloworld.serverless.kuberun.com just deployed is not obvious to ordinary users and is difficult to remember.

It would be perfect if you could access the hello world service at hello.kuberun.com Here's how to do it:

First modify the domain name resolution on Wanwang, and point the A record of hello.kuberun.com to Istio Gateway 47.95.191.136

After hello.kuberun.com resolves to Istio Gateway, Istio Gateway does not know which service this should be forwarded to, so you need to configure VirtualService to tell Istio how to forward, and save the following contents to the hello-ingress-route.yaml file:

apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata:name: hello-ingress-routenamespace: knative-servingspec:gateways:- knative-ingress-gatewayhosts:- hello.helloworld.serverless.kuberun.com- hello.kuberun.comhttp:- match: - uri: prefix: "/" rewrite: authority: hello.helloworld.svc.cluster.local retries: attempts: 3 perTryTimeout: 10m0s route: - destination: host: istio-ingressgateway.istio-system.svc.cluster.local port: number: 80 weight: 100 timeout: 10m0s websocketUpgrade: true

Now open http://hello.kuberun.com/ and you can see helloworld services:

Path-based service forwarding

The real online service scenario may be a path backend corresponding to an application. Now let's expand on hello.kuberun.com. Let the path at the beginning of/blog map to blog service, and the other paths are still typed to hello service.

Save the following content to the blog.yaml file, and then execute: kubectl apply -f blog.yaml to complete the deployment of the blog service.

---apiVersion: v1kind: Namespacemetadata: name: blog---apiVersion: serving.knative.dev/v1alpha1kind: Servicemetadata: name: hello-blog namespace: blogspec: template: metadata: labels: app: hello annotations: autoscaling.knative.dev/target: "10" spec: containers: - image: registry.cn-hangzhou.aliyuncs.com/knative-sample/simple-app:132e07c14c49 env: - name: TARGET value: "Blog! "

Check the default domain name for blog services:

└─# kubectl -n blog get ksvcNAME URL LATESTCREATED LATESTREADY READY REASONhello http://hello-blog.blog.serverless.kuberun.com hello-zbm7q hello-zbm7q True

Now open http://hello-blog.blog.serverless.kuberun.com using your browser to access the service you just deployed:

This is the default domain name, our requirement is to want to access through http://hello.kuberun.com/blog, so we also need to modify the configuration of Istio VirtualService. Add/blog configuration to hello-ingress-route.yaml as follows:

apiVersion: networking.istio.io/v1alpha3kind: VirtualServicemetadata: name: hello-ingress-route namespace: knative-servingspec: gateways: - knative-ingress-gateway hosts: - hello.helloworld.serverless.kuberun.com - hello.kuberun.com http: - match: - uri: prefix: "/blog" rewrite: authority: hello-blog.blog.svc.cluster.local retries: attempts: 3 perTryTimeout: 10m0s route: - destination: host: istio-ingressgateway.istio-system.svc.cluster.local port: number: 80 weight: 100 - match: - uri: prefix: "/" rewrite: authority: hello.helloworld.svc.cluster.local retries: attempts: 3 perTryTimeout: 10m0s route: - destination: host: istio-ingressgateway.istio-system.svc.cluster.local port: number: 80 weight: 100 timeout: 10m0s websocketUpgrade: true

You can now open http://hello.kuberun.com/blog in your browser as follows:

Here, we mainly introduce the routing management of Knative Service around the domain name of Knative Service.

The above is how to understand routing management and Ingress in Knative Serving. Xiaobian believes that some knowledge points may be seen or used in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report