13

I am trying to execute helm commands on VSTS release definition using Run command VSTS extension but the problem is it is not able to find the kubeconfig file on the custom build agent i have configured. I think this is coz the build steps defined run in a separate process. When i run

kubectl config view

It gives me an empty config file. Just wanted to know if i can provide the kubeconfig file inline when m executing helm commands something like

helm init --kubeconfig=kubeconfigpath

Or is there any way i can set the kubeconfig file before running the helm commands in vsts release process?

Appreciate any help. Thanks.

narcs
  • 213
  • 1
  • 2
  • 13

3 Answers3

18

'helm init' command discovers your Kubernetes cluster's configuration by reading $KUBECONFIG variable(default '~/.kube/config') and using the default Kubernetes context. If you are using a different config file then you have to change $KUBECONFIG value so that helm gets info about your cluster from the correct config file.

Change the $KUBECONFIG value

export KUBECONFIG=/path_to_your_kubeconfig_file

To be on safe side use the --kube-contex flag to specify the current context

helm init --kube-context CONTEXT_NAME --upgrade

Check helm client and tiller version using

helm version

zaman sakib
  • 851
  • 11
  • 18
3

Try to specify kubeconfig file through kubectl command.

kubectl config SUBCOMMAND

Options

-h, --help=false: help for config
      --kubeconfig="": use a particular kubeconfig file

On the other hand, you can try to change build agent account (e.g. your account) and check whether it can find the kubeconfig file (permission issue)

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • Did that. but the --kubeconfig option is specific to that command only. The build agent that i am using has only one account with admin rights and have used same account credentials to configure the build agent on VSTS. I even tried to set the environment variable using set and setx command but that too didn't work. – narcs Mar 17 '17 at 06:27
  • @narcs Is the build agent running as service or interactive mode? If it is running as service, what's the account of service? – starian chen-MSFT Mar 17 '17 at 06:32
  • its running as service. Its properties > Log On tab shows it is using "This account" i.e. Network Service. – narcs Mar 17 '17 at 06:38
  • changed it to the actual account using browse in this VSTS service properties and restarted the service. Have also copied the .kube folder which contains config file to Users\Public folder. Not sure if this will help but have triggered the build/release.. – narcs Mar 17 '17 at 06:41
  • @narcs Try to setup a build agent running as Interactive mode. – starian chen-MSFT Mar 17 '17 at 06:42
  • Ok, sure I will try that one as well after this build is completed. – narcs Mar 17 '17 at 06:43
  • Thank you very much. I dunno what made the config available; copying it to C:\Users\Public folder or setting the account in properties for VSTS build agent service. but now, the helm command can find the config and can install/upgrade in VSTS release pipeline. Thanks again :) – narcs Mar 17 '17 at 06:58
0

I'm playing with WSL 2.0 Ubuntu and use different cloud essential tools installed in Ubuntu distribution.

I easily succeeded to use kubectl with Windows kubeconfig but failed to run any helm version:

kubectl --kubeconfig /mnt/c/Users/Pavel/.kube/config cluster-info

Kubernetes master is running at https://kubernetes.docker.internal:6443 KubeDNS is running at https://kubernetes.docker.internal:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

To further debug and diagnose cluster problems, use kubectl cluster-info dump.

kubectl --kubeconfig /mnt/c/Users/Pavel/.kube/config get pods

NAME READY
STATUS RESTARTS AGE freenginx-nginx-ingress-controller-675bd7f48b-szd88 1/1
Running 0 3d22h freenginx-nginx-ingress-default-backend-85c897bdd6-cjk4j 1/1
Running 0 3d22h mysql-1576664918-69dd8486b5-vb44p
1/1 Running 0 4d2h pavel@MSI:~$ helm --kubeconfig /mnt/c/Users/Pavel/.kube/config list Error: unknown flag: --kubeconfig

I expect that helm should behave in the same manner. If I succeed to save long time on double installation of Kubernetes client utilities for users who use WSL 2.0

Matus Dubrava
  • 13,637
  • 2
  • 38
  • 54
Pavel Sosin
  • 111
  • 1
  • 3