<p>I am building an application which should execute tasks in a separate container/pods.
this application would be running in a specific namespace the new pods must be created in the same namespace as well.</p>
<p>I understand we can similar via custom CRD and Operators, but I found it is overly complicated and we need Golang knowledge for the same.</p>
<p>Is there any way this could be achived without having to learn Operators and GoLang?</p>
<p>I am ok to use <code>kubctl</code> or <code>api</code> within my container and wanted to connect the host and to the same namespace.</p>

Manish Bansal
<p>Yes, this is certainly possible using a <code>ServiceAccount</code> and then connecting to the API from within the Pod.</p>
<ul>
<li><p>First, create a <code>ServiceAccount</code> in your namespace using</p>
<pre><code>kubectl create serviceaccount my-service-account
</code></pre>
</li>
<li><p>For your newly created <code>ServiceAccount</code>, give it the permissions you want using <a href="https://kubernetes.io/docs/reference/access-authn-authz/rbac/" rel="nofollow noreferrer"><code>Roles</code> and <code>RoleBindings</code></a>. The subject would be something like this:</p>
<pre><code>subjects:
- kind: ServiceAccount
  name: my-service-account
  namespace: my-namespace
</code></pre>
</li>
<li><p>Then, add the <code>ServiceAccount</code> to the Pod from where you want to create other Pods from (see <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/" rel="nofollow noreferrer">documentation</a>). Credentials are automatically mounted inside the Pod using <code>automountServiceAccountToken</code>.</p>
</li>
<li><p>Now from inside the Pod you can either use <code>kubectl</code> or call the API using the credentials inside the Pod. There are libraries for a lot of programming languages to talk to Kubernetes, use those.</p>
</li>
</ul>
