0

I am trying to deploy a Magento app but I am getting the following error. This cluster is created on EKS and PVC is there enter image description here

persistentvolumeclaim "media" not found Error: failed to start container "magento-web": Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "process_linux.go:449: container init caused "rootfs_linux.go:58: mounting \"/var/lib/kubelet/pods/8865b7dsdbd-721c-45f3-ab77-43a5f5da1362/volume-subpaths/nginx-config/magento-web/0\" to rootfs \"/var/lib/docker/overlay2/b1b3faa530b6sasas4ad6a9e62db641c5589fef3d29a9ab01f2db594652851a1814a6/merged\" at \"/var/lib/docker/overlay2/b1b3faa530b64ad6a9e62db641c5589fef3d29a9ab01fdsd2db594652851a1814a6/merged/etc/nginx/conf.d/default.conf\" caused \"not a directory\""": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type Back-off restarting failed container

    apiVersion: v1
kind: Service
metadata:
  name: magento-web
  namespace: magento
  labels:
    app: magento-web
    k8s-app: magento
spec:
  ports:
  - name: "http"
    port: 80
    protocol: TCP
    targetPort: 80
  selector:
    app: magento-web

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: magento-web
  namespace: magento
  labels:
    app: magento-web
    k8s-app: magento
spec:
  selector:
    matchLabels:
      app: magento-web
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 30%
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: magento-web
        k8s-app: magento
    spec:
      containers:
      - image: nginx:mainline
        imagePullPolicy: Always
        name: magento-web
        ports:
        - containerPort: 80
          protocol: TCP
        resources:
          limits:
            cpu: 10m
            memory: 128Mi
          requests:
            cpu: 10m
            memory: 128Mi
        volumeMounts:
        - mountPath: /etc/nginx/conf.d/default.conf
          name: nginx-config
          subPath: default.conf
        - mountPath: /var/www/html/magento2.conf
          name: nginx-config
          subPath: magento2.conf
        - name: media
          mountPath: /var/www/html/pub/media
        - mountPath: /var/www/html/pub/static
          name: static
      volumes:
      - configMap:
          defaultMode: 420
          name: nginx
        name: nginx-config
      - name: media
        persistentVolumeClaim:
          claimName: media
      - name: static
        persistentVolumeClaim:
          claimName: static

kubectl get pvc -n magento

enter image description here

volumes:
      - configMap:
          defaultMode: 420
          name: nginx
        name: nginx-config
      - name: media
        persistentVolumeClaim:
          claimName: media
      - name: static
        persistentVolumeClaim:
          claimName: static
  • did you create pvc? what is the output of `kubectl get pvc -n magento` ? – hoque Jul 20 '20 at 11:37
  • data-db-0 Bound pvc-e4b8aaa6-86fe-4f73-8343-80trt11afcfcetrbf 10Gi RWO gp2 38m media Bound pvc-1bf3011e-685c-41f6-be86-9ftrtr12862c3c4a 10Gi RWO gp2 21m static Bound pvc-b12cc1b6-32b2-4d9f-aeeweef-af4a2e55a9ca 2Gi RWO gp2 21m – programmer one Jul 20 '20 at 11:38
  • can you share your configmap yaml as well. – Tarun Khosla Jul 20 '20 at 12:11

1 Answers1

2

As the error states "Are you trying to mount a directory onto a file (or vice-versa)" for default.conf ,

The configmap usage seems incorrect , try using like this

 - configMap:
          items:
          - key: default.conf
            path: default.conf
          name: nginx
        name: nginx-config

Read here - https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-specific-path-in-the-volume

Tarun Khosla
  • 1,274
  • 7
  • 10
  • volumes: - configMap: defaultMode: 420 name: nginx name: nginx-config - name: media persistentVolumeClaim: claimName: media - name: static persistentVolumeClaim: claimName: static – programmer one Jul 20 '20 at 12:15
  • @programmerone kubectl describe configmap , could you tell the output – Tarun Khosla Jul 20 '20 at 12:26
  • Hi Tarun, thanks for your replies. Have added configs – programmer one Jul 20 '20 at 12:56
  • @programmerone - kubectl describe configmap nginx -o yaml , can you share this output. – Tarun Khosla Jul 20 '20 at 13:04
  • The one in the default namespace has a log output and one in the Magento namespace is empty. Not sure why its getting created in the default namespace Name: nginx-9h974c5kcc Namespace: default Labels: Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","data":{"default.conf":"resolver kube-dns.kube-system.svc.cluster.local valid=5s;\n\nupstream fastcgi_backend {\n serv... – programmer one Jul 20 '20 at 13:13
  • Name: nginx Namespace: magento Labels: Annotations: magento namespace output Data ==== Events: – programmer one Jul 20 '20 at 13:14