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.
nginx.yml
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
CodePudding user response:
- reduce the replica count to 1
- verify that /home/amjed/Documents/SPS/k8s/mongo/mnt location is valid and is accessible from the pod
CodePudding user response:
First, create folder that you want to mount inside minikube:
minikube ssh
mkdir /home/docker/some-mount
Make sure that you have some .html file inside that folder, otherwise you will get 403 error. You also need to add securityContext fsGroup inside your Deployment manifest, so that /usr/share/nginx/html is owned by nginx user (101 uid).
Snippet for your Deployment below:
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
Let me know if it works.
