skip to Main Content

I’m running into an issue where my code is not being mounted into my Docker container when using Skaffold on Windows. My setup involves a Kubernetes cluster managed by Skaffold, and I’m developing on a Windows machine.
Here’s my setup:
Skaffold Configuration (skaffold.yaml):

apiVersion: skaffold/v2beta12
kind: Config
metadata:
  name: healthflow
build:
  local:
    push: true
  artifacts:
    - image: yazangali/authservice
      context: authservice
      docker:
        dockerfile: Dockerfile # Production Dockerfile
    - image: yazangali/userservice
      context: userservice
      docker:
        dockerfile: Dockerfile # Production Dockerfile
deploy:
  kubectl:
    manifests:
      - k8s/authservice/deployment.yaml
      - k8s/authservice/service.yaml
      - k8s/userservice/deployment.yaml
      - k8s/userservice/service.yaml
      - k8s/nginx-deployment.yaml
      - k8s/nginx-service.yaml
      - k8s/nginx-configmap.yaml
profiles:
  - name: development
    build:
      artifacts:
        - image: yazangali/authservice-dev
          context: authservice
          docker:
            dockerfile: Dockerfile.dev # Use the dev Dockerfile for development
        - image: yazangali/userservice-dev
          context: userservice
          docker:
            dockerfile: Dockerfile.dev # Use the dev Dockerfile for development
    deploy:
      kubectl:
        manifests:
          - k8s/authservice/deployment-dev.yaml
          - k8s/authservice/service.yaml
          - k8s/userservice/deployment-dev.yaml
          - k8s/userservice/service.yaml
          - k8s/nginx-deployment.yaml
          - k8s/nginx-service.yaml
          - k8s/nginx-configmap.yaml
  - name: production
    build:
      artifacts:
        - image: yazangali/authservice
          context: authservice
          docker:
            dockerfile: Dockerfile # Use the production Dockerfile
        - image: yazangali/userservice
          context: userservice
          docker:
            dockerfile: Dockerfile # Use the production Dockerfile
    deploy:
      kubectl:
        manifests:
          - k8s/authservice/deployment.yaml
          - k8s/authservice/service.yaml
          - k8s/userservice/deployment.yaml
          - k8s/userservice/service.yaml
          - k8s/nginx-deployment.yaml
          - k8s/nginx-service.yaml
          - k8s/nginx-configmap.yaml

Kubernetes Deployment for Development (deployment-dev.yaml):

apiVersion: apps/v1
kind: Deployment
metadata:
  name: authservice
spec:
  replicas: 1
  selector:
    matchLabels:
      app: authservice
  template:
    metadata:
      labels:
        app: authservice
    spec:
      containers:
        - name: authservice
          image: yazangali/authservice-dev
          ports:
            - containerPort: 3000
          env:
            - name: NODE_ENV
              value: "development"
          volumeMounts:
            - name: auth-code
              mountPath: /usr/src/app
      volumes:
        - name: auth-code
          hostPath:
            path: "/mnt/c/Users/FPCC/Desktop/web-dev/healthflow/authservice"
            type: DirectoryOrCreate

Dockerfile for Development (Dockerfile.dev):

FROM node:14

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install

COPY . .

CMD ["npm", "run", "dev"]

When I run

skaffold dev -p development

the services are created, but the src folder inside the container is empty. As a result, Nodemon cannot find the src/index.ts file and throws an ERR_MODULE_NOT_FOUND error.

I’ve ensured that Docker Desktop is set up to share the C: drive and that the paths are correctly formatted using /mnt/c/….

I believe the problem is in the way of how mounting works in kubernetes pods.

What could be causing the code not to mount properly inside the container? How can I resolve this issue so that my code is correctly mounted and Nodemon can detect changes?

I configured Skaffold to use a development profile with volume mounts to share my local code with the Docker container. I ensured the paths were correct and that Docker Desktop was set up to share my C: drive. I expected the src folder inside the container to contain my local code and for Nodemon to restart the service on code changes.

However, when I ran skaffold dev -p development, the services started, but the src folder inside the container was empty. Nodemon couldn’t find the src/index.ts file and threw an ERR_MODULE_NOT_FOUND error.

UPDATE : I tried to test with a test pod (its mountning the folders but without mounting anything inside them)
// test-pod.yaml

apiVersion: v1
kind: Pod
metadata:
  name: test-pod
spec:
  containers:
  - name: test-container
    image: alpine
    command: ["sh", "-c", "while true; do sleep 30; done"]
    volumeMounts:
    - mountPath: /mnt/c/Users/FPCC/Desktop/web-dev/healthflow/authservice/
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      path: /mnt/c/Users/FPCC/Desktop/web-dev/healthflow/authservice/
      type: DirectoryOrCreate

then I try after applying the pod to
kubectl exec -it test-pod -- sh
and then I try to list what I got so I try
/ # ls mnt/c/Users/FPCC/Desktop/web-dev/healthflow/ and it result in listing the folder authservice !
if i try to list what inside it, it’s empty (non of my host machine code was mounted)

2

Answers


  1. Chosen as BEST ANSWER

    I managed to fix the problem without using mounting or host paths at the end It is done just by skaffold and nodemon only I tried before with skaffold sync actually but the problem was in the dest now it is working with that settings sync: manual: - src: 'src/**/*.ts' dest: .


  2. Here’s a documentation Airwave Tech that corresponds on mounting skaffold using Windows.

    You can check this documentation as reference. Including as well this documentation.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search