Kubernetes 部署错误:未知标志:--replicas 问题

Ash*_*shu 2 kubernetes

使用命令创建部署时

kubectl create deploy nginx --image=nginx:1.7.8 --replicas=2 --port=80
Run Code Online (Sandbox Code Playgroud)

我收到错误 Error: unknown flag: --replicas

controlplane $ kubectl version
Client Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:58:59Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"18", GitVersion:"v1.18.0", GitCommit:"9e991415386e4cf155a24b1da15becaa390438d8", GitTreeState:"clean", BuildDate:"2020-03-25T14:50:46Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}
controlplane $ kubectl create deploy nginx --image=nginx:1.7.8 --replicas=2 --port=80
Error: unknown flag: --replicas
See 'kubectl create deployment --help' for usage.
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题,因为这个命令正在其他 Kubernetes 集群上工作?

小智 11

您可以尝试在 -- 和命令之间放置一个空白字符例如

kubectl 创建部署 nginx --image=nginx:1.7.8 --replicas=2

这对我来说是工作。

  • 这是一个不好的建议,`--` 之后的关键字是“命令”的一部分。将 `replicas=2` 放在那里只会在容器的 shell 中设置变量“replicas”,这没有任何效果 (5认同)
  • 它对我有用..为什么会发生这种情况? (3认同)
  • 之前: kubectl run nginx --image=nginx:1.15.12-alpine --generator=run-pod/v1 之后: kubectl run nginx --image=nginx:1.15.12-alpine --generator=run-pod/v1谢谢!!! (2认同)

Kri*_*sia 7

看起来像这样,--replicas并且根据发行说明--port在版本中添加了标志,这就是您看到错误的原因。1.19v1-19

因此,您需要最低版本1.19才能将replicasport标志用作kubectl create deployment命令的一部分。

但是,您可以kubectl scale/expose在创建部署后使用该命令。

对于相关的PR链接replicasport

  • 我在 kubectl 1.23 中看到此错误 (4认同)