<p>I want to run my Jenkins behind k8s. We can achieve that with any standard helm chart or our own manifest files. In this case, Jenkins (master only) will run inside a container (Pod).</p>
<p>Now I also want to have a pipeline job that uses docker agent as described <a href="https://www.jenkins.io/doc/book/pipeline/docker/" rel="nofollow noreferrer">here</a></p>
<p>I am getting confused, about</p>
<ul>
<li>how and where this docker container will be run (on the same node where Jenkins is running? and suppose the node capacity is over then it needs to run docker agent on a different node)</li>
<li>how does Jenkins will authenticate to run containers on k8s nodes?</li>
<li>I saw the Kubernetes plugin/docker plugin. But those plugins create containers beforehand (<em>or at least we need to set up a template, which decides how containers will start, which image will be used and many more</em>) and connects Jenkins with help of JNLP / ssh. I lose the flexibility to have an image as an agent in that case.</li>
<li>going further, I also like to build custom images on the fly with help of Dockerfile shipped along with code. An example is available in the same <a href="https://www.jenkins.io/doc/book/pipeline/docker/" rel="nofollow noreferrer">link</a>.</li>
</ul>

Guru
<p>I believe this documentation is answering all of your questions: <a href="https://devopscube.com/jenkins-build-agents-kubernetes/" rel="nofollow noreferrer">https://devopscube.com/jenkins-build-agents-kubernetes/</a></p>
<p>With this method, you are not losing your flexibility because your Jenkins master going to create a K8s pod on the fly. Yes, additionally you need JNLP authentication but you can think of that as a sidecar container.</p>
<p>About your first question: If you use exactly that way, your Jenkins jobs going to run under Jenkins master with the same Docker that your Jenkins Master is using.</p>
