1

I am using kubernetes helm to deploy apps to my cluster. Everything works fine from my laptop when helm uses the cluster's kube-config file to deploy to the cluster.

I want to use helm from my CI/CD server (which is separate from my cluster) to automatically deploy apps to my cluster. I have created a k8s service account for my CI/CD server to use. But how do I create a kube-config file for the service account so that helm can use it to connect to my cluster from my CI/CD server??

Or is this not the right way to use Helm from a CI/CD server?

Nithin
  • 2,223
  • 4
  • 21
  • 29
  • It is the right way to do that. You can just copy the ~/.kube directory to get the configs required. – Norbert Apr 25 '17 at 22:02

4 Answers4

1

Helm works by using the installed kubectl to talk to your cluster. That means that if you can access your cluster via kubectl, you can use helm with that cluster.

Don't forget to make sure you're using to proper context in case you have more than one cluster in you kubcfg file. You can check that by running kubectl config current-context and comparing that to the cluster details in the kubecfg.

You can find more details in Helm's docs, check the quick start guide for more information.

Merlin
  • 171
  • 2
  • 5
1

why not just run your CI server inside your kubernetes cluster then you don't have to manage secrets for accessing the cluster? We do that on Jenkins X and it works great - we can run kubectl or helm inside pipelines just fine.

James Strachan
  • 9,168
  • 34
  • 31
  • Well when the question was asked, Jenkin X simply didnt exist. In my usual setup, i have atleast 2 clusters, staging and prod and I generally dont run build stuff on prod. Having 2 clusters and when the build/deploy does not run on the same cluster where the app is deployed, the question arises again. – Nithin May 31 '18 at 13:05
  • Because repo is outside of cluster and webhooks can't talk to my cluster? Makes PR builds and such difficult – Sinaesthetic Sep 05 '18 at 03:26
0

In this case you will want to install kubectl on whichever slave or agent you have identified for use by your CI/CD server, OR install kubectl on-the-fly in your automation, AND then make sure you have OR are able to generate a kubeconfig to use.

To answer the question:

But how do I create a kube-config file for the service account ...

You can set new clusters, credentials, and contexts for use with kubectl in a default or custom kubeconfig file using kubectl config set-cluster, kubectl config set-credentials, and kubectl config set-context. If you have KUBECONFIG env variable set and pointing to a kubeconfig file, that works or when setting new entries simply pass -kubeconfig to point to a custom file.

Here's the relevant API documentation for v1.6.

0

We created helmsman which provides you with declarative syntax to manage helm charts in your cluster. It configures kubectl (and therefore helm) for you wherever you run it. It can also be used from a docker container.

Sami
  • 7,797
  • 18
  • 45
  • 69