Home > Blockchain >  Jenkins cron job to run selenium & k8s
Jenkins cron job to run selenium & k8s

Time:07-09

I am working on a project in which I have created a k8s cluster to run selenium grid locally. I want to schedule the tests to run and until now I have tried to create a Jenkins cron job to do so. For that I am using k8s plugin in Jenkins.

However I am not sure about the steps to follow. Where should I be uploading the kube config file? There are a few options here:

Build Environment in Jenkins

Any ideas or suggestions? Thanks

CodePudding user response:

Typically, you can choose any option, depending on how you want to manage the system, I believe:

  1. secret text or file option will allow you to copy/paste a secret (with a token) in Jenkins which will be used to access the k8s cluster. Token based access works by adding an HTTP header to your requests to the k8s API server as follows: Authorization: Bearer $YOUR_TOKEN. This authenticates you to the server. This is the programmatic way to access the k8s API.
  2. configure kubectl option will allow you to perhaps specify the config file within Jenkins UI where you can set the kubeconfig. This is the imperative/scriptive way of configuring access to the k8s API. The kubeconfig itself contains set of keypair based credentials that are issued to a username and signed by the API server's CA.

Any way would work fine! Hope this helps!

CodePudding user response:

If Jenkins is running in Kubernetes as well, I'd create a service account, create the necessary Role and RoleBinding to only create CronJobs, and attach your service account to your Jenkins deployment or statefulset, then you can use the token of the service account (by default mounted under /var/run/secrets/kubernetes.io/serviceaccount/token) and query your API endpoint to create your CronJobs.

However, if Jenkins is running outside of your Kubernetes cluster, I'd authenticate against your cloud provider in Jenkins using one of the plugins available, using:

  • Service account (GCP)
  • Service principal (Azure)
  • AWS access and secret key or with an instance profile (AWS).

and then would run any of the CLI commands to generate a kubeconfig file:

  • gcloud container clusters get-credentials
  • az aks get-credentials
  • aws eks update-kubeconfig
  • Related