before this question i used jenkins command line but it is not effective for me so i wanted to write something that automates the process but not from terminal. As i looked up i can create a pipeline or freestyle project, but i am new to this i could not understand the things that i see. Is there a way to automate this process?
This was my jenkins cli to delete the pods:
kubectl delete pod --field-selector=status.phase==Succeeded'
Can i generate this code and turn this to that will be applied in all projects and delete pods from openshift ?
Thanks for the help
Related
I am trying to move the complete eco-system of our SAAS product to Kubernetes (and use Docker containers).
I am supposed to give a bash script which will set up everything. Only manual intervention should be setting up the Kubernetes cluster and mounting Persistent Volumes.
We were using Jenkins for code deployment and cron jobs. I am able to create the Jenkins service but I can not find ways to configure it using the command line. Tried finding ways online but can not find any good documentation.
First welcome to kubernetes, second, there are a lot of tools, templates over there, I would recommend you to check what is Helm
This is the Jenkins chart if you want to check:
https://github.com/helm/charts/tree/master/stable/jenkins
There is also a "fork" of jenkins for containerized environments, that I like, you can check more about Jenkins-X here
You can use helm package manager and simply install the Jenkin stable version.
Before using helm you have to setup tiller on kubernetes cluster.
$ helm install --name my-release stable/jenkins
here stable version of jenkin using helm.
https://github.com/helm/charts/tree/master/stable/jenkins
I can add that you can store Jenkins home folder as well as plugins and artifacts folder on persistent volume and mount that volume to Jenkins pod as a part of Helm installation. You can also make daily snapshots/backups of Jenkins disk. In this way Jenkins deployment becomes very smooth, quick and reliable.
I am running Jenkins inside a Kubernetes cluster and setup to spawn an executor pod with 3 containers: jnlp, golang and kubectl.
Using "golang" container, I would like to be able to pull dependencies from github using "go install"
However, I am getting these errors (my code is in /go/src/test-app):
cannot find package "github.com/andreid/test-app/controllers"
cannot find package "github.com/sirupsen/logrus"
and it seems unable to pull from github (though that's where Jenkins is pulling my code from and it's configured to do that using a developer oauth key that I generated).
It seems that the "jnlp" container handles the pulling of code successfully.
What can I do to allow "go install" to work as expected?
Thanks!
For posterity: when running Jenkins in a Kubernetes cluster with all the proper paraphernalia (Kubernetes pod agents, etc), there's no straightforward way to do this. You might expect agents will pick up github credentials setup in Jenkins, but they don't.
A quick way is to create a secret containing a github access token and mounting it as the env var GITHUB_TOKEN in the golang container used in the execution pod. YOu will need to maintain that secret or use multiple secrets if you have pipelines with multiple needs.
Then, you need to run:
git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic#github.com/<myproject>".insteadOf "https://github.com/<myproject>" before doing build/get.
I have created a cluster using minikube which has 2 namespaces, dev and infra. dev contains my UI and backend apps while infra contains my Jenkins StatefulSet. I set Jenkins and added the Kubernetes plugin (v 1.1.3). Now I want to create a Jenkins job so that I can redeploy services in my dev namespace.
However, when my Jenkins job runs, I can see that it spins a new pod in the infra namespace as expected for the build, but this pod does not have access to the kubeconfig or the kubectl command. How do I promote builds in this case?
Here is my Kubernetes Cloud Configuration
And here is the console output of a sample job
The sample job above does nothing, I was just testing to make sure that it spins off a pod of its own every time it is run.
How can I use these Jenkins jobs now to redeploy my services/pods in the dev namespace?
this pod does not have access to the kubeconfig or the kubectl command
You need to use a jenkins agent docker image that has those commands
You also need that agent pod to use a service account that has permission to access the dev namespace if you want to change things there
I am running a Kubernetes cloud on which I am hosting Jenkins Master CI instances. My JM launches a builder Pod inside the cloud and kills that Pod after build is done (nothing unusual here). I am copying back the workspace on the master with the 'copy-to-slave' plugin. The problem is, I am not able to access my workspace after the build is done, even though the workspace sits on Jenkins Master (I can exec into the JM pod and I can see the workspace under $JENKINS_HOME/workspace/<job_name>. Is there any workaround regarding this? How can I access my workspace AFTER the build is done?
You need to run specific job at least once on the master. Don't know why such strange behavior, but after one run on master you will be able to see workspace
I've been struggling with setting up the Jenkins Kubernetes Plugin on the Google Container Engine.
I have the plugin installed but I think all my builds are still running on master.
I haven't found any good documentation or guides on configuring this.
UPDATE
I removed the master executor from my Jenkins image. So now my builds aren't running on master but now they have no executor so they don't run at all. Just waits in the queue forever.
You'll need to tell Jenkins how and where to run your builds by adding your Kubernetes cluster as a 'cloud' in the Jenkins configuration. Go to Manage Jenkins -> Configure System -> Cloud -> Add new cloud and select 'Kubernetes'. You'll find the server certificate key, user name and password in your local kubectl configuration (usually in ~/.kube/config). The values for 'Kubernetes URL' and 'Jenkins URL' depend on your cluster setup.
Next, you'll need to configure the docker images that should be used to run your builds by selecting 'Add Docker Template'. Use labels to define which tasks should be run with which image!
Here's a good video tutorial and here you'll find a nice tutorial which explains everything in detail.
The important bit after you've installed the plugin, set up access to your Kubernetes cluster, and set up your first Kubernetes Pod Template with a label like jnlp-slave, is that in your Jenkinsfile you need to begin with something like node('jnlp-slave') {}. Then the pod will be started when you trigger a build.
There's also a helm chart for easy deployment if that helps :)
This example might also help once you've set the plugin up too.