调用DescribeCrTemplates查询服务网格中常见使用场景下的Istio资源YAML模板。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

请求参数

名称 类型 是否必选 示例值 描述
IstioVersion String v1.9.7.31-g24cdcb43-aliyun

服务网格使用的Istio版本

Kind String VirtualService

查询的常见模板istio资源类型,取值:

  • AuthorizationPolicy
  • RequestAuthentication
  • PeerAuthentication
  • WorkloadGroup
  • WorkloadEntry
  • Sidecar
  • EnvoyFilter
  • ServiceEntry
  • Gateway
  • DestinationRule
  • VirtualService

返回数据

名称 类型 示例值 描述
RequestId String 7B1DC8D7-CE45-5643-BB05-705E630B****

请求Id

Templates Array of Templates

根据查询内容返回的Istio资源常用YAML模板列表

ChineseName String HTTP基础路由

YAML模板的中文名称

EnglishName String HTTP basic routing

YAML模板的英文名称

Yaml String apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n name: reviews-route # Name for this VirtualService.\nspec:\n hosts:\n - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. \n http:\n - name: \"reviews-route\" # Name for the route.\n route:\n - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.\n host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n port:\n number: 8080

YAML模板的具体内容

示例

请求示例

http(s)://[Endpoint]/?Action=DescribeCrTemplates
&Kind=v1.9.7.31-g24cdcb43-aliyun
&IstioVersion=VirtualService
&<公共请求参数>

正常返回示例

XML格式

<RequestId>7B1DC8D7-CE45-5643-BB05-705E630B6D08</RequestId>
<Templates>
    <ChineseName>HTTP基础路由</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: reviews-route # Name for this VirtualService.
spec:
  hosts:
  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. 
  http:
  - name: "reviews-route" # Name for the route.
    route:
    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.
        host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
        port:
          number: 8080</Yaml>
    <EnglishName>HTTP basic routing</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP多版本路由</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: reviews-route # Name for this VirtualService.
spec:
  hosts:
  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. 
  http:
  - name: "reviews-v2-routes" # Name for the route.
    match: # Match conditions to be satisfied for the route to be activated.
    - uri: # Match requests whose URL path starts with /wpcatalog.
        prefix: "/wpcatalog"
    - uri: # Match requests whose URL path starts with /consumercatalog.
        prefix: "/consumercatalog"
    - headers: # Match requests whose URL path starts with /reviews/v2/ and the request contains a `end-user` header with value `jason`.
        end-user:
          exact: jason
      uri:
        prefix: "/reviews/v2/"
    route:
    - destination: # Uniquely identifies the instances of a service to which matched traffic should be forwarded to.
        host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
        subset: v2 # The name of the service subset which is defined in DestinationRule.
  - name: "reviews-v1-route"
    route:
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v1</Yaml>
    <EnglishName>HTTP subset routing</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP权重路由</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: reviews-route # Name for this VirtualService.
spec:
  hosts:
  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. 
  http:
    - route:
      - destination: # Uniquely identifies the instances of a service to which traffic should be forwarded to.
          host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
          subset: v2 # The name of the service subset which is defined in DestinationRule.
        weight: 25 # Weight for the service subset.
      - destination:
          host: reviews.prod.svc.cluster.local
          subset: v1
        weight: 75</Yaml>
    <EnglishName>HTTP weighted routing</EnglishName>
</Templates>
<Templates>
    <ChineseName>TLS透传路由</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: bookinfo-sni # Name for this VirtualService.
spec:
  hosts:
  - "*.bookinfo.com" # Service that this VirtualSerivce belongs to. 
  gateways:
  - mygateway # This VirtualSerice is only applied on Gateway of mygateway.
  tls:
  - match: # Match conditions to be satisfied for the route to be activated.
    - port: 443 # Match port.
      sniHosts:
      - login.bookinfo.com # Server Name Indication (SNI) contained in the traffic.
    route:
    - destination: # Uniquely identifies the instances of a service to which matched traffic should be forwarded to.
        host: login.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.</Yaml>
    <EnglishName>Unterminated TLS routing</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP重定向</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-route # Name for this VirtualService.
spec:
  hosts:
  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. 
  http:
  - match: # Match conditions to be satisfied for the route to be activated.
    - uri: # Match requests whose URL path is exactly /v1/getProductRatings.
        exact: /v1/getProductRatings
    redirect: # Traffic will be directed to.
      uri: /v1/bookRatings
      authority: newratings.default.svc.cluster.local</Yaml>
    <EnglishName>HTTP redirect</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP重写</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-route # Name for this VirtualService.
spec:
  hosts:
  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. 
  http:
  - match: # Match conditions to be satisfied for the route to be activated.
    - uri: # Match requests whose URL path starts with /ratings.
        prefix: /ratings
    rewrite: # Replace /ratings with /v1/bookRatings.
      uri: /v1/bookRatings
    route:
    - destination: # Uniquely identifies the instances of a service to which matched traffic should be forwarded to.
        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.</Yaml>
    <EnglishName>HTTP rewrite</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP超时</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-route # Name for this VirtualService.
spec:
  hosts:
  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.
  http:
  - timeout: 5s # Timeout of 5s for all traffic to ratings.prod.svc.cluster.local service.
    route:
    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.
        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.</Yaml>
    <EnglishName>HTTP timeout</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP重试</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-route # Name for this VirtualService.
spec:
  hosts:
  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.
  http:
  - route:
    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.
        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
    retries:
      attempts: 3 # Try 3 times.
      perTryTimeout: 2s # Timeout for each retry.
      retryOn: gateway-error,connect-failure,refused-stream # Details at https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-on</Yaml>
    <EnglishName>HTTP retry</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP请求延时故障注入</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: reviews-route # Name for this VirtualService.
spec:
  hosts:
  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.
  http:
  - match: # Match conditions to be satisfied for the route to be activated.
    - sourceLabels: # Traffic from all pods with label env: prod
        env: prod
    route:
    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.
        host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
        subset: v1 # The name of the service subset which is defined in DestinationRule.
    fault:
      delay:
        percentage: # 5 second delay in 1 out of every 1000 requests.
          value: 0.1
        fixedDelay: 5s</Yaml>
    <EnglishName>HTTP fault injection of request delay</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP请求中止故障注入</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-route # Name for this VirtualService.
spec:
  hosts:
  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.
  http:
  - route:
    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.
        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
        subset: v1 # The name of the service subset which is defined in DestinationRule.
    fault:
      abort:
        percentage: # Return an HTTP 400 error code for 1 out of every 1000 requests.
          value: 0.1
        httpStatus: 400</Yaml>
    <EnglishName>HTTP fault injection of request abort</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP流量镜像</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: ratings-route # Name for this VirtualService.
spec:
  hosts:
    - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.
  http:
  - route:
    - destination:
        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
        subset: v1
      weight: 100
    mirror: # All traffic to subset v1 will be mirrored to subset v2.
      host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.
      subset: v2
    mirrorPercentage: # Percentage of the traffic to be mirrored by the `mirror` field.
      value: 100.0</Yaml>
    <EnglishName>HTTP traffic mirroring</EnglishName>
</Templates>
<Templates>
    <ChineseName>HTTP代理</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: bookinfo # Name for this VirtualService.
spec:
  hosts:
  - "bookinfo.com" # Service that this VirtualSerivce belongs to.
  gateways:
  - mygateway # This VirtualSerice is only applied on Gateway of mygateway.
  http:
  - match: # Match conditions to be satisfied for the route to be activated.
    - uri: # Match requests whose URL path is exactly /productpage.
        prefix: "/productpage"
    delegate:
       name: productpage # The name of VirtualService to which matched traffic are forwarded. 
       namespace: nsA</Yaml>
    <EnglishName>HTTP delegate</EnglishName>
</Templates>
<Templates>
    <ChineseName>TCP权重路由</ChineseName>
    <Yaml>apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
  name: tcp-echo # Name for this VirtualService.
spec:
  hosts:
  - "*" # Service that this VirtualSerivce belongs to. 
  gateways:
  - tcp-echo-gateway # This VirtualSerice is only applied on Gateway of tcp-echo-gateway.
  tcp:
  - match:
    - port: 31400
    route:
    - destination:
        host: tcp-echo
        port:
          number: 9000
        subset: v1
      weight: 80
    - destination:
        host: tcp-echo
        port:
          number: 9000
        subset: v2
      weight: 20</Yaml>
    <EnglishName>TCP weighted routing</EnglishName>
</Templates>

JSON格式

{
    "RequestId": "7B1DC8D7-CE45-5643-BB05-705E630B6D08",
    "Templates": [
        {
            "ChineseName": "HTTP基础路由",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: reviews-route # Name for this VirtualService.\nspec:\n  hosts:\n  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. \n  http:\n  - name: \"reviews-route\" # Name for the route.\n    route:\n    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.\n        host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n        port:\n          number: 8080",
            "EnglishName": "HTTP basic routing"
        },
        {
            "ChineseName": "HTTP多版本路由",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: reviews-route # Name for this VirtualService.\nspec:\n  hosts:\n  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. \n  http:\n  - name: \"reviews-v2-routes\" # Name for the route.\n    match: # Match conditions to be satisfied for the route to be activated.\n    - uri: # Match requests whose URL path starts with /wpcatalog.\n        prefix: \"/wpcatalog\"\n    - uri: # Match requests whose URL path starts with /consumercatalog.\n        prefix: \"/consumercatalog\"\n    - headers: # Match requests whose URL path starts with /reviews/v2/ and the request contains a `end-user` header with value `jason`.\n        end-user:\n          exact: jason\n      uri:\n        prefix: \"/reviews/v2/\"\n    route:\n    - destination: # Uniquely identifies the instances of a service to which matched traffic should be forwarded to.\n        host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n        subset: v2 # The name of the service subset which is defined in DestinationRule.\n  - name: \"reviews-v1-route\"\n    route:\n    - destination:\n        host: reviews.prod.svc.cluster.local\n        subset: v1",
            "EnglishName": "HTTP subset routing"
        },
        {
            "ChineseName": "HTTP权重路由",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: reviews-route # Name for this VirtualService.\nspec:\n  hosts:\n  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. \n  http:\n    - route:\n      - destination: # Uniquely identifies the instances of a service to which traffic should be forwarded to.\n          host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n          subset: v2 # The name of the service subset which is defined in DestinationRule.\n        weight: 25 # Weight for the service subset.\n      - destination:\n          host: reviews.prod.svc.cluster.local\n          subset: v1\n        weight: 75",
            "EnglishName": "HTTP weighted routing"
        },
        {
            "ChineseName": "TLS透传路由",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: bookinfo-sni # Name for this VirtualService.\nspec:\n  hosts:\n  - \"*.bookinfo.com\" # Service that this VirtualSerivce belongs to. \n  gateways:\n  - mygateway # This VirtualSerice is only applied on Gateway of mygateway.\n  tls:\n  - match: # Match conditions to be satisfied for the route to be activated.\n    - port: 443 # Match port.\n      sniHosts:\n      - login.bookinfo.com # Server Name Indication (SNI) contained in the traffic.\n    route:\n    - destination: # Uniquely identifies the instances of a service to which matched traffic should be forwarded to.\n        host: login.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.",
            "EnglishName": "Unterminated TLS routing"
        },
        {
            "ChineseName": "HTTP重定向",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: ratings-route # Name for this VirtualService.\nspec:\n  hosts:\n  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. \n  http:\n  - match: # Match conditions to be satisfied for the route to be activated.\n    - uri: # Match requests whose URL path is exactly /v1/getProductRatings.\n        exact: /v1/getProductRatings\n    redirect: # Traffic will be directed to.\n      uri: /v1/bookRatings\n      authority: newratings.default.svc.cluster.local",
            "EnglishName": "HTTP redirect"
        },
        {
            "ChineseName": "HTTP重写",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: ratings-route # Name for this VirtualService.\nspec:\n  hosts:\n  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to. \n  http:\n  - match: # Match conditions to be satisfied for the route to be activated.\n    - uri: # Match requests whose URL path starts with /ratings.\n        prefix: /ratings\n    rewrite: # Replace /ratings with /v1/bookRatings.\n      uri: /v1/bookRatings\n    route:\n    - destination: # Uniquely identifies the instances of a service to which matched traffic should be forwarded to.\n        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.",
            "EnglishName": "HTTP rewrite"
        },
        {
            "ChineseName": "HTTP超时",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: ratings-route # Name for this VirtualService.\nspec:\n  hosts:\n  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.\n  http:\n  - timeout: 5s # Timeout of 5s for all traffic to ratings.prod.svc.cluster.local service.\n    route:\n    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.\n        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.",
            "EnglishName": "HTTP timeout"
        },
        {
            "ChineseName": "HTTP重试",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: ratings-route # Name for this VirtualService.\nspec:\n  hosts:\n  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.\n  http:\n  - route:\n    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.\n        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n    retries:\n      attempts: 3 # Try 3 times.\n      perTryTimeout: 2s # Timeout for each retry.\n      retryOn: gateway-error,connect-failure,refused-stream # Details at https://www.envoyproxy.io/docs/envoy/latest/configuration/http/http_filters/router_filter#x-envoy-retry-on",
            "EnglishName": "HTTP retry"
        },
        {
            "ChineseName": "HTTP请求延时故障注入",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: reviews-route # Name for this VirtualService.\nspec:\n  hosts:\n  - reviews.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.\n  http:\n  - match: # Match conditions to be satisfied for the route to be activated.\n    - sourceLabels: # Traffic from all pods with label env: prod\n        env: prod\n    route:\n    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.\n        host: reviews.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n        subset: v1 # The name of the service subset which is defined in DestinationRule.\n    fault:\n      delay:\n        percentage: # 5 second delay in 1 out of every 1000 requests.\n          value: 0.1\n        fixedDelay: 5s",
            "EnglishName": "HTTP fault injection of request delay"
        },
        {
            "ChineseName": "HTTP请求中止故障注入",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: ratings-route # Name for this VirtualService.\nspec:\n  hosts:\n  - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.\n  http:\n  - route:\n    - destination: # Uniquely identifies the instances of a service to which all traffic should be forwarded to.\n        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n        subset: v1 # The name of the service subset which is defined in DestinationRule.\n    fault:\n      abort:\n        percentage: # Return an HTTP 400 error code for 1 out of every 1000 requests.\n          value: 0.1\n        httpStatus: 400",
            "EnglishName": "HTTP fault injection of request abort"
        },
        {
            "ChineseName": "HTTP流量镜像",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: ratings-route # Name for this VirtualService.\nspec:\n  hosts:\n    - ratings.prod.svc.cluster.local # Service that this VirtualSerivce belongs to.\n  http:\n  - route:\n    - destination:\n        host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n        subset: v1\n      weight: 100\n    mirror: # All traffic to subset v1 will be mirrored to subset v2.\n      host: ratings.prod.svc.cluster.local # The name of a service from the service registry or ServiceEntry.\n      subset: v2\n    mirrorPercentage: # Percentage of the traffic to be mirrored by the `mirror` field.\n      value: 100.0",
            "EnglishName": "HTTP traffic mirroring"
        },
        {
            "ChineseName": "HTTP代理",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: bookinfo # Name for this VirtualService.\nspec:\n  hosts:\n  - \"bookinfo.com\" # Service that this VirtualSerivce belongs to.\n  gateways:\n  - mygateway # This VirtualSerice is only applied on Gateway of mygateway.\n  http:\n  - match: # Match conditions to be satisfied for the route to be activated.\n    - uri: # Match requests whose URL path is exactly /productpage.\n        prefix: \"/productpage\"\n    delegate:\n       name: productpage # The name of VirtualService to which matched traffic are forwarded. \n       namespace: nsA",
            "EnglishName": "HTTP delegate"
        },
        {
            "ChineseName": "TCP权重路由",
            "Yaml": "apiVersion: networking.istio.io/v1beta1\nkind: VirtualService\nmetadata:\n  name: tcp-echo # Name for this VirtualService.\nspec:\n  hosts:\n  - \"*\" # Service that this VirtualSerivce belongs to. \n  gateways:\n  - tcp-echo-gateway # This VirtualSerice is only applied on Gateway of tcp-echo-gateway.\n  tcp:\n  - match:\n    - port: 31400\n    route:\n    - destination:\n        host: tcp-echo\n        port:\n          number: 9000\n        subset: v1\n      weight: 80\n    - destination:\n        host: tcp-echo\n        port:\n          number: 9000\n        subset: v2\n      weight: 20",
            "EnglishName": "TCP weighted routing"
        }
    ]
}

错误码

HttpCode 错误码 错误信息 描述
404 ERR404 Not found 不存在

访问错误中心查看更多错误码。