<p>I am trying to deploy application on kubernetes cluster by using jenkins multi branch pipeline and "Jenkins file" but unable to  make connection between Jenkins and Kubernetes. From code side I can't share more details here. </p>

<p>I just want to know if there is any way to make this connection (Jenkins and Kubernetes) using Jenkins file so that I will use it to deploy the application on Kubernetes. </p>

<p>Following is the technology stack that might clear my issue:</p>

<ol>
<li><p>Jenkins file is kept at root location of project in git hub.</p></li>
<li><p>Separate jenkins server where pipeline is created to deploy the application on Kubernetes.</p></li>
<li><p>On premise kubernetes cluster.</p></li>
</ol>

Rahul
<p>You need credentials to talk to Kubernetes. When you have automation like Jenkins running jobs, it's best to create a service account for Jenkins, <a href="https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/" rel="nofollow noreferrer">look here for some documentation</a>. Once you create the Jenkins service account, you can extract an authentication token for that account, which you put into Jenkins. What I would recommend doing, since your Jenkins is not a pod inside your Kubernetes cluster is to upload a working kubectl config as a secret file in the Jenkins credential manager.</p>

<p>Then, in your Jenkins job configuration, you can use that secret. Jenkins can put the file somewhere for your job to access, then in your Jenkinsfile, you can run commands with "kubectl --kubeconfig= ...".</p>
