kubernetes 服务器上的 dry-run 错误

Ali*_*Ali 3 yaml kubernetes kubectl

和:

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

我收到错误:

Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.
Run Code Online (Sandbox Code Playgroud)

甚至还有:

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
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?

我正在使用 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"}
Run Code Online (Sandbox Code Playgroud)

我的集群版本是1.22.4

Mik*_*iak 5

我收到错误:

Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.
Run Code Online (Sandbox Code Playgroud)

这是正确的。该标志已被弃用。您需要使用--dry-run=server标志。欲了解更多信息,请查看此网站

至于第二个问题,k8s方面看来这是正确的。您可以在这里找到解释。如果您想解决问题,您需要删除字段creationTimestamp这个问题已经很好解释了。

  • 非常感谢...它现在像冠军一样工作... (2认同)