loading...

Jenkins pipeline failed trying to deploy to Kubernetes, help!!

marluanguerrero profile image Marluan Espirituanto ・1 min read

Im trying to make a CI/CD with a Jenkins Pipeline. The steps are:

  • Clone git repository
  • Build application (Node app) npm install
  • Run tests npm run tests
  • Build Docker image
  • Push Docker image to Azure container registry
  • Deploy to Kubernetes kubectl create -f app-deployment.yml -v=8

This is the Jenkins file structure:

node {

    def gitRepo = 'http://repositoryurl.git'
    def DOCKER_IMAGE_NAME

    stage('Clone repository') {
        try {
            checkout scm
        } catch (e) {
            notify("Something failed while trying to clone the repository")
            throw e;
        } 
    }

    stage('Install dependencies') {
        try{
            sh 'npm install'
        } catch(e){
            notify("Something failed while installing dependecies")
            throw e;
        }
    }

    stage('Run tests') {
        try{
            sh 'npm run test'
            if (currentBuild.result.equals("FAILURE")) {
                throw "Test results did not pass thresholds"
            }
        } catch(e){
            notify("Some tests failed")
            throw e;
        }
    }

    stage('Build Docker Image'){
        try{
            DOCKER_IMAGE_NAME="docker image name"
            sh 'docker build . -t ' + DOCKER_IMAGE_NAME
        } catch(e) {
            notify("Something failed building Docker Image")
            throw e;
        }
    }

    stage('Push image to container registry'){
        try{
            sh('docker login ${CONTAINER_REGISTRY_SERVER} -u ${CONTAINER_REGISTRY_USERNAME} -p ${CONTAINER_REGISTRY_PASSWORD}')
            sh('docker push ' + DOCKER_IMAGE_NAME)
        } catch(e) {
            notify("Something failed pushing Docker Image")
            throw e;
        }
    }


    // here the error occurs
    stage('Kubernetes Setup'){
        try{
            sh("kubectl create -f app-deployment.yml -v=8")
        } catch(e) {
            notify("Something failed Kubernetes Setup")
            throw e;
        }
    }

    notify("Process finish")
}

def notify(String message) {
  slackSend (color: '#FFFF00', message: "${message}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]' (${env.BUILD_URL})")
}

Jenkins pipeline console output:

Jenkins project configuration

I would appreciate your help !

Discussion

markdown guide
 

It's hard to tell without having a look at your app-deployment.yml, but my guess is : It seems that you have a step in your deployment to access swagger endpoint, but at that point the pod is not alive yet, so that's why it gives a 404. You may want to check kubernetes.io/docs/tasks/configure...

 

Here an example of my app-deployment.yml

Jenkins project configuration

I apreciate your help :(

 

I still don't see swagger here. Can you maybe search in that directory for "swagger" to see where this

http://localhost:8000/swagger-2.0.0.pb-v1

comes from ?

I'll tell you what the problem really is:
This is my local enviroment:

  1. Ubuntu server
  2. I have the following installed on the server:
    • Docker
    • Minikube and kubectl http://172.27.136.180:30000
    • Jenkins http://172.27.136.180:8080

I made kubectl and minikube installation following the official documentation: Kubernetes documentation . The same with Jenkins

The idea is to create a CI and cd with a Jenkins pipeline. You can see the project structure here, in Kubernetes setup pipeline you can see that I execute sh("kubectl get nodes -v=8") for a simple test, I got the same error: Error from server (NotFound): the server could not find the requested resource

This is the log Jenkins Pipeline log:

Started by GitLab push by Marluan Guerrero
Obtained Jenkinsfile from git http://archdev-repo.csid.local/M.Guerrero/FacebookAutocampaignApi.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] node
Running on Jenkins in /var/lib/jenkins/workspace/facebook-pipeline
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Kubernetes Setup)
[Pipeline] sh
[facebook-pipeline] Running shell script
+ kubectl get nodes -v=8
I0706 05:48:21.019414   48887 round_trippers.go:414] GET http://localhost:8080/api
I0706 05:48:21.019438   48887 round_trippers.go:421] Request Headers:
I0706 05:48:21.019444   48887 round_trippers.go:424]     Accept: application/json, */*
I0706 05:48:21.019449   48887 round_trippers.go:424]     User-Agent: kubectl/v1.9.2 (linux/amd64) kubernetes/5fa2db2
I0706 05:48:21.023245   48887 round_trippers.go:439] Response Status: 302 Found in 3 milliseconds
I0706 05:48:21.023296   48887 round_trippers.go:442] Response Headers:
I0706 05:48:21.023302   48887 round_trippers.go:445]     Server: Jetty(9.4.z-SNAPSHOT)
I0706 05:48:21.023307   48887 round_trippers.go:445]     Date: Fri, 06 Jul 2018 12:48:21 GMT
I0706 05:48:21.023311   48887 round_trippers.go:445]     X-Content-Type-Options: nosniff
I0706 05:48:21.023316   48887 round_trippers.go:445]     Location: http://localhost:8080/api/
I0706 05:48:21.023344   48887 round_trippers.go:445]     Content-Length: 0
I0706 05:48:21.026555   48887 round_trippers.go:414] GET http://localhost:8080/api/
I0706 05:48:21.026566   48887 round_trippers.go:421] Request Headers:
I0706 05:48:21.026572   48887 round_trippers.go:424]     Accept: application/json, */*
I0706 05:48:21.026577   48887 round_trippers.go:424]     Referer: http://localhost:8080/api
I0706 05:48:21.026581   48887 round_trippers.go:424]     User-Agent: kubectl/v1.9.2 (linux/amd64) kubernetes/5fa2db2
I0706 05:48:21.029608   48887 round_trippers.go:439] Response Status: 200 OK in 3 milliseconds
I0706 05:48:21.029626   48887 round_trippers.go:442] Response Headers:
I0706 05:48:21.029632   48887 round_trippers.go:445]     Cache-Control: no-cache,no-store,must-revalidate
I0706 05:48:21.029637   48887 round_trippers.go:445]     Content-Type: text/html;charset=utf-8
I0706 05:48:21.029652   48887 round_trippers.go:445]     X-Hudson: 1.395
I0706 05:48:21.029657   48887 round_trippers.go:445]     X-Jenkins: 2.121.1
I0706 05:48:21.029663   48887 round_trippers.go:445]     X-Jenkins-Session: 86df52bf
I0706 05:48:21.029668   48887 round_trippers.go:445]     Server: Jetty(9.4.z-SNAPSHOT)
I0706 05:48:21.029673   48887 round_trippers.go:445]     X-Content-Type-Options: nosniff
I0706 05:48:21.029677   48887 round_trippers.go:445]     X-Hudson-Theme: default
I0706 05:48:21.029681   48887 round_trippers.go:445]     Set-Cookie: JSESSIONID.0f618009=node07cmbl5d9dj4y1nvjus4dap5li33.node0;Path=/;HttpOnly
I0706 05:48:21.029686   48887 round_trippers.go:445]     Date: Fri, 06 Jul 2018 12:48:21 GMT
I0706 05:48:21.029691   48887 round_trippers.go:445]     X-Frame-Options: sameorigin
I0706 05:48:21.029695   48887 round_trippers.go:445]     X-Instance-Identity: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAldVNd+iX90mzH46u69reLk9FXpjrAIwkYev7KUtb4Au+mVBaBDSXAfHxMUXHkNJCr3I1t8hAlOg3x4x4h1nmn+GZJ+58at20eh7q/w7UKds5VvHrp2tyoll4DScjGPTQW2rrj7/f93wlpVNWYXDNhJG6s/4PWVOy2gmSAlZ+75uqAuvEf1yGkAOepLZkyUwce5DxnjfgIJ6/DOE53EKShxxUUPMMJn6tvzHzRcUG2EbFcBXIXWvQbAkcxCnVUfXJ4ronC8yn44ZudOgiM9hFnbfI1p3T12mx59AON0K9aFirUPXRkI6zIK/3Sbsa1pzhNpiVKvoAkanMzip2putb5wIDAQAB
I0706 05:48:21.029702   48887 round_trippers.go:445]     Expires: Thu, 01 Jan 1970 00:00:00 GMT
I0706 05:48:21.030096   48887 request.go:873] Response Body: 





  <!DOCTYPE html><html><head resURL="/static/86df52bf" data-rooturl="" data-resurl="/static/86df52bf">

 <!DOCTYPE html><html><head resURL="/static/86df52bf" data-rooturl="" data-resurl="/static/86df52bf">


    <title>Remote API [Jenkins]</title><link rel="stylesheet" href="/static/86df52bf/css/layout-common.css" type="text/css" /><link rel="stylesheet" href="/static/86df52bf/css/style.css" type="text/css" /><link rel="stylesheet" href="/static/86df52bf/css/color.css" type="text/css" /><link rel="stylesheet" href="/static/86df52bf/css/responsive-grid.css" type="text/css" /><link rel="shortcut icon" href="/static/86df52bf/favicon.ico" type="image/vnd.microsoft.icon" /><link color="black" rel="mask-icon" href="/images/mask-icon.svg" /><script>var isRunAsTest=false; var rootURL=""; var resURL="/static/86df52bf";</script><script src="/static/86df52bf/scripts/prototype.js" type="text/javascript"></script><script src="/static/86df52bf/scripts/behavior.js" type="text/javascript"></script><script src='/adjuncts/86df52bf/org/kohsuke/stapler/bind.js' type='text/javascript'></script><script src="/static/86df [truncated 11255 chars]
I0706 05:48:21.055509   48887 cached_discovery.go:124] skipped caching discovery info due to yaml: line 11: mapping values are not allowed in this context
I0706 05:48:21.055533   48887 factory_object_mapping.go:93] Unable to retrieve API resources, falling back to hardcoded types: yaml: line 11: mapping values are not allowed in this context
I0706 05:48:21.056384   48887 round_trippers.go:414] GET http://localhost:8080/api/v1/nodes?limit=500
I0706 05:48:21.056402   48887 round_trippers.go:421] Request Headers:
I0706 05:48:21.056413   48887 round_trippers.go:424]     Accept: application/json
I0706 05:48:21.056423   48887 round_trippers.go:424]     User-Agent: kubectl/v1.9.2 (linux/amd64) kubernetes/5fa2db2
I0706 05:48:21.056966   48887 round_trippers.go:439] Response Status: 404 Not Found in 0 milliseconds
I0706 05:48:21.056982   48887 round_trippers.go:442] Response Headers:
I0706 05:48:21.056992   48887 round_trippers.go:445]     X-Content-Type-Options: nosniff
I0706 05:48:21.057002   48887 round_trippers.go:445]     Cache-Control: must-revalidate,no-cache,no-store
I0706 05:48:21.057010   48887 round_trippers.go:445]     Content-Length: 0
I0706 05:48:21.057019   48887 round_trippers.go:445]     Server: Jetty(9.4.z-SNAPSHOT)
I0706 05:48:21.057027   48887 round_trippers.go:445]     Date: Fri, 06 Jul 2018 12:48:21 GMT
I0706 05:48:21.057055   48887 request.go:873] Response Body: 
I0706 05:48:21.057330   48887 helpers.go:201] server response object: [{
  "metadata": {},
  "status": "Failure",
  "message": "Unable to list \"nodes\": the server could not find the requested resource (get nodes)",
  "reason": "NotFound",
  "details": {
    "kind": "nodes",
    "causes": [
      {
        "reason": "UnexpectedServerResponse"
      }
    ]
  },
  "code": 404
}]
F0706 05:48:21.057368   48887 helpers.go:119] Error from server (NotFound): Unable to list "nodes": the server could not find the requested resource (get nodes)

Thanks for your atention!

 

I don't know anything about Jenkins or Kubernetes, but is it supposed to be sending a GET request to localhost:8080?

 

I don't really know why that route http://localhost:8080 appears :( But the original error its: Error from server (NotFound): the server could not find the requested resource