Getting accurate status of openshift pod deployment - jenkins

I have deployment stage in Jenkins which executes "oc patch" and "oc rollout" commands. These commands replaces docker image name in DeploymentConfig and rollout the changes in openshift.
As you can imagine, this is asynchronous call. It means in Jenkins I am not able to verify if newly deployed pod is running or failing. Jenkins just executes oc commands and proceeds to next stage execution. My requirement is I want to get the actual status of pod back in Jenkins to mark pipeline success/failed.
I could not find any oc or kubectl command which provides me exact status of deployment using synchronous call. As workaround I wrote shell script which checks the status of pod (using grep)for certain amount of time post "oc rollout" and send exit status back to Jenkins shell. I feel this is not correct method to do the deployment validation as my pipeline execution time is increased.
Do we have standard utility in openshift/kubernetes which can provide me exact status of pod post deployment on which I can rely and using which I can mark my deployment pipeline success/fail in Jenkins.
Please note, I am opening shell session in pipeline and executing oc cli commands on agent which has oc cli installed. This agent is not part of openshift cluster and Jenkins is sitting outside openshift cluster.

You have to use oc rollout status
Synopsis
oc rollout status
Description
Watch the status of the latest rollout, until it's done.

Related

Rolling updation with "kubectl apply" command

Currently I am practicing with Kubernetes resources like replicaSet , deployment and services. When I created my sample deployment and service for testing , I used kube apply command for creating the deployment and service into the Kubernetes cluster.That is properly working.
Now I am trying to make a end-to-end deployment using CI/CD pipeline. So when I am adding the deployment step in the Jenkinsfile , Can I use the kube apply command inside Jenkinsfile. Means If I am continuously committing in my SVN repo , changes will get update by using kube apply command? For each change I am making to repo need to reflect in deployment.
Can I use kube apply command for update also in Kubernetes ? Or Do I need to use rollout for updation of Kubernetes resource?
If I am continuously committing in my SVN repo , changes will get update by using kube apply command?
Ans:Yes
Below is the definition from kube document
Apply is a command that will update a Kubernetes cluster to match
state defined locally in files.
https://kubectl.docs.kubernetes.io/pages/app_management/apply.html

How to update k8s pods in another namespace using Jenkins - Minikube

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

How to trigger a Jenkins build after Deis deployment?

I have a test suite set up on a Jenkins server that I would like to be executed after an app's Docker deployment to Deis (on AWS) is complete. There doesn't appear to be any documentation around achieving this, so I'm wondering if there is anywhere in the Deis post-deployment process where I might be able to invoke a build so that I could test my app on Jenkins every time it is deployed to Deis--perhaps I could start the build with a curl command, like the following:
curl -X POST "http://jenkins.myserver.com/jenkins/job/PROJECT_NAME/buildWithParameters?APP_HOST=$host"
but I don't know where I would include this build trigger within Deis. Is there perhaps a way to include a shell script to customize actions to be taken after a deployment has finished? I've also looked for Jenkins plugins for Deis, but there appears to be none. Any advice is appreciated!
I came here looking for a Jenkins plugin for Deis too :)
Regarding your question (if still relevant to you) - IMHO this can be achieved by running the Deis deployment itself from a jenkins job - then when it's complete (and successful) - trigger another jenkins job or step for the testing.

Setting up the Kubernetes Plugin on Jenkins

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.

How do I pass on my build file from Jenkins to Saltstack master

We have a Jenkins system to automate build from Github, now we are implementing a Saltstack system. So I need to integrate my Jenkins with Salt-master so that it passes all the new builds to the master which then sends it across the salt-clients(minions).
The saltstack setup is in AWS cloud and and the Jenkins machine is outside the cloud in a local setup.
You could enable the salt-api and using the following plugin: https://wiki.jenkins-ci.org/display/JENKINS/saltstack-plugin then all of your jenkins builds can execute states / orchestrations etc. to any minions on a per job basis.
Another way of doing this is to have a minion running on the salt-master and install the jenkins slave on the same box. Then restrict the jenkins jobs to that jenkins slave and execute the commands as if you were at the command line. NOTE: this option requires a bit more configuration.

Resources