<p>Background: I have two deployments in my k8s cluster called (as an example) the following:</p>
<pre><code>foo-bar
foo-bar-asd
</code></pre>
<p>In my pipeline, I want to implement logic which checks if there's any deployments named &quot;foo-bar&quot; already deployed.</p>
<p>How do I construct my command to only fetch/output &quot;foo-bar&quot;, and not &quot;foo-bar-asd&quot; ?</p>
<p>I've tried toying around with regex, '^foo-bar$' etc without any success, found through googling/similar stackoverflow-questions.</p>
<p>My current command (which fetches both):</p>
<pre><code>kubectl -n my-namespace get deployments | grep foo-bar 
</code></pre>
<p>Thank you in advance for any help!</p>
<p>Edit:
Realized beggars can't be choosers, <em>but</em> on top of just fetching &quot;foo-bar&quot; I would need the command to not explicitly mention &quot;foo-bar-asd&quot;.
(Building a pipeline where this command is to be placed, and is supposed to be generic for different apps. Does not explain fully, but hopefully a little.)</p>

Erik Jönelid
<p><code>grep</code> command can also exclude certain string. You can run something like</p>
<p><code>kubectl -n my-namespace get deployments | grep foo-bar | grep -v  foo-bar-asd</code></p>
<p>This should show you what you are looking for.</p>
