<p>I am trying to use Kubernetes volumes for Nginx, but am facing an issue with it. After volumes are set Nginx is unable to serve the HTML page. Also am tried with PV and PVS this time also got the same error.</p>
<p>nginx.yml</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels: 
    app: nginx 

spec: 
  replicas: 2
  selector: 
    matchLabels: 
      app: nginx
  template:
    metadata: 
      labels:
        app: nginx
    spec: 
      volumes:
        - name: nginxhtml
          # persistentVolumeClaim: 
          #   claimName: pvc
          hostPath:
            path: /home/amjed/Documents/SPS/k8s/mongo/mnt
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: nginxhtml 
              mountPath: /usr/share/nginx/html
              
          ports: 
            - containerPort: 80



---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector: 
    app: nginx
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

</code></pre>

Amjed saleel
<p>First, create folder that you want to mount inside minikube:</p>
<pre><code>dobrucki@minikube:~$ minikube ssh
Last login: Tue Jan 11 13:54:50 2022 from 192.168.49.1
docker@minikube:~$ ls -l 
total 4
drwxr-xr-x 2 docker docker 4096 Jan 11 13:56 nginx-mount
</code></pre>
<p>This folder is what is mapped to <code>/usr/share/nginx/html</code> inside Pods, so files you paste here will be displayed when you connect to your service.
Make sure that you have some <code>.html</code> file inside that folder, otherwise you will get 403 error. For me, example <code>index.html</code> is this:</p>
<pre><code>&lt;html&gt;
 &lt;head&gt;
 &lt;/head&gt;
 &lt;body&gt;
   &lt;h1&gt;Hello World&lt;h1&gt;
 &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>You also need to add <code>securityContext</code> <code>fsGroup</code> inside your Deployment manifest, so that <code>/usr/share/nginx/html</code> is owned by nginx user (101 uid).</p>
<p>Then, apply Deployment and LoadBalancer resources using this:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels: 
    app: nginx 
spec:
  replicas: 2
  selector: 
    matchLabels: 
      app: nginx
  template:
    metadata: 
      labels:
        app: nginx
    spec:
      securityContext:
        fsGroup: 101
      volumes:
        - name: nginxhtml
          hostPath:
            path: /home/docker/nginx-mount
      containers:
        - name: nginx
          image: nginx
          volumeMounts:
            - name: nginxhtml 
              mountPath: /usr/share/nginx/html       
          ports: 
            - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx-service
spec:
  selector: 
    app: nginx
  type: LoadBalancer
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
</code></pre>
<p>After that you can check if the content is served correctly</p>
<pre><code>dobrucki@minikube:~$ curl $(minikube service nginx-service --url)
&lt;html&gt;
 &lt;head&gt;
 &lt;/head&gt;
 &lt;body&gt;
   &lt;h1&gt;Hello World&lt;h1&gt;
 &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Let me know if you have more questions.</p>
