【问题标题】:error with dry-run on the server in kubernetes在 kubernetes 的服务器上空运行时出错
【发布时间】:2022-01-03 17:13:43
【问题描述】:

与:

kubectl apply -f web.yaml --server-dry-run --validate=false -o yaml

我收到一个错误:

Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.

甚至:

kubectl apply -f web.yaml --dry-run=server --validate=false -o yaml

我收到另一个错误:

Warning: resource deployments/web is missing the kubectl.kubernetes.io/last-applied-configuration annotation which is required by kubectl apply. kubectl apply should only be used on resources created declaratively by either kubectl create --save-config or kubectl apply. The missing annotation will be patched automatically.
Error from server (Conflict): error when applying patch:
{"metadata":{"annotations":{"kubectl.kubernetes.io/last-applied-configuration":"{\"apiVersion\":\"apps/v1\",\"kind\":\"Deployment\",\"metadata\":{\"annotations\":{},\"creationTimestamp\":\"2021-12-30T08:51:06Z\",\"generation\":1,\"labels\":{\"app\":\"web\"},\"name\":\"web\",\"namespace\":\"default\",\"resourceVersion\":\"1589\",\"uid\":\"c2a4c20e-f55b-4113-b8e6-d2c19bb3e91c\"},\"spec\":{\"progressDeadlineSeconds\":600,\"replicas\":1,\"revisionHistoryLimit\":10,\"selector\":{\"matchLabels\":{\"app\":\"web\"}},\"strategy\":{\"rollingUpdate\":{\"maxSurge\":\"25%\",\"maxUnavailable\":\"25%\"},\"type\":\"RollingUpdate\"},\"template\":{\"metadata\":{\"creationTimestamp\":null,\"labels\":{\"app\":\"web\"}},\"spec\":{\"containers\":[{\"image\":\"nginx\",\"imagePullPolicy\":\"Always\",\"name\":\"nginx\",\"resources\":{},\"terminationMessagePath\":\"/dev/termination-log\",\"terminationMessagePolicy\":\"File\"}],\"dnsPolicy\":\"ClusterFirst\",\"restartPolicy\":\"Always\",\"schedulerName\":\"default-scheduler\",\"securityContext\":{},\"terminationGracePeriodSeconds\":30}}},\"status\":{}}\n"},"resourceVersion":"1589"}}
to:
Resource: "apps/v1, Resource=deployments", GroupVersionKind: "apps/v1, Kind=Deployment"
Name: "web", Namespace: "default"
for: "web.yaml": Operation cannot be fulfilled on deployments.apps "web": the object has been modified; please apply your changes to the latest version and try again

我该怎么办?

我正在使用 docker-desktop,我的 kubectl 版本是:

Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:48:33Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"darwin/amd64"}
Server Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.4", GitCommit:"b695d79d4f967c403a96986f1750a35eb75e75f1", GitTreeState:"clean", BuildDate:"2021-11-17T15:42:41Z", GoVersion:"go1.16.10", Compiler:"gc", Platform:"linux/amd64"}

我的集群版本是1.22.4

【问题讨论】:

  • 请指定kubectl和Kubernetes集群的版本
  • 我指定它,tnx

标签: kubernetes yaml kubectl


【解决方案1】:

我收到一个错误:

Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.

没错。此标志已弃用。您需要使用--dry-run=server 标志。更多请看at this site

至于第二个问题,这在k8s方面似乎是正确的。您可以找到explanation here。如果您想解决您的问题,您需要删除字段creationTimestamp。在this question 中有很好的解释。

【讨论】:

  • 非常感谢...它现在像冠军一样工作...
猜你喜欢
  • 2014-10-31
  • 2020-07-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-03
  • 1970-01-01
  • 1970-01-01
  • 2020-02-05
相关资源
最近更新 更多