【问题标题】:Why does simple kubectl(1.16) run show an error?为什么 simple kubectl(1.16) 运行会显示错误?
【发布时间】:2019-12-04 21:44:49
【问题描述】:

kubectl 版本

$ kubectl version
Client Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.3", GitCommit:"b3cbbae08ec52a7fc73d334838e18d17e8512749", GitTreeState:"clean", BuildDate:"2019-11-18T14:56:51Z", GoVersion:"go1.12.13", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"16", GitVersion:"v1.16.2", GitCommit:"c97fe5036ef3df2967d086711e6c0c405941e14b", GitTreeState:"clean", BuildDate:"2019-10-15T19:09:08Z", GoVersion:"go1.12.10", Compiler:"gc", Platform:"linux/amd64"}

错误 当我运行kubectl run 时,出现错误。

$ kubectl run nginx --image=nginx
WARNING: New generator "deployment/apps.v1" specified, but it isn't available. Falling back to "run/v1".
kubectl run --generator=deployment/apps.v1 is DEPRECATED and will be removed in a future version. Use kubectl run --generator=run-pod/v1 or kubectl create instead.
error: no matches for kind "Deployment" in version "apps/v1"

这似乎是由新版本(1.16.x)引起的,不是吗? 据我搜索,即使是官方文件也没有明确提到与这种情况有关的事情。如何使用kubectl run

【问题讨论】:

  • 为部署编写一个 YAML 文件,将其签入源代码控制,然后使用 kubectl apply 安装它几乎总是更好;尽量避免使用kubectl run,一次性调试 Pod 除外。话虽如此,这种输出看起来像是您的集群已损坏,并且修复这不是 SO 关注的那种编程问题。
  • @DavidMaze 感谢您的建议!但是,k8s 教程告诉读者这样做(kubectl run),因此出现错误很奇怪。
  • 这很奇怪。你的 Kubernetes 版本是什么?我会说你的kubectl 是比你的 kubernetes 集群更新的版本,所以在你的集群上,它仍然期望以deployment/v1beta1 进行部署,但是kubectl 正在尝试使用提升的deployment/apps.v1@987654332 创建部署@.

标签: kubernetes kubectl


【解决方案1】:

试试

kubectl create deployment --image nginx my-nginx

【讨论】:

    【解决方案2】:

    正如kubectl Usage Conventions 建议的那样,

    指定 --generator 标志以固定到特定行为,当您 使用基于生成器的命令,例如 kubectl run 或 kubectl expose

    请改用kubectl run --generator=run-pod/v1 nginnnnnnx --image nginx

    还有@soltysh describes well enough 为什么最好使用kubectl create 而不是kubectl run

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-08
      • 1970-01-01
      • 2022-06-26
      • 1970-01-01
      • 2021-03-16
      • 2021-01-21
      • 2017-01-16
      相关资源
      最近更新 更多