'Jenkins pipeline to deploy on Kubernetes
Im still new to jenkins and kubernetes, I want to deploy a python app on my (minikube) kubernetes cluster. For that I have my Jenkins instance running inside my minikube cluster. My jenkinsfile looks like this,(Im not sure what type of agent I need to use to perform this job.)
def podTemplate = """
apiVersion: v1
kind: Pod
spec:
containers:
- name: jenkins-slave
image: jenkinsci/slave
command:
- sleep
args:
- infinity
"""
pipeline {
agent {
kubernetes {
yaml podTemplate
defaultContainer 'jenkins-slave'
}
}
stages {
stage('Deploy') {
steps {
container('jenkins-slave') {
script {
kubernetesDeploy(configs: "deployment.yaml", kubeconfigId: "myconfig")
}
}
}
}
}
}
But my pipeline always ends with this error.
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] container
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Deploy)
[Pipeline] container
[Pipeline] {
[Pipeline] script
[Pipeline] {
[Pipeline] kubernetesDeploy
Starting Kubernetes deployment
ERROR: ERROR: null
java.lang.NullPointerException
at com.microsoft.jenkins.kubernetes.KubernetesDeployContext.clientFactory(KubernetesDeployContext.java:284)
at com.microsoft.jenkins.kubernetes.command.DeploymentCommand.execute(DeploymentCommand.java:58)
at com.microsoft.jenkins.kubernetes.command.DeploymentCommand.execute(DeploymentCommand.java:45)
at com.microsoft.jenkins.azurecommons.command.CommandService.runCommand(CommandService.java:88)
at com.microsoft.jenkins.azurecommons.command.CommandService.execute(CommandService.java:96)
at com.microsoft.jenkins.azurecommons.command.CommandService.executeCommands(CommandService.java:75)
at com.microsoft.jenkins.azurecommons.command.BaseCommandContext.executeCommands(BaseCommandContext.java:77)
at com.microsoft.jenkins.kubernetes.KubernetesDeploy.perform(KubernetesDeploy.java:42)
at com.microsoft.jenkins.azurecommons.command.SimpleBuildStepExecution.run(SimpleBuildStepExecution.java:54)
at com.microsoft.jenkins.azurecommons.command.SimpleBuildStepExecution.run(SimpleBuildStepExecution.java:35)
at org.jenkinsci.plugins.workflow.steps.SynchronousNonBlockingStepExecution.lambda$start$0(SynchronousNonBlockingStepExecution.java:47)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
[Pipeline] }
[Pipeline] // script
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // container
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] }
[Pipeline] // podTemplate
[Pipeline] End of Pipeline
ERROR: Kubernetes deployment ended with HasError
Finished: FAILURE
I have another pipelines to build docker images that runs fine.
Solution 1:[1]
Download Kubernetes Continuous Plugin 1.0.0 version from https://updates.jenkins.io/download/plugins/kubernetes-cd/1.0.0/kubernetes-cd.hpi
To install downloaded file go to "Advanced" tab and then upload it to the "Deploy Plugin" section and then click "Deploy" button as shown below:

Then run manually:
docker stop <jenkins_container_ID_or_name>
docker start <jenkins_container_ID_or_name>
Then browse to your web browser to load the Jenkins server and click on "Build Now" of your Pipeline. This will resolve the above issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Milson |
