Skip to content
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

kubernetes: Expand example to show best practices for interacting with k8s provider. #564

Merged
merged 8 commits into from
Jan 29, 2021

Conversation

andrewsomething
Copy link
Member

As seen in #562, using interpolation to pass credentials to the Kubernetes provider from other resources can cause some issues due to the order in which Terraform evaluates the provider blocks vs. actual resources. In fact, the Kubernetes provider docs have added a warning to discourage using interpolation to pass credentials:

https://registry.terraform.io/providers/hashicorp/kubernetes/latest/docs#stacking-with-managed-kubernetes-cluster-resources

This PR expands the Kubernetes example in this repo to be more complete and better adhere to best practices for interacting with the Kubernetes provider. It also adds a notes to the Kubernetes cluster resource docs addressing the issue and linking to that example. Finally, it updates usage of the Kubernetes provider for it 2.0.x release (specifically the removal of the load_config_file attribute).

Fixes: #562

Copy link
Contributor

@devurandom devurandom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this improvement! I have a few questions the answers to which might also help other newbies with DOKS and Terraform.

docs/resources/kubernetes_cluster.md Outdated Show resolved Hide resolved
examples/kubernetes/README.md Outdated Show resolved Hide resolved
Comment on lines 40 to 49
Optionally, this example can generate a kubeconfig file in the current working
directory. However, the token in this config will expire. The token can be
refreshed by running `terraform apply` again and setting `write_kubeconfig` to
`true`.

```
terraform apply -var="write_kubeconfig=true"
export KUBECONFIG=$(terraform output -raw kubeconfig_path
kubectl get pods -n test
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use a combination of terraform refresh and terraform output kubeconfig > .../kubeconfig. That seems less intimidating (i.e. potentially destructive) that terraform apply.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this creates a local_file resource, apply is needed to replace the file if new credentials are needed.

examples/kubernetes/README.md Show resolved Hide resolved
examples/kubernetes/kubernetes-config/main.tf Show resolved Hide resolved
examples/kubernetes/kubernetes-config/main.tf Show resolved Hide resolved
examples/kubernetes/README.md Outdated Show resolved Hide resolved
Copy link
Contributor

@ChiefMateStarbuck ChiefMateStarbuck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@scotchneat scotchneat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks awesome @andrewsomething

@andrewsomething andrewsomething merged commit b3827fc into main Jan 29, 2021
andrewsomething added a commit that referenced this pull request Apr 26, 2021
…h k8s provider. (#564)

* kubernetes: Expand example to show best practices for interacting with k8s provider.

* Add README to the kubernetes example.

* Update Kubernetes provider interoperability acceptance test for 2.0.x

* kubernetes: Update documentation.

* Update examples/kubernetes/README.md

Co-authored-by: Dennis Schridde <[email protected]>

* Update examples/kubernetes/README.md

Co-authored-by: Samuel Guyah <[email protected]>

* k8s: Replace the interpolation example with one using the data source.

* Document using the exec plugin w/ doctl.

Co-authored-by: Dennis Schridde <[email protected]>
Co-authored-by: Samuel Guyah <[email protected]>
@andrewsomething andrewsomething deleted the asb/k8s-interop branch September 2, 2021 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants