使用“kn service update hello-example --request”设置资源限制时出错

问题描述

在 Knative in Action 中完成一些示例,并在尝试设置最低 CPI 和 RAM 时遇到以下错误

Omers-MacBook-Pro-2:Knative development$ kn service update hello-example --request 'cpu=500m,memory=256Mi'
Error: giving up after 3 retries: admission webhook "validation.webhook.serving.knative.dev" denied the request: validation Failed: Saw the following changes without a name change (-old +new): spec.template.Metadata.name
{*v1.RevisionTemplateSpec}.Spec.PodSpec.Containers[0].Resources.Requests:
    -: "map[]"
    +: "map[cpu:{i:{value:500 scale:-3} d:{Dec:<nil>} s:500m Format:DecimalSI} memory:{i:{value:268435456 scale:0} d:{Dec:<nil>} s: Format:BinarySI}]"

Run 'kn --help' for usage

我也尝试过(正如书中所建议的):

Omers-MacBook-Pro-2:Knative development$ kn service update hello-example --requests-cpu 500m --requests-memory 256Mi

但这种格式似乎已被弃用。

关于为什么这可能会失败的任何想法?

解决方法

我怀疑是 kn CLI 正在发送请求并且与 knative 服务的版本不兼容

确保 kn CLI 的版本与您安装的 knative 服务版本兼容。我建议使用相同的版本是安全的。

例如,我能够使用 kn CLI v0.21 使用 knative services v0.21 使您的示例工作

您可以通过kn version

查看
kn version

Version:      v0.21.0
Supported APIs:
- serving.knative.dev/v1 (knative-serving v0.21.0)

我使用 konk 和 kn CLI 来重现 从此处下载 kn CLI 二进制文件 v0.21 https://github.com/knative/client/releases/tag/v0.21.0 然后从这里安装种类 0.10 https://github.com/kubernetes-sigs/kind/releases/tag/v0.10.0

然后在 kind (konk) https://konk.dev 上安装 knative 不到 5 分钟

curl -sL get.konk.dev | bash

konk 附带一个服务和事件示例应用程序。

为资源请求运行更新命令

kn service update hello --request 'cpu=500m,memory=256Mi'

您将看到以下输出

Updating Service 'hello' in namespace 'default':

  0.053s The Configuration is still working to reflect the latest desired specification.
 11.497s Traffic is not yet migrated to the latest revision.
 11.608s Ingress has not yet been reconciled.
 11.829s Waiting for load balancer to be ready
 11.986s Ready to serve.

Service 'hello' updated to latest revision 'hello-00002' is available at URL:
http://hello.default.127.0.0.1.nip.io
,

您似乎正在尝试针对由旧版 kn 工具创建的服务向我们提供新版 kn 工具。在 release 0.21 中,有从客户端到服务器端命名支持的切换。

作为从客户端到服务器端命名的一次性转换,您可能需要运行:

kn service update hello-example --revision-name ""

如果您愿意,您可以将其与现有更新相结合:

kn service update hello-example --revision-name "" --request "cpu=500m,memory=256Mi"

请注意,清除客户端生成的修订名称​​将在服务器端创建一个新修订(并可能推出),因为该名称是服务器上修订模板的一部分。