<p>I found specifying like <code>kubectl --context dev --namespace default {other commands}</code> before kubectl client in many examples. Can I get a clear difference between them in a k8's environment?</p>

Kishor Unnikrishnan
<p>The kubernetes concept (and term) <strong>context</strong> only applies in the kubernetes client-side, i.e. the place where you run the kubectl command, e.g. your command prompt.
The kubernetes server-side doesn't recognise this term 'context'.</p>
<p>As an example, in the command prompt, i.e. as the client:</p>
<ul>
<li>when calling the <code>kubectl get pods -n dev</code>, you're
retrieving the list of the pods located under the namespace 'dev'.</li>
<li>when calling the <code>kubectl get deployments -n dev</code>, you're
retrieving the list of the deployments located under the namespace 'dev'.</li>
</ul>
<p>If you know that you're targetting basically only the 'dev' namespace at the moment, then instead of adding &quot;-n dev&quot; all the time in each of your kubectl commands, you can just:</p>
<ol>
<li>Create a context named 'context-dev'.</li>
<li>Specify the namespace='dev' for this context.</li>
<li>Set the current-context='context-dev'.</li>
</ol>
<p>This way, your commands above will be simplified to as followings:</p>
<ul>
<li><code>kubectl get pods</code></li>
<li><code>kubectl get deployments</code></li>
</ul>
<p>You can set different contexts, such as 'context-dev', 'context-staging', etc., whereby each of them is targeting different namespace. BTW it's not obligatory to prefix the name with 'context'. You can just set the name with 'dev', 'staging', etc.</p>
<p>Just as an analogy where a group of people are talking about films. So somewhere within the conversation the word 'Rocky' was used. Since they're talking about films, it's clear and there's no ambiguity that 'Rocky' here refers to the boxing film 'Rocky' and not about the &quot;bumpy, stony&quot; terrains. It's redundant and unnecessary to mention 'the movie Rocky' each time. Just one word, 'Rocky', is enough. The context is obviously about film.</p>
<p>The same thing with Kubernetes and with the example above. If the context is already set to a certain cluster and namespace, it's redundant and unnecessary to set and / or mention these parameters in each of your commands.</p>
<p>My explanation here is just revolving around namespace, but this is just an example. Other than specifying the namespace, within the context you will actually also specify which cluster you're targeting and the user info used to access the cluster. You can have a look inside the ~/.kube/config file to see what information other than the namespace is associated to each context.</p>
<p>In the sample command in your question above, both the namespace and the context are specified. In this case, <code>kubectl</code> will use whatever configuration values set within the 'dev' context, but the <code>namespace</code> value specified within this context (if it exists) will be ignored as it will be overriden by the value explicitly set in the command, i.e. 'default'.</p>
<p>Meanwhile, the <strong>namespace</strong> concept is used in both sides: server and client sides. It's a logical grouping of Kubernetes objects. Just like how we group files inside different folders in Operating Systems.</p>
