0

I have an Azure cloud where a Kubernetes cluster was created by me. Besides, in my environment, I have Jenkins running for the pipeline. I need to create a container with React FE in it. I need to describe some kubectl commands with kubeconfig to enable access to Kubernetes clusters in my Azure cloud. Below lines of code are from the Jenkins groovy file:

sh "helm template $podPath -f $destPath --set namespace=$namespace > helm_chart_${env}.yaml" sh "kubectl config set-context jenkins-react@react --kubeconfig=/root/.kube/sa_new_kubeconfig" sh "kubectl delete -f helm_chart_${env}.yaml
--kubeconfig=/root/.kube/sa_new_kubeconfig || true" sh "sleep 10"

I am willing to know if there is any alternative way to use kubeconfig apart from defining it explicitly in Jenkins groovy code. If yes then which is the convenient and better way?

Ivan Aracki
  • 4,861
  • 11
  • 59
  • 73
UnicsSol
  • 27
  • 7

1 Answers1

1

You can use an env variable KUBECONFIG with the path to your Kubernetes config file.

Then, it depends on how you configure your Jenkins and your Jenkins pipeline, but you may:

  • Add this variable to your Jenkins agent configuration
  • Add this variable to your Jenkinsfile pipeline
Rafał Leszko
  • 4,939
  • 10
  • 19
  • Could the same KUBECONFIG variable be used in values.yml or chart.yml files as I am using Helm charts here. – UnicsSol Feb 21 '22 at 12:19