i am using jenkins kubernetes plugin.Configure it and testing a sample pipeline code as below:
podTemplate(containers: [
containerTemplate(name: 'ssh-client', image: 'kroniak/ssh-client:3.6', ttyEnabled: true, command: 'cat')
]) {
node(POD_LABEL) {
stage('container log') {
container('ssh-client') {
sshagent (credentials: ['ContainerExecDecoratorPipelineTest-sshagent']) {
sh 'env'
sh 'ssh-add -L'
sh 'ssh -vT -o "StrictHostKeyChecking=no" git@github.com'
}
}
}
}
}
while this is building i can check my kubernetes cluster and noticed that pods are creating but terminating also after few seconds. It keeps happening infinitely. I even checked with all other sample pipelines. The console output in Jenkins shows :
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] podTemplate
[Pipeline] {
[Pipeline] node
Created Pod: ns-jenkins/tests-14-zm889-hxd6p-j19bl
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Scheduled] Successfully assigned ns-jenkins/tests-14-zm889-hxd6p-j19bl to docker-desktop
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Pulling] Pulling image "kroniak/ssh-client:3.6"
Still waiting to schedule task
‘tests-14-zm889-hxd6p-j19bl’ is offline
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Pulled] Successfully pulled image "kroniak/ssh-client:3.6"
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Created] Created container ssh-client
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Started] Started container ssh-client
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Pulled] Container image "jenkins/inbound-agent:4.3-4" already present on machine
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Created] Created container jnlp
[Normal][ns-jenkins/tests-14-zm889-hxd6p-j19bl][Started] Started container jnlp
Created Pod: ns-jenkins/tests-14-zm889-hxd6p-23hwk
[Normal][ns-jenkins/tests-14-zm889-hxd6p-23hwk][Scheduled] Successfully assigned ns-jenkins/tests-14-zm889-hxd6p-23hwk to docker-desktop
[Normal][ns-jenkins/tests-14-zm889-hxd6p-23hwk][Pulled] Container image "kroniak/ssh-client:3.6" already present on machine
[Normal][ns-jenkins/tests-14-zm889-hxd6p-23hwk][Created] Created container ssh-client
[Normal][ns-jenkins/tests-14-zm889-hxd6p-23hwk][Started] Started container ssh-client
[Normal][ns-jenkins/tests-14-zm889-hxd6p-23hwk][Pulled] Container image "jenkins/inbound-agent:4.3-4" already present on machine
[Normal][ns-jenkins/tests-14-zm889-hxd6p-23hwk][Created] Created container jnlp
[Normal][ns-jenkins/tests-14-zm889-hxd6p-23hwk][Started] Started container jnlp
Created Pod: ns-jenkins/tests-14-zm889-hxd6p-wnxr9
[Normal][ns-jenkins/tests-14-zm889-hxd6p-wnxr9][Scheduled] Successfully assigned ns-jenkins/tests-14-zm889-hxd6p-wnxr9 to docker-desktop
[Normal][ns-jenkins/tests-14-zm889-hxd6p-wnxr9][Pulled] Container image "kroniak/ssh-client:3.6" already present on machine
[Normal][ns-jenkins/tests-14-zm889-hxd6p-wnxr9][Created] Created container ssh-client
[Normal][ns-jenkins/tests-14-zm889-hxd6p-wnxr9][Started] Started container ssh-client
[Normal][ns-jenkins/tests-14-zm889-hxd6p-wnxr9][Pulled] Container image "jenkins/inbound-agent:4.3-4" already present on machine
[Normal][ns-jenkins/tests-14-zm889-hxd6p-wnxr9][Created] Created container jnlp
[Normal][ns-jenkins/tests-14-zm889-hxd6p-wnxr9][Started] Started container jnlp
I had the same issue. I ran the command kubectl logs -l jenkins=slave -f
then I was able to identify the issue.
The issue was Failed to connect to jenkins-agent:50000
so I think the agent pod wasn't able to connect to jenkins-agent on port 50000.
I went to https://your-jenkins-domain.com/configureSecurity/
and set TCP port for inbound agents to 50000.
The issue is gone after I made that change
kubectl logs <jenkins-pod> --namespace=<jenkins-namespace>
is a good starting point to start debugging the issue.
When you define your Kubernetes clusters under Manage Jenkins -> Configure System -> Cloud -> Kubernetes Cloud Details
, does the Jenkins URL match the Endpoint address in kubectl describe service jenkins
?
The Endpoint address must match the Jenkins URL in the Kubernetes Cloud Details
kubectl describe service jenkins -n jenkins | grep Endpoint
Endpoints: 192.168.151.57:8080