<p>I have deployed an application into Kubernetes using the following command.</p>
<pre><code>kubectl apply -f deployment.yaml -n &lt;NAMESPACE&gt;
</code></pre>
<p>I have my deployment content in the deployment yaml file.</p>
<p>This is working fine. Now, I have updated few things in the deployment.yaml file and hence would like to update the deployment.</p>
<p><strong>Option 1:- Delete and deploy again</strong></p>
<pre><code>kubectl delete -f deployment.yaml -n &lt;NAMESPACE&gt;
kubectl apply -f deployment.yaml -n &lt;NAMESPACE&gt;
</code></pre>
<p><strong>Option 2:- Use set to update changes</strong></p>
<pre><code>kubectl set image deployment/nginx-deployment nginx=nginx:1.91
</code></pre>
<p>I don't want to use this approach as I am keeping my deployment.yaml file in GitHUB.</p>
<p><strong>Option 3:- Using edit command</strong></p>
<pre><code>kubectl edit deployment/nginx-deployment
</code></pre>
<p>I don't want to use the above 3 options.</p>
<p>Is there any way to update the deployment using the file itself.</p>
<p>Like,</p>
<pre><code>kubectl update deployment.yaml -n NAMESPACE
</code></pre>
<p>This way, I will make sure that I will always have the latest deployment file in my GitHub repo.</p>

<p>As @Daisy Shipton has said, what you want to do could be simplified with a simple command: <code>kubectl apply -f deployment.yaml</code>. </p>

<p><strong>I will also add that I don't think it's correct to utilize the <em>Option 2</em> to update the image utilized by the <code>Pod</code> with an imperative command!</strong> If the source of truth is the <code>Deployment</code> file present on your GitHub, you should simply update that file, by modifying the image that is used by your Pod's container there! </p>

<ul>
<li>Next time you desire to update your <code>Deployment</code> object, unless you don't forget to modify the .yaml file, you will be setting the Pods to use the previous Nginx's image.</li>
</ul>

<p>So there certainly should exist some restriction in using imperative commands to update the specification of any Kubernetes's object!</p>
