-
-
Notifications
You must be signed in to change notification settings - Fork 507
Parameterise mount path for longhorn volume #1800
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
Open
garry-t
wants to merge
32
commits into
mysticaltech:master
Choose a base branch
from
garry-t:mount_path
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
43c9cb4
Update variables.tf
garry-t 7c15422
Update agents.tf
garry-t 3336faf
Update locals.tf
garry-t 574df9e
Update agents.tf
garry-t 4f77bb5
Update locals.tf
garry-t d68210e
Update agents.tf
garry-t 785d476
Update variables.tf
garry-t fffc5bd
Update agents.tf
garry-t e4c33b3
Update variables.tf
garry-t 8ad2141
Update variables.tf
garry-t 94b77e6
Create customize-mount-path-longhorn.md
garry-t 0ae30f0
Update kube.tf.example
garry-t 54af473
- fix typo
garry-t b7ef617
- gemini suggest fix doc
garry-t 968772b
- gemini suggest fix comment
garry-t e720ea9
- gemini fix validation
garry-t cb6f68c
- gemini yet another fixes
garry-t 66d9676
- gemini mountpoint checks
garry-t 012c59d
Merge branch 'master' into mount_path
garry-t 7bfada4
Merge branch 'master' into mount_path
garry-t aa01c5d
- gemini added "set -e"
garry-t 3b517e2
- gemini fix review
garry-t 889ae77
- provide idempotent mount command
garry-t 42a32cd
- fix one more gemini review comment
garry-t 436224a
- improved regex one more time
garry-t b57b819
Update docs/customize-mount-path-longhorn.md
garry-t 8fdce26
- improve validation variable
garry-t a9dcac1
- satisfy gemini
garry-t fe22dbd
Update docs/customize-mount-path-longhorn.md
garry-t 0d58ced
- gemini yet another fix
garry-t 1159886
- gemini yet another validation fix
garry-t 2befe18
- gemini fix doc..
garry-t File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| ## How to use a custom mount path for Longhorn | ||
| <hr> | ||
|
|
||
| In order to use NVMe and external disks with Longhorn, you may need to mount an external disk to a location other than the default under the `/var/` folder. This can provide more storage capacity across the cluster, especially if you haven't disabled the default Longhorn disks. | ||
|
|
||
| > ⚠️ Note: You can set any mount path, but it must be within the `/var/` folder. | ||
|
|
||
| ### How to set a custom mount path for your external disk? | ||
|
|
||
| 1. You must enable Longhorn in your module. | ||
| ```terraform | ||
| enable_longhorn = true | ||
| ``` | ||
|
|
||
| 2. Set the Helm values for Longhorn. The `defaultDataPath` is important as this path is automatically created by Longhorn and will be the default storage class pointing to your primary disks (e.g., NVMe). | ||
| ```yaml | ||
| longhorn_values = <<EOT | ||
| defaultSettings: | ||
| nodeDrainPolicy: allow-if-replica-is-stopped | ||
| defaultDataPath: /var/longhorn | ||
| persistence: | ||
| defaultFsType: ext4 | ||
| defaultClassReplicaCount: 3 | ||
| defaultClass: true | ||
| EOT | ||
| ``` | ||
|
|
||
| 3. In the `agent_nodepools` where you want to have a customized mount path, set the `longhorn_mount_path` variable. It's a good practice to define this path as a local variable to ensure consistency. | ||
|
|
||
| ```terraform | ||
| locals { | ||
| custom_longhorn_path = "/var/lib/longhorn" | ||
| } | ||
|
|
||
| agent_nodepools = [ | ||
| { | ||
| # ... other nodepool configuration | ||
| labels = ["role=monitoring", "storage=ssd"], # Label we use to filter nodes | ||
| longhorn_volume_size = 50, | ||
| longhorn_mount_path = local.custom_longhorn_path # This is the custom path | ||
| } | ||
| ] | ||
| ``` | ||
|
|
||
| 4. Apply the changes. As a result, your external disks will be mounted to the path defined in `local.custom_longhorn_path`. | ||
|
|
||
| ### How to configure Longhorn to use the new path? | ||
|
|
||
| After setting the custom mount path, you need to configure Longhorn to recognize and use it. This typically involves: | ||
| 1. Patching the Longhorn nodes to add the new disk. | ||
| 2. Creating a new StorageClass that uses the new disk. | ||
|
|
||
| Here is an example of how you can achieve this with Terraform: | ||
|
|
||
| ```terraform | ||
| # Find the nodes with the 'ssd' storage label | ||
| data "kubernetes_nodes" "ssd_nodes" { | ||
| metadata { | ||
| labels = { | ||
| "storage" = "ssd" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # Patch the selected Longhorn nodes to add the new disk | ||
| resource "null_resource" "longhorn_patch_external_disk" { | ||
| for_each = { | ||
| for node in data.kubernetes_nodes.ssd_nodes.nodes : node.metadata[0].name => node.metadata[0].name | ||
| } | ||
| provisioner "local-exec" { | ||
| command = <<-EOT | ||
| KUBECONFIG=${var.kubeconfig_path} kubectl -n longhorn-system patch nodes.longhorn.io ${each.key} --type merge -p '{ | ||
| "spec": { | ||
| "disks": { | ||
| "external-ssd": { | ||
| "path": "${local.custom_longhorn_path}", # IMPORTANT: This path must match the 'longhorn_mount_path' for the nodes selected by the 'storage=ssd' label. | ||
| "allowScheduling": true, | ||
| "tags": ["ssd"] | ||
| } | ||
| } | ||
| } | ||
| }' | ||
| EOT | ||
| } | ||
| } | ||
|
|
||
| # Create a new StorageClass for the SSD-backed Longhorn storage | ||
| resource "kubernetes_manifest" "longhorn_ssd_storageclass" { | ||
| manifest = { | ||
| apiVersion = "storage.k8s.io/v1" | ||
| kind = "StorageClass" | ||
| metadata = { | ||
| name = "longhorn-ssd" | ||
| } | ||
| provisioner = "driver.longhorn.io" | ||
| parameters = { | ||
| numberOfReplicas = "3" | ||
| staleReplicaTimeout = "30" | ||
| diskSelector = "ssd" | ||
| fromBackup = "" | ||
| } | ||
| reclaimPolicy = "Delete" | ||
| allowVolumeExpansion = true | ||
| volumeBindingMode = "Immediate" | ||
| } | ||
|
|
||
| depends_on = [null_resource.longhorn_patch_external_disk] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.