I have my jenkins running on EC2 and installed kubectl. I've also configured kubectl to communicate with my EKS cluster in AWS.
Now, I'm trying to automate the deployment of our application to EKS using Jenkins pipeline. But when jenkins reaches this code below
sh "kubectl apply -f platform_api_deployment.yml"
It's showing me this error
/var/lib/jenkins/workspace/platform-api-pipeline/kubernetes@tmp
/durable-2696d974/script.sh: line 1: kubectl: command not found
I've tried deploying it manually and it works fine.
Basically you need a kubeconfig file to communicate with the API Server. Therefore, You just need login to the server where jenkins is installed, then switch to the user "may be root" from where you can execute kubectl command and execute below commands manually on the shell. These command will copy the kubeconfig to the jenkins user root directory. After that re-run jenkins pipeline.
sudo cp ~/.kube/config ~jenkins/.kube/
sudo chown -R jenkins: ~jenkins/.kube/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With