-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error during EKS Creation: Post "http://localhost/api/v1/namespaces/kube-system/configmaps": dial tcp 127.0.0.1:80: connect: connection refused #1280
Comments
It looks like the Kubernetes provider isn't receiving a configuration. Here's how I configure mine, which is similar to the EKS module README except it's for the newer version of the Kubernetes provider. (My team recently released version 2.0 of the Kubernetes provider and it requires a slightly different config than shown in this module's README).
|
@dak1n1 - The code example I provided does NOT instantiate the kubernetes provider (at least not directly). The error happens during creation of the EKS module - not before or after. So - the problem happens in the EKS module itself - not outside of the module. |
Right, but the EKS module uses the Kubernetes provider under the hood, so it needs a provider configuration. Otherwise, it will assume a default/empty config. You can skip using the Kubernetes provider within the EKS module by specifying
|
I have the same issue on a newly created cluster everything is fine and then I'm changing the module tag and get this error, the weird thing is that if I put everything back just like in the state everything work as expected |
@dak1n1 -- How am I supposed to instantiate the Kubernetes provider using output from this module, but before I instantiate this module? (Also, is everyone who specifies |
The issues vary depending on the user's configuration, but they're all related to a subject I'm currently researching, which is why I'm volunteering my time here. The EKS module, which is a community-driven effort (not managed by Hashicorp), specifically is using a pattern that is discouraged by the creators of Terraform. (Specifically, where it says a provider config should The issues being described in this bug report all have the same root cause, which is that they are passing variables into a provider configuration which are not known at plan time. Terraform simply doesn't support that, and so they encourage instead separating out the AWS provider and Kubernetes provider resources, so you can use two applies when needed. However, there are some work-arounds that can still help to achieve this workflow. Since so many users want to use this in a single apply, this is my area of interest, to try and enable that pattern to succeed, despite the current limitations in Terraform. TLDR: you can copy/paste the config I gave above, which will only read the EKS cluster after the variables are known. You can also use the config in this repo's README, which is another way to establish this dependency. However, since this pattern is not actually supported in Terraform, there will be times when it will fail. Specifically, when the EKS cluster's credentials become unknown, such as when replacing the cluster, or during This page can be helpful for learning about configuring providers that are used with modules. https://www.terraform.io/docs/language/modules/develop/providers.html I also have a couple working configs here, if anyone wants to reference them. On the Kubernetes provider side, I have some plans to smooth this out a bit and provide more meaningful error messages. I'm also planning to implement a version of this old request that I found when researching the topic. That will allow the Kubernetes provider to keep trying to contact the Kubernetes API, rather than failing immediately with the obscure |
Thanks for the thorough response, Stef. I appreciate it.
Ultimately, since my `eks` module is called within another module, the provider solution just doesn’t work out due to the limitation against nesting providers within modules.
I’m taking a look at cdktf and seeing if it gives me the flexibility that I need.
|
it probably won't apply to many people, but in case that can help: I had this config:
Somehow, removing the "config_context" line made this error disappear ... |
I have never set The resolution was
|
@dak1n1 this issue is being caused by hashicorp/terraform#24886 (which is also a pretty large pain point in implementing a Hashicorp native credential flow e.g. OIDC -> Vault STS -> AWS provider). Without this being solved what is the logic for a TL;DR - Is there a hack to make a |
@stevehipwell Do you think this might be related to the issue you mentioned above ? |
@ArchiFleKs I suspect that it's related and I meant to add a comment to that effect. We're having to delete the |
@stevehipwell Yes my workaround is:
|
@ArchiFleKs have you tried reverting the Kubernetes provider version? |
To which version ? before v2.0 ? |
That'd be my first suggestion, and if it works see is any of the v2 versions also work. |
I am also looking into best practices, although currently I use a single terraform run to deploy some dependencies, this eks module, and a bunch of helm charts and kubernetes yaml files. Currently, using kubernetes provider version = "~> 1.11.1" and terraform 0.14.11 (and also manage_aws_auth=true) I am not experiencing big issues. ( I do need to refresh before destroy, but I feel that is expected). My provider blocks look like this:
I though of sharing my versions and blocks in case someone finds it useful. Still, will keep around the discussion, in case I get an issue in the future and we can come up with workarounds. |
We encountered this trouble too and @grandria find another workaround : set a good value to KUBE_CONFIG_PATH |
I experience this issue too and alike @jaimehrubiks I am as well using eks as a submodule and install a good amount of helm charts and other stuff into the cluster. I have had huge problems with token lifetimes in the past and always had to spin up clusters in two steps. 1st create the cluster, then error because there is no token, replan and apply with a token now. I configured my providers like this in the submodule to overcome these problems:
With this I can spin up a cluster and install helm charts and other stuff in a single plan/apply.
The data blocks to configure the provider are empty somehow and I cannot just reference a kube config since I want to be able to still use Atlantis and it's easy iam assumeables for authentification. If I get said error I go into the local terraform file cache under .terraform/modules/$module-name and edit the provider files for the clusters into this:
This works everytime once the cluster is already spun up. But I cant just use it like that, since I cannot spin up cluster in a single plan/apply fashion any more. I don't understand tho why the datablocks become stale and empty, even refreshing them doesn't help at all |
Actually this technique is working, but it is a bit hard to set when running in a CI for example and kubeconfig is not present |
okay, I think I somehow solved the problem at least for me.
(I know putting the depends_on twice is actually redundant, but I just like to make really sure)
That module gets sourced multiple times in a single aws account to spin up a load of clusters and this somehow gave me the least problems. The sleep makes the api more resilient to timing problems ( so I feel at least ) |
I'm facing the same issue after trying to change the tags of the cluster |
Okay, I found out what is the problem. Spent the entire day to fix it :) TL;DR
It's a bad idea to set First of all, I put k8s provider configuration inside aws_auth.tf:
This is the only one correct configuration for eks that is also pointed out in official doc. U can also use pre-generated kubeconfig file from Back to the main point: since there's an
And Voila, it works! |
We've been told by Hashicorp to always use the |
We met same error when we try to add extra subnets to the VPC and EKS, removed the extra subnets, the error disappeared |
A user of this module can subsequently use this ConfigMap output as they wish, in their own module. This should help with issue terraform-aws-modules#1280 ``` resource "kubernetes_config_map" "aws_auth" { metadata { name = module.eks.config_map_aws_auth_yaml.metadata.name namespace = module.eks.config_map_aws_auth_yaml.metadata.namespace labels = module.eks.config_map_aws_auth_yaml.metadata.labels } data = module.eks.config_map_aws_auth_yaml.data } ```
This issue has been automatically marked as stale because it has been open 30 days |
same here.
|
I was able to solve my problem in the same way, I have a module to manage network resources and another module to manage the EKS cluster. |
This happened to us, as well; we wanted to expand our cluster into additional subnets (specifically, the worker node ASGs, not so much the control plane); of course, by default the ASGs use the same set of subnets as the cluster control plan, and, apparently, you can't change the subnets of the cluster control plane. That said, it's a bit wild to me that this causes the planning phase to fall back to querying localhost. It's not easy to tell from Terraform's default logging what step is going wrong, but maybe setting |
This issue has been resolved in version 18.0.0 🎉 |
@antonbabenko we're still seeing this issue using v18.0.5 of this module. I see in the upgrade doc that:
...and we have shifted to using the new
...but don't understand what about the release fixed this issue, or what other config this fix is dependent on. Any advice would be appreciated. We could raise another issue, but I feel this is likely a misunderstanding on our part. |
The issue was marked as resolved by release v18 because we removed the management of the aws-auth config map from the module (what the issue was created for) |
Thanks @bryantbiggs. So, does this mean that it would be expected that this issue would still occur in a terraform project which uses v18+ of this eks module, and still uses the kubernetes provider? That's us. We're still managing our aws_auth config map in the same project which of course requires the kubernetes provider. I understand this was moved out of the eks module. |
It's possible; it's highly dependent on how your resources are configured, network connectivity, and what actions you are taking |
OK, thanks for the info. We're first going to try using the exec plugin to handle kubernetes provider authentication, as some others have recommended above. |
@timblaktu the tl;dr here is use the exec plugin for all Kubernetes based providers. The long answer is that if you ask HashiCorp how to do this you will get many different, usually incorrect, answers. Of these two actually work; the "official" one is that you can't use Kubernetes in the workspace where it was created, the "engineering" one is to use the exec plugin and make sure you plan out your dependencies correctly. |
@stevehipwell thanks so much for those insights. I'm trying your "engineering" answer and want to dive a bit into the "make sure you plan out your dependencies correctly" part. I've changed my kubernetes provider config (which used to specify a token) to use the exec plugin for auth, like this:
and am still getting the "localhost connection refused" error, presumably the first time the kubernetes provider tries to reach out to the cluster. In my case this is at the declaration of a So,
EDIT: Could my problem here be that I am declaring the kubernetes provider to be implicitly dependent on the eks module through my reference to
...but this dependency is probably caused by my references to |
@timblaktu I've used the following pattern when layering on top of an EKS cluster created by this module for a number of major releases. I think the important point here is to use the module outputs for provider "kubernetes" {
host = module.eks.cluster_endpoint
cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data)
exec {
api_version = "client.authentication.k8s.io/v1alpha1"
command = "aws"
args = ["eks", "get-token", "--cluster-name", local.cluster_name]
}
} |
Thanks again, @stevehipwell! This appears to be the final (and quite obscured!) wisdom that completely solves this issue. Using v18 of the module doesn't fix it by itself. Using an exec plugin in your kubernetes provider config doesn't fix it by itself. Your last point is also essential to the solution: you can't workaround this bug completely if you are referring to eks cluster data sources in your kubernetes provider config. It's too bad that more issues aren't followed up on after being closed with the resulting essential tribal wisdom like we (mostly you) did here. But I guess that's the way of open source, no? If we (the tribe) doesn't do it, who will? Thanks again! |
Is it worth calling out @stevehipwell's recommendations/details in the examples, and potentially the module docs, so others are aware of this caveat/don't run into the same issue? We've got many teams who have run into the same thing, and just temporarily split up the terraform to prevent running them so close together, which isn't ideal. I understand it's not the fault of these modules, but it might be worth at least adding a little snippet to point people in the right direction. |
@lrstanley Probably it would make the most sense for this info to go prominently into the eks module documentation, since ultimately this is a bug in the module implementation, as noted here, and is the reason why all of these "all planets in alignment" work arounds are necessary. |
@timblaktu this isn't an issue with this module, it's a general Terraform defect disguised as a design choice. I agree that the docs here could be updated with some "suggestions" on use, but HashiCorp should be the ones documenting how their providers work (as noted above don't hold your breath). Remember the maintainers have removed the nested provider in the module so provider logic belongs to the workspace consuming the module; HashiCorp own supporting this now. |
@dak1n1 Hi Dak1n1 , I run into the same issue and fix this issue by your method , glad to to see you |
I am not sure if I understand the solution correctly: Is it to use That is what I have done (hopefully no silly mistakes there):
But I am still getting the original error:
All I am doing is spinning up an emtpy cluster with This workaround does help, but is kind of ugly:
It is probably possible to avoid the error by saying |
This worked for me. |
You can declare an env variable in your GitHub YAML like that and this will work: |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Description
When creating an EKS Cluster using terraform, we get the following error:
To fix this, we have to manually run:
and then:
Versions
Reproduction
terraform init && terraform apply -auto-approve
To fix, manually run:
aws eks update-kubeconfig --name ${var.context.app_name} --region ${var.context.region}
terraform apply -auto-approve
Code Snippet to Reproduce
Expected behavior
The cluster gets created successfully
Actual behavior
We get this output:
The text was updated successfully, but these errors were encountered: