Setup kubectl with jenkins

11/20/2018

Does anyone know how to setup kubectl with jenkins? Jenkins is running on AWS EC2 which can communicate with AWS EKS Cluster.

when i run shell script in jenkins as kubectl version i get :

+ kubectl version

output :

Client Version: version.Info{Major:"1", Minor:"10",    GitVersion:"v1.10.3",     GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0",     GitTreeState:"clean", BuildDate:"2018-07-26T20:40:11Z",     GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
Error from server (Forbidden): <html><head><meta http-equiv='refresh' content='1;url=/login?from=%2Fversion'/>    <script>window.location.replace('/login?from=%2Fversion');</script></head>    <body style='background-color:white; color:white;'>


Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
 ... which is implied by: hudson.security.Permission.GenericRead
 ... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>
Build step 'Execute shell' marked build as failure
-- Abhishek Chudekar
aws-eks
jenkins
kubernetes

3 Answers

11/20/2018

There are multiple ways to do that. Check the link below posted by AWS. According to the link. When it comes to EKS you can use Jenkins X. It's designed for K8s only.

https://aws.amazon.com/blogs/opensource/continuous-delivery-eks-jenkins-x/

-- AnmolNagpal
Source: StackOverflow

11/20/2018

Remove ~/ from aws eks export commands and then you can easily setup kubectl for aws eks.

-- Abhishek Chudekar
Source: StackOverflow

11/20/2018

One of the ways to configure it in proper way is to use Jenkins Kubernetes plugin: https://illya-chekrygin.com/2017/08/26/configuring-certificates-for-jenkins-kubernetes-plugin-0-12/

Another one is to pass cluster kubeconfig file to kubectl.

-- VKR
Source: StackOverflow