代码改变世界

k8s 在WSL2中以 hostPath 挂载本地卷

2022-03-24 15:17  Dorisoy  阅读(378)  评论(0编辑  收藏  举报

wsl2 中的映射

 

 

 

配置 yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations: {}
  labels:
    app: demo
  name: demo
  namespace: default
  resourceVersion: '315836'
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: demo
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: demo
    spec:
      containers:
        - image: httpd
          imagePullPolicy: Always
          name: httpd
          ports:
            - containerPort: 80
              protocol: TCP
          resources: {}
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
          volumeMounts:
            - mountPath: /app
              name: v1
            - mountPath: '/remote_debugger:rw'
              name: v2
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
      volumes:
        - hostPath:
            path: /run/desktop/mnt/host/d/microservices/dapr.eshop/services/accountservice/host/bin/debug/net6.0
            type: ''
          name: v1
        - hostPath:
            path: /run/desktop/mnt/host/c/users/administrator/vsdbg/vs2017u5
            type: ''
          name: v2

进入pod 容器查看:

 

 已经挂载成功。注意对应目录:

Windows WSL2 K8S-docker.io/hostpath
C:// /mnt/c
/run/desktop/mnt/host/c
D:// /mnt/d
/run/desktop/mnt/host/d

 

文件浏览器: