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

Add an example for GKE + NFS + PVC #840

Merged
merged 2 commits into from
May 20, 2020
Merged

Add an example for GKE + NFS + PVC #840

merged 2 commits into from
May 20, 2020

Conversation

dak1n1
Copy link
Contributor

@dak1n1 dak1n1 commented May 6, 2020

Description

This example shows how to create a GKE cluster and use Google Filestore (NFS) to create Persistent Volumes in Kubernetes. It also mounts the volume to an example Deployment (mariadb) using a Persistent Volume Claim.

References

There is a limitation in the current version of the terraform-plugin-sdk, which makes it difficult to differentiate between null and "" values for attributes. For example, the storage_class_name attribute of the kubernetes_persistent_volume_claim resource cannot accept a value of "" using the current SDK. It will interpret the value as if the attribute had been omitted entirely, which generally will cause Kubernetes to use the default storage class.

This example demonstrates a workaround, which is to create a storageclass instead of attempting to use the blank value.

There are related issues that may be mitigated by this workaround.

@ghost ghost added the size/L label May 6, 2020
capacity = {
storage = "1T"
}
storage_class_name = "filestore"
Copy link

@yu-iskw yu-iskw May 7, 2020

Choose a reason for hiding this comment

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

Can we refer kubernetes_storage_class.nfs.metadata[0].name instead of the literal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! Done.

}
spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "filestore"
Copy link

Choose a reason for hiding this comment

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

ditto

spec {
access_modes = ["ReadWriteMany"]
storage_class_name = "filestore"
volume_name = "nfs-volume"
Copy link

@yu-iskw yu-iskw May 7, 2020

Choose a reason for hiding this comment

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

Can we refer kubernetes_persistent_volume .example.metadata[0].name?

storage = "1T"
}
}
}
Copy link

Choose a reason for hiding this comment

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

It would be nicer to add depends_on.

For example,

  depends_on = [kubernetes_persistent_volume.example]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this resource now has these references defined, there is an implicit dependency. So the PVC won't be created until the storageclass and the PV are created.

 storage_class_name = kubernetes_storage_class.nfs.metadata[0].name
 volume_name = kubernetes_persistent_volume.example.metadata[0].name

I looked it up in the docs to be sure:

"Explicitly specifying a dependency is only necessary when a resource relies on some other resource's behavior but doesn't access any of that resource's data in its arguments."

Copy link

Choose a reason for hiding this comment

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

Sure. Let's keep the current implementation.

@yu-iskw
Copy link

yu-iskw commented May 7, 2020

I got the error when executing terraform plan locally. I set the GCP region to us-west1.

Environment

$ terraform version
Terraform v0.12.24
+ provider.google v3.20.0
+ provider.kubernetes v1.11.2
+ provider.local v1.4.0
+ provider.random v2.2.1
+ provider.template v2.1.2

Error messages

Error: node_version and min_master_version must be set to equivalent values on create

  on main.tf line 41, in resource "google_container_cluster" "primary":
  41: resource "google_container_cluster" "primary" {



Error: Error waiting to create Instance: Error waiting for Creating Instance: error while retrieving operation: Get https://file.googleapis.com/v1/projects/kouzoh-p-yu/locations/us-west1-a/operations/operation-1588828160178-5a507e218b8a4-60a7d6b5-2de8328e?alt=json: dial tcp [2404:6800:4004:81b::200a]:443: connect: no route to host

  on main.tf line 71, in resource "google_filestore_instance" "test":
  71: resource "google_filestore_instance" "test" {

@ghost ghost added size/XL and removed size/L labels May 7, 2020
@dak1n1
Copy link
Contributor Author

dak1n1 commented May 7, 2020

I'm glad you brought that up! I ran into that error too, with the node_version. It means there is a mismatch in version availability between the master and node. The availability of versions varies by zone, and the version that you pass in via the CLI might not be available in your chosen zone for both the master and node.

I've made a change to the config that will install the latest version available for the master (since it looks like older versions are available for masters). And if no version is found, it'll use the GKE default. It worked in my testing when I passed in 1.15 and 1.16 for the kubernetes version. Omitting the version entirely now works too.

This example config shows how to use GKE with
Google Filestore (NFS) to create Persistent Volumes in Kubernetes.
@jrhouston
Copy link
Collaborator

This example is great @dak1n1 thanks for making this.

Co-authored-by: John Houston <jrhouston@users.noreply.github.com>
@dak1n1 dak1n1 merged commit 043ef88 into hashicorp:master May 20, 2020
@ghost
Copy link

ghost commented Jun 20, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked and limited conversation to collaborators Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants