Istio:蓝色/绿色部署 [英] Istio: Blue/green deployment
问题描述
我可以创建一种流量策略,以在不同kubernetes命名空间中运行的服务之间路由流量吗?
Could I create an traffic strategy in order to route traffic between services running in different kubernetes' namespaces?
当前,我的测试服务位于staging
命名空间.另一方面,我在生产环境中的服务位于production
命名空间上.
Currently, my testing service is located at staging
namespace. By other hand, my service in production are on production
namespace.
我想平衡位于staging
命名空间和production
命名空间的服务之间的流量.因此,将10%分配给staging:service
,将90%分配给production:service
.
I'd like to balance traffic between service located in staging
namespace and production
namespace. So, 10% goes to staging:service
and 90% goes to production:service
.
到目前为止,我已经能够创建虚拟服务和目标规则,但是两个服务都在同一个命名空间中运行.
Up to now, I've been able to create a virtual service and a destination rule, but both services running inside the same namespace.
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
creationTimestamp: null
name: recommendation
namespace: istio-project
spec:
host: recommendation
subsets:
- labels:
version: v1
name: version-v1
- labels:
version: v2
name: version-v2
还有一个VirtualService
:
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
creationTimestamp: null
name: recommendation
namespace: istio-project
spec:
hosts:
- recommendation
http:
- route:
- destination:
host: recommendation
subset: version-v1
weight: 75
- destination:
host: recommendation
subset: version-v2
weight: 25
此配置是在istio-project
名称空间内运行的两个服务之间的平衡.
This configuration is balancin between both services running inside istio-project
namespace.
有什么想法吗?
编辑
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
creationTimestamp: null
name: recommendation
namespace: istio-project
spec:
hosts:
- recommendation
http:
- route:
- destination:
host: recommendation
weight: 75
- destination:
host: recommendation.istio-project-two.svc.cluster.local
weight: 25
---
推荐答案
有什么想法吗?
Any ideas?
您是否尝试过使用FQDN来覆盖跨命名空间的Pod.格式为servicename.namespace.svc.cluster.local
.在 istio文档中,针对VirtualServices的示例中将其引用为:
Did you try with FQDN to cover for cross-namespace pods. It is in format servicename.namespace.svc.cluster.local
. In the istio documentation for VirtualServices this is referenced in their example as:
spec:
hosts:
- ratings.prod.svc.cluster.local
在该特定示例中,其中ratings
是服务名称,prod
是名称空间.他们还列出:
where ratings
would be service name, prod
would be namespace in that particular example. Also they list:
...
namespace: foo
spec:
host: reviews # interpreted as reviews.foo.svc.cluster.local
...
以交叉命名空间为例:
...
spec:
hosts:
- productpage.prod.svc.cluster.local # ignores rule namespace
...
在文档的其他部分中,他们专门建议Kubernetes用户使用FQDN,引用:
In the other part of documentation they specifically suggest usage of FQDN for Kubernetes users, quote:
Kubernetes用户的注意事项:当使用短名称(例如,使用"reviews"而不是"reviews.default.svc.cluster.local")时,Istio将根据规则的名称空间而不是服务来解释该短名称.包含主机评论"的默认"命名空间中的规则将被解释为"reviews.default.svc.cluster.local",而不管与评论服务关联的实际命名空间如何.为避免可能的错误配置,建议始终使用完全限定的域名代替短名称.
Note for Kubernetes users: When short names are used (e.g. "reviews" instead of "reviews.default.svc.cluster.local"), Istio will interpret the short name based on the namespace of the rule, not the service. A rule in the "default" namespace containing a host "reviews will be interpreted as "reviews.default.svc.cluster.local", irrespective of the actual namespace associated with the reviews service. To avoid potential misconfigurations, it is recommended to always use fully qualified domain names over short names.
如果我正确理解了您的配置,您将需要:recommendation.staging.svc.cluster.local
和recommendation.production.svc.cluster.local
分别作为在命名空间之间路由的主机.
If I understand your configuration correctly you would need: recommendation.staging.svc.cluster.local
and recommendation.production.svc.cluster.local
respectively as hosts to route across namespaces.
如果您想按所述百分比将recommendation.istio-project.svc.cluster.local
路由到在其中运行的pod和recommendation.istio-project-two.svc.cluster.local
服务,则可以,这看起来像是有效的配置.
If you would like to route recommendation.istio-project.svc.cluster.local
to pods running in that and recommendation.istio-project-two.svc.cluster.local
services in said percentages then yes, this looks like valid config.
这篇关于Istio:蓝色/绿色部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!