{"record":{"id":"295f6f645826a0b0","repo":"microsoft/aspire","slug":"kubernetes-persistent-volume-volume-name-is-used-by-both","errorCode":null,"errorMessage":"Kubernetes persistent volume '{volume.Name}' is used by both local container and host-process resources ({resourceNames}). Run mode cannot provide one shared backing store across those execution types. Use only containers or only projects/executables for this volume.","messagePattern":"Kubernetes persistent volume '(.+?)' is used by both local container and host-process resources \\((.+?)\\)\\. Run mode cannot provide one shared backing store across those execution types\\. Use only containers or only projects/executables for this volume\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentExtensions.cs","lineNumber":189,"sourceCode":"            {\n                var containers = volumeGroup.Where(item => item.Resource is ContainerResource).ToArray();\n\n                // Only host processes that asked for the environment path materialize an IAspireStore\n                // directory. A project or executable bound to a publish-only volume consumes no local\n                // backing store in run mode, so it cannot conflict with a container's named volume.\n                // Rejecting it would break AppHosts that predate the environment-path feature.\n                //\n                // Resolving the env name covers both spellings, and is order-independent because it\n                // runs here rather than when either builder method was called.\n                var hostProcesses = volumeGroup.Where(item =>\n                    item.Resource is ProjectResource or ExecutableResource &&\n                    GetLocalPathEnvironmentVariableName(item.Resource, item.Annotation) is not null).ToArray();\n\n                if (containers.Length > 0 && hostProcesses.Length > 0)\n                {\n                    var volume = volumeGroup.First().Annotation.Volume;\n                    var resourceNames = string.Join(\", \", containers.Concat(hostProcesses).Select(item => $\"'{item.Resource.Name}'\"));\n                    throw new DistributedApplicationException(\n                        $\"Kubernetes persistent volume '{volume.Name}' is used by both local container and host-process resources ({resourceNames}). \" +\n                        $\"Run mode cannot provide one shared backing store across those execution types. Use only containers or only projects/executables for this volume.\");\n                }\n            }\n        }\n    }\n\n    private static string? GetLocalPathEnvironmentVariableName(\n        IResource resource,\n        KubernetesPersistentVolumeBindingAnnotation annotation)\n    {\n        // WithPersistentVolume(volume, mountPath, env) records the env on the binding itself.\n        if (annotation.EnvironmentVariableName is not null)\n        {\n            return annotation.EnvironmentVariableName;\n        }\n\n        // The name-match composition spells it on a separate mount instead:","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentExtensions.cs#L171-L207","documentation":"A Kubernetes persistent volume is bound simultaneously by local container resources and by host-process resources (projects/executables running on the host). Run mode cannot provide a single shared backing store across those two execution types, so validation throws DistributedApplicationException.","triggerScenarios":"The same named persistent volume is referenced both by a container resource and by a project/executable resource, then the AppHost is run.","commonSituations":"Sharing a data directory between a database container (e.g. Postgres) and a worker console project that processes the same files locally; mixed container/host-process topologies evolving over time.","solutions":["Use the volume exclusively with container resources, or exclusively with projects/executables.","Split the storage into two separate volumes: one for containers, one for host-process resources.","Switch the host-process consumer to a container so all consumers share the same execution type."],"exampleFix":"// before\nvolume.Bind(vol, postgres);   // container\nvolume.Bind(vol, migration);  // executable -> conflict\n// after\nvolume.Bind(vol, postgres);\nmigrationVolume.Bind(migrationVolume, migration);","handlingStrategy":"validation","validationCode":"bool allContainers = bindings.All(b => b.Resource is ContainerResource) || bindings.All(b => b.Resource is ProjectResource or ExecutableResource);","typeGuard":null,"tryCatchPattern":"try { RunAppHostAsync(); } catch (DistributedApplicationException ex) when (ex.Message.Contains(\"both local container and host-process\")) { /* split volumes by execution type */ }","preventionTips":["Decide per volume whether consumers are containers or host processes","Split shared storage into separate volumes per execution type","Document volume ownership in the AppHost"],"tags":["kubernetes","volumes","run-mode","shared-storage"],"backgroundTag":"conflicting-config-options","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}