Surya Bhusal
Surya Bhusal

Reputation: 650

Jenkins Pipeline With Kubernetes Deployment

I've a following groovy code in my Jenkins pipeline:

pipeline {
    agent any

    stages {
        
       .....
       .....

        stage('Deploy To Kubernetes') {
            steps {
                    withCredentials([string(credentialsId: 'kubernetes-secret', variable: 'K8S_TOKEN')]) {
                        sh """
                            kubectl --token=$K8S_TOKEN get pods
                        """
                    }
            }
        }
      
        .......
        .......
    }
}

In the stage deploy to kubernetes, im using a token which i manually created using:

kubectl create token default

I'm not sure what i'm missing. I keep getting following error:

+ kubectl --token=**** get pods
E0222 22:06:55.856387  321714 memcache.go:265] "Unhandled Error" err=<
    couldn't get current server API group list: <html><head><meta http-equiv='refresh' content='1;url=/login?from=%2Fapi%3Ftimeout%3D32s'/><script id='redirect' data-redirect-url='/login?from=%2Fapi%3Ftimeout%3D32s' src='/static/ffec7a5e/scripts/redirect.js'></script></head><body style='background-color:white; color:white;'>
    Authentication required
    <!--
    -->
    
    </body></html>
 >
E0222 22:06:55.858786  321714 memcache.go:265] "Unhandled Error" err=<
    couldn't get current server API group list: <html><head><meta http-equiv='refresh' content='1;url=/login?from=%2Fapi%3Ftimeout%3D32s'/><script id='redirect' data-redirect-url='/login?from=%2Fapi%3Ftimeout%3D32s' src='/static/ffec7a5e/scripts/redirect.js'></script></head><body style='background-color:white; color:white;'>
    Authentication required
    <!--
    -->
    
    </body></html>
 >

Upvotes: 0

Views: 46

Answers (1)

Thomas
Thomas

Reputation: 12029

Probably you are connecting to localhost:8080 to access the Kubernetes API server as that is the default if nothing else is configured. This happens to be the Jenkins server/UI itself and generates the response you see.

Configure the Kubernetes API endpoint in addition to the credentials.

Upvotes: 0

Related Questions