<p><strong>Can't replicate <code>kubectl apply -f</code> functionality with Python client</strong></p>
<p>I have created a deployment using <code>create_namespced_deployment</code> (<a href="https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#create_namespaced_deployment" rel="nofollow noreferrer">https://github.com/kubernetes-client/python/blob/master/kubernetes/docs/AppsV1Api.md#create_namespaced_deployment</a>) in python.</p>
<p>But when I tried to update the deployment manually using <code>kubectl apply -f</code>, I am getting warning message like below</p>
<pre><code>Warning: resource deployments/fronend-deployment 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
</code></pre>
<p>I want to get rid of this warning message.Is there any other way?</p>
<p>I think the <code>create_namespced_deployment</code> method internally using <code>kubectl create -f</code> functionality.Is there any method that uses <code>kubectl apply -f</code>.</p>
<p>Let me know if you have any questions</p>

<p>In order to supply a full answer, let's start by explaining the difference between<br />
<code>kubectl apply</code> to <code>kubectl create</code></p>
<hr />
<h3><code>kubectl apply</code> vs <code>kubectl create</code></h3>
<p>The key difference between <code>kubectl apply</code> and <code>kubectl create</code> is that apply creates Kubernetes objects through a <strong>declarative</strong> syntax,
while the <code>create</code> command is <strong>imperative</strong>.</p>
<hr />
<p><a href="https://i.stack.imgur.com/7IHhi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7IHhi.jpg" alt="enter image description here" /></a></p>
<hr />
<h3><code>apply</code></h3>
<ul>
<li>The <code>kubectl apply</code> is a cli command used to create or modify Kubernetes resources defined in a <strong>manifest file</strong>.</li>
<li>Manifest file is referred to as <strong><code>Declarative</code></strong>.</li>
<li>Using a <strong><code>Declarative</code></strong> files we &quot;describe&quot; what should be our <strong>final</strong> state of our cluster (regarding the resources which we define)</li>
<li>The state of the resource is <strong>declared in the manifest file</strong> and this is where the name is coming from, then <code>kubectl apply</code> is used to implement that state.</li>
</ul>
<h3><code>create</code></h3>
<ul>
<li><p>In contrast to <code>apply</code>, the create command <code>kubectl create</code> is used for <strong>creating</strong> a Kubernetes resource directly. (for example: <code>kubectl create ns XXX</code> which will create a namespace.</p>
</li>
<li><p>This is an <strong>Imperative</strong> usage.</p>
</li>
<li><p>You can also use <code>kubectl create</code> with a manifest file to create a <strong>new instance</strong> of the resource. However, if the resource already exists, you should get an error 9but most likely K8S will tolerate it and you will not see the error in most cases).</p>
</li>
</ul>
<hr />
<p>Hopefully, now you can understand the errors you keep getting.</p>
