Reputation: 97
i have a Deploy stage in jenkins like below.
stage('Deploy service to K8S') {
steps {
withDockerContainer(image: "gcr.io/google.com/cloudsdktool/cloud-sdk", toolName: 'latest'){
withCredentials([file(credentialsId: 'jenkins_secret', variable: 'GC_KEY')]) {
sh("HOME=$WORKSPACE gcloud --quiet auth activate-service-account --key-file=${GC_KEY}")
sh("HOME=$WORKSPACE gcloud container clusters get-credentials test --zone us-central1-c --project ${PROJECT_ID}")
sh("kubectl get pods")
}
}
}
}
Despite of Jenkins logs show me that autentication was succedd. But kubectl get pods commands fail with this error : The connection to the server localhost:8080 was refused - did you specify the right host or port?
What can be the issue there ?
P.S I can run it inside docker manually.
Upvotes: 2
Views: 384
Reputation: 440
I was running into such an issue recently and this helped: GitHub Issue on kubectl
It is basically failing because of a wrong kubeconfig.
Please check that you have no old ~/.kube/config
in your filesystem.
If this does also not work please try to give the kube api server explicitely as it seems to try to connect to localhost instead of to your kubectl api server:
kubectl config set-cluster some-cluster --server=http://master.example.com:8080
Upvotes: 1