<p>I can get the ReplicaSet if given the <code>replica-set-name</code> using the api as below:</p>

<pre><code>GET /apis/apps/v1/namespaces/{namespace}/replicasets/{name}
</code></pre>

<p>But how can I get the ReplicaSet based on the deployment?</p>

<p>Any help is appreciated.</p>

<p>Thank you</p>

surazzarus
<blockquote>
  <p>But how can I get the ReplicaSet based on the deployment?</p>
</blockquote>

<p>With quite some gymnastics... If you inspect how <code>kubectl</code> does it (by executing <code>kubectl -n my-namespace describe deploy my-deployment --v=9</code>) you will see that it dos the following:</p>

<ul>
<li>first gets deployment details with: <code>/apis/extensions/v1beta1/namespaces/my-namespace/deployments/my-deployment</code>. From there it gets labels for replicaset selection. </li>
<li>then gets replicaset details using labels from deployment in previous step (say labels were <code>my-key1:my-value1</code> and <code>my-key2:my-value2</code>) like so: <code>/apis/extensions/v1beta1/namespaces/my-namespace/replicasets?labelSelector=my-key1%3Dmy-value1%2Cmy-key2%3Dmy-value2</code></li>
</ul>

<p>Funny part here begins with extracting multiple labels from deployment output and formatting them for replicaset call, and that is task for grep, awk, jq or even python, depending on your actual use case (from bash, python, some client or whatever...)</p>
