使用kubectl

时间:2018-05-25 21:29:09

标签: kubernetes kubectl istio

我正在尝试通过更改每个服务版本接收的流量比例来动态修补Istio的RouteRule。现在我跑的时候

kubectl describe routerule my-rule

我得到了描述:

Name:         my-rule
Namespace:    default
Labels:       <none>
Annotations:  kubectl.kubernetes.io/last-applied-configuration={"apiVersion":"config.istio.io/v1alpha2","kind":"RouteRule","metadata":{"annotations":{},"name":"my-rule","namespace":"default"},"spec":...
API Version:  config.istio.io/v1alpha2
Kind:         RouteRule
Metadata:
  Cluster Name:        
  Creation Timestamp:  2018-05-25T16:21:59Z
  Generation:          0
  Resource Version:    154906
  Self Link:           /apis/config.istio.io/v1alpha2/namespaces/default/routerules/my-rule
  UID:                 bfd78178-6037-11e8-8d5c-06f2e5b7e6b2
Spec:
  Destination:
    Name:  MyApp
  Match:
    Request:
      Headers:
        Uri:
          Prefix:  /MyApp/
  Rewrite:
    Uri:  /
  Route:
    Labels:
      Version:  v1
    Weight:     10
    Labels:
      Version:  v2
    Weight:     90

现在我想更改规则,以便90%的流量发送到v1,10%发送到v2:

kubectl patch routerule my-rule --type='json' -p='[{"op":"replace", "path":"/spec/route", "value":[{"labels":{"version":"v1"}, "weight": "90"}, {"labels":{"version":"v2"}, "weight": "10"}]}]'

当我运行此命令时,命令会以routerule.config.istio.io "my-rule" patched成功;如果我再次在我的规则上运行kubectl describe,我可以验证它是否具有更新的值:

...
Route:
Labels:
  Version:  v1
Weight:     90
Labels:
  Version:  v2
Weight:     10

然而,这实际上并没有生效。当我点击端点时,我仍然看到原始规则被应用(大部分流量被发送到v2)。关于可能导致这种情况的任何想法?我是否需要以某种方式通知Istio规则已经改变了?

1 个答案:

答案 0 :(得分:0)

愚蠢的错误 - 弄清楚我做错了什么:

"weight": "90"应该是"weight": 90(整数值而不是字符串)。但奇怪的是,Istio乐意从补丁中获取字符串值并应用它,即使它应该报告错误。我会等着看他们是否在飞行员的稳定释放中修复它,否则会引发PR。