With:
kubectl apply -f web.yaml --server-dry-run --validate=false -o yaml
I get an error:
Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.
And even with:
kubectl apply -f web.yaml --dry-run=server --validate=false -o yaml
I get another error:
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
What should I do?
I'm using docker-desktop and my kubectl version is:
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"}
and my cluster version is 1.22.4
I get an error:
Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.
That's correct. This flag is deprecated. You need to use --dry-run=server
flag. For more look at this site.
As for the second problem, it seems that this is correct on the part of k8s. You can find the explanation here. If you want to resolve your problem you need to remove fields creationTimestamp
. It is well explained in this question.