Windows 卷装载不工作Kubernetes和WSL 2以及Docker

Windows 卷装载不工作Kubernetes和WSL 2以及Docker,windows,docker,kubernetes,windows-subsystem-for-linux,Windows,Docker,Kubernetes,Windows Subsystem For Linux,我无法在Docker和WSL2中运行的Kubernetes中使用HostPath正确装载卷。在Docker中运行的Kubernetes中装载卷时,这似乎是WSL2的问题。有人知道怎么解决这个问题吗 以下是步骤: 为我的应用程序将调试构建部署到Kubernetes。 使用Kubernetes扩展附加Visual Studio代码 导航到使用卷装载附加的我的应用程序的项目文件夹根据以下线程,wsl2尚未正式支持hostPath卷。他们确实建议了一个解决办法,尽管我很难让它发挥作用。我发现,预编/ru

我无法在Docker和WSL2中运行的Kubernetes中使用HostPath正确装载卷。在Docker中运行的Kubernetes中装载卷时,这似乎是WSL2的问题。有人知道怎么解决这个问题吗

以下是步骤:

为我的应用程序将调试构建部署到Kubernetes。 使用Kubernetes扩展附加Visual Studio代码
导航到使用卷装载附加的我的应用程序的项目文件夹根据以下线程,wsl2尚未正式支持hostPath卷。他们确实建议了一个解决办法,尽管我很难让它发挥作用。我发现,预编
/run/desktop/mnt/host/c
似乎适合我

// C:\someDir\volumeDir
hostPath:
  path: /run/desktop/mnt/host/c/someDir/volumeDir
  type: DirectoryOrCreate
线程源:

线程中建议的解决方法:

Kubernetes作为一个动态开发环境是非常糟糕的;将主机目录装载到pod中的YAML的长度与pod配置的整个其余部分差不多,因此在非开发人员Kubernetes安装上实际上不起作用。我建议您在本地构建和测试您的应用程序,并且在开始集成测试时只考虑Kubernetes。谢谢,但这是我们在WSL2之前能够成功做到的。我们回去验证它是否有效,只是在WSL2上没有。让它“再次工作”的价值非常高,因为我们有一个微服务架构,在Kubernetes集群中开发非常有价值。谢谢!我在那件事上浪费了一个小时。在Wsl发行版
/mnt/c/…
上运行,但在Windows(cmd/powershell)上,我一直在绞尽脑汁。天哪,我真不敢相信,这是一些高级的不一致性,我还浪费了一个小时来找到你的答案,泰!这是我唯一能让它工作的方法,甚至在linux子系统中不使用/mnt/c/works。Docker应该更好地记录这一点-根据您使用的Docker/WSL版本,Windows可能有3到4种hostpath配置。
====================================================================
Dockerfile
====================================================================
#
# Base image for deploying and running based on Ubuntu
#
# Support ASP.NET and does not include .NET SDK or NodeJs
# 
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-bionic AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
#
# Base image for building .NET based on Ubuntu
#
# 1. Uses .NET SDK image as the starting point 
# 2. Restore NuGet packages
# 3. Build the ASP.NET Core application
#
# Destination is /app/build which is copied to /app later on
#
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS build
WORKDIR /src
COPY ["myapp.csproj", "./"]
RUN dotnet restore "./myapp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "myapp.csproj" -c Release -o /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-bionic AS debug
RUN curl --silent --location https://deb.nodesource.com/setup_12.x | bash -
RUN apt-get install --yes nodejs
ENTRYPOINT [ "sleep", "infinity" ]

#
# Base image for building React based on Node/Ubuntu
#
# Destination is /app/ClientApp/build which is copied to /clientapp later
#
# NOTE: npm run build puts the output in the build directory
#
FROM node:12.18-buster-slim AS clientbuild
WORKDIR /src
COPY ./ClientApp /app/ClientApp
WORKDIR "/app/ClientApp"
RUN npm install
RUN npm run build
#
# Copy clientbuild:/app/ClientApp to /app/ClientApp
#
# Copy build:/app to /app
#
FROM base as final
WORKDIR /app/ClientApp
COPY --from=clientbuild /app/ClientApp .
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "myapp.dll"]

====================================================================
Kubernetes Manifest
====================================================================
apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  selector:
    matchLabels:
      app: myapp
  replicas: 1
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: localhost:6000/myapp
        ports:
        - containerPort: 5001
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /local
          name: local
        resources: {}        
      volumes:
      - name: local
        hostPath:
          path: /C/dev/myapp
          type: DirectoryOrCreate
      hostname: myapp
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: myapp
spec:
  type: LoadBalancer
  ports:
  - name: http
    protocol: TCP
    port: 5001
    targetPort: 5001
  selector:
    app: myapp
// C:\someDir\volumeDir
hostPath:
  path: /run/desktop/mnt/host/c/someDir/volumeDir
  type: DirectoryOrCreate