terraform-deploy icon indicating copy to clipboard operation
terraform-deploy copied to clipboard

Shouldn't need to run update-kubeconfig manually

Open jaytmiller opened this issue 4 years ago • 6 comments

I ran into this:

Error: stat /Users/jmiller/.kube/config: no such file or directory on autoscaler.tf line 63, in resource "helm_release" "cluster-autoscaler": 63: resource "helm_release" "cluster-autoscaler" {

and @yuvipanda suggested I write an issue about it.

The manual work-around was:

aws eks update-kubeconfig --name <CLUSTER-NAME>

jaytmiller avatar May 07 '20 13:05 jaytmiller

Yeah, I've had to run

aws eks update-kubeconfig --name=<name> --region=<region> --profile=<profile>

after every cluster's creation. I have a feeling Terraform doesn't want to change your local kubeconfig.

There are options for the terraform-aws-eks module that can output a kubeconfig file, but there would still be a step to switch to that file instead of ~/.kube/config I think.

salvis2 avatar Aug 10 '20 21:08 salvis2

Yeah, might be useful to output a kubeconfig file locally, and then set the KUBECONFIG env var to point to it? Terraform definitely doesn't wanna change your ~/.kube/config...

yuvipanda avatar Aug 11 '20 06:08 yuvipanda

I think by default the terraform-aws-eks module outputs a kubeconfig file into the directory where you ran Terraform commands and names it kubeconfig_${var.cluster_name} (see https://github.com/terraform-aws-modules/terraform-aws-eks/blob/master/kubectl.tf). Maybe there is a good way to automatically switch to the KUBECONFIG env var to it?

salvis2 avatar Aug 11 '20 17:08 salvis2

We're wondering about maybe adding this to hubploy? (Maybe as an option which defaults to on?) How "expert" is the scenario where automatic kubeconfig is bad?

jaytmiller avatar Aug 11 '20 19:08 jaytmiller

hubploy doesn't depend on KUBECONFIG - it gets credentials from the keys set in hubploy.yaml. Current environment variables shouldn't matter, and I'd prefer to not have hubploy modify anything in ~/.kube/config.

If you can find a way to set KUBECONFIG env var after terraform completes, that's not a bad idea. However, I think changing what KUBECONFIG points to without the user explicitly asking for it is recipe for trouble, as you can then accidentally perform operations in the wrong cluster! So I'd generally recommend against it, nad instead document what people can do.

yuvipanda avatar Aug 12 '20 10:08 yuvipanda

OK, sounds totally reasonable to me. We're in the process of documenting the end-to-end process internally so this is easy to add to those docs explicitly. If we ever do make a comprehensive wrapper script to automate installing all the pieces end-to-end, we could also add this step to that script.

jaytmiller avatar Aug 12 '20 12:08 jaytmiller