Answers: <p>My approach would be to run the Jenkins container inside the k8s cluster (Kind in your case) in a pod (through a Deployment). You would then give permissions to the deployment using ClusterRole, ClusterRoleBinding and ServiceAccount to execute the commands you wish Jenkins to execute.</p>
  <p>Don't forget to set Quotas on your Jenkins pods.</p>
  
Answers: CC BY-SA 4.0
Answers: 2024-02-14T12:57:22.327Z
Answers: 2024-02-14T12:57:22.327Z
Answers: alban boitier
Body: <p>I am a beginner to devops and right now I'm learning jenkins. I have a kind cluster on my local machine and jenkins running inside a docker container at http://localhost:8000. I wish to execute the kubernetes commands liek 'kubectl get pods' in the cluster using my jenkins pipeline.</p>
  <p>The motive of doing this is to automate various steps in setting up a blockchain network using hlf operator. But I've found it very difficult to connect my jenkins to kubernetes.</p>
  <p>Things I have tried so far :</p>
  <ol>
  <li>I did try to upload the kubeconfig as a secret while adding a new cloud in jenkins. Still I get the following error .</li>
  </ol>
  <p><a href="https://i.sstatic.net/NH6Fj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/NH6Fj.png" alt="enter image description here" /></a></p>
  <p>I would appreciate any help regarding the same.</p>
  <p>Some additional questions :</p>
  <ol>
  <li>Is there a better tool suited for running kubernetes command ?</li>
  </ol>
  
Tags: <kubernetes><jenkins><jenkins-pipeline><jenkins-plugins><kubectl>
Title: Execute Kubernetes commands with Jenkins
UserDisplayName: Haaris Khatri
ThreadText: # Execute Kubernetes commands with Jenkins
  
  (Asked by: username_0 on 2024-02-14)
  
  I am a beginner to devops and right now I'm learning jenkins. I have a kind cluster on my local machine and jenkins running inside a docker container at http://localhost:8000. I wish to execute the kubernetes commands liek 'kubectl get pods' in the cluster using my jenkins pipeline.
  
  The motive of doing this is to automate various steps in setting up a blockchain network using hlf operator. But I've found it very difficult to connect my jenkins to kubernetes.
  
  Things I have tried so far :
  
  1. I did try to upload the kubeconfig as a secret while adding a new cloud in jenkins. Still I get the following error .
  
  [![enter image description here](https://i.sstatic.net/NH6Fj.png)](https://i.sstatic.net/NH6Fj.png)
  
  I would appreciate any help regarding the same.
  
  Some additional questions :
  
  1. Is there a better tool suited for running kubernetes command ?
  
  **Tags:** kubernetes, jenkins, jenkins-pipeline, jenkins-plugins, kubectl
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2024-02-14. Score: 0
  
  My approach would be to run the Jenkins container inside the k8s cluster (Kind in your case) in a pod (through a Deployment). You would then give permissions to the deployment using ClusterRole, ClusterRoleBinding and ServiceAccount to execute the commands you wish Jenkins to execute.
  
  Don't forget to set Quotas on your Jenkins pods.
  
  
  ---
  
  