<p>With:</p>
<p><code>kubectl apply -f web.yaml --server-dry-run --validate=false -o yaml</code></p>
<p>I get an error:</p>
<pre><code>Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.
</code></pre>
<p>And even with:</p>
<p><code>kubectl apply -f web.yaml --dry-run=server --validate=false -o yaml</code></p>
<p>I get another error:</p>
<pre><code>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:
{&quot;metadata&quot;:{&quot;annotations&quot;:{&quot;kubectl.kubernetes.io/last-applied-configuration&quot;:&quot;{\&quot;apiVersion\&quot;:\&quot;apps/v1\&quot;,\&quot;kind\&quot;:\&quot;Deployment\&quot;,\&quot;metadata\&quot;:{\&quot;annotations\&quot;:{},\&quot;creationTimestamp\&quot;:\&quot;2021-12-30T08:51:06Z\&quot;,\&quot;generation\&quot;:1,\&quot;labels\&quot;:{\&quot;app\&quot;:\&quot;web\&quot;},\&quot;name\&quot;:\&quot;web\&quot;,\&quot;namespace\&quot;:\&quot;default\&quot;,\&quot;resourceVersion\&quot;:\&quot;1589\&quot;,\&quot;uid\&quot;:\&quot;c2a4c20e-f55b-4113-b8e6-d2c19bb3e91c\&quot;},\&quot;spec\&quot;:{\&quot;progressDeadlineSeconds\&quot;:600,\&quot;replicas\&quot;:1,\&quot;revisionHistoryLimit\&quot;:10,\&quot;selector\&quot;:{\&quot;matchLabels\&quot;:{\&quot;app\&quot;:\&quot;web\&quot;}},\&quot;strategy\&quot;:{\&quot;rollingUpdate\&quot;:{\&quot;maxSurge\&quot;:\&quot;25%\&quot;,\&quot;maxUnavailable\&quot;:\&quot;25%\&quot;},\&quot;type\&quot;:\&quot;RollingUpdate\&quot;},\&quot;template\&quot;:{\&quot;metadata\&quot;:{\&quot;creationTimestamp\&quot;:null,\&quot;labels\&quot;:{\&quot;app\&quot;:\&quot;web\&quot;}},\&quot;spec\&quot;:{\&quot;containers\&quot;:[{\&quot;image\&quot;:\&quot;nginx\&quot;,\&quot;imagePullPolicy\&quot;:\&quot;Always\&quot;,\&quot;name\&quot;:\&quot;nginx\&quot;,\&quot;resources\&quot;:{},\&quot;terminationMessagePath\&quot;:\&quot;/dev/termination-log\&quot;,\&quot;terminationMessagePolicy\&quot;:\&quot;File\&quot;}],\&quot;dnsPolicy\&quot;:\&quot;ClusterFirst\&quot;,\&quot;restartPolicy\&quot;:\&quot;Always\&quot;,\&quot;schedulerName\&quot;:\&quot;default-scheduler\&quot;,\&quot;securityContext\&quot;:{},\&quot;terminationGracePeriodSeconds\&quot;:30}}},\&quot;status\&quot;:{}}\n&quot;},&quot;resourceVersion&quot;:&quot;1589&quot;}}
to:
Resource: &quot;apps/v1, Resource=deployments&quot;, GroupVersionKind: &quot;apps/v1, Kind=Deployment&quot;
Name: &quot;web&quot;, Namespace: &quot;default&quot;
for: &quot;web.yaml&quot;: Operation cannot be fulfilled on deployments.apps &quot;web&quot;: the object has been modified; please apply your changes to the latest version and try again
</code></pre>
<p>What should I do?</p>
<p>I'm using docker-desktop and my kubectl version is:</p>
<pre><code>Client Version: version.Info{Major:&quot;1&quot;, Minor:&quot;22&quot;, GitVersion:&quot;v1.22.4&quot;, GitCommit:&quot;b695d79d4f967c403a96986f1750a35eb75e75f1&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-11-17T15:48:33Z&quot;, GoVersion:&quot;go1.16.10&quot;, Compiler:&quot;gc&quot;, Platform:&quot;darwin/amd64&quot;}
Server Version: version.Info{Major:&quot;1&quot;, Minor:&quot;22&quot;, GitVersion:&quot;v1.22.4&quot;, GitCommit:&quot;b695d79d4f967c403a96986f1750a35eb75e75f1&quot;, GitTreeState:&quot;clean&quot;, BuildDate:&quot;2021-11-17T15:42:41Z&quot;, GoVersion:&quot;go1.16.10&quot;, Compiler:&quot;gc&quot;, Platform:&quot;linux/amd64&quot;}
</code></pre>
<p>and my cluster version is <code>1.22.4</code></p>

<blockquote>
<p>I get an error:</p>
</blockquote>
<pre class="lang-yaml prettyprint-override"><code>Error: unknown flag: --server-dry-run
See 'kubectl apply --help' for usage.
</code></pre>
<p>That's correct. This flag is deprecated. You need to use <code>--dry-run=server</code> flag. For more look <a href="https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands#create" rel="nofollow noreferrer">at this site</a>.</p>
<p>As for the second problem, it seems that this is correct on the part of k8s. You can find the <a href="https://github.com/kubernetes/kubernetes/issues/84430#issuecomment-638376994" rel="nofollow noreferrer">explanation here</a>. If you want to resolve your problem you need to remove fields <code>creationTimestamp</code>. It is well explained in <a href="https://stackoverflow.com/questions/51297136/kubectl-error-the-object-has-been-modified-please-apply-your-changes-to-the-la">this question</a>.</p>
