Persistent Volumes in Kubernetes--error

Create a PersistentVolume named as pv-nautilus. Configure the spec as storage class should be manual, set capacity to 4Gi, set access mode to ReadWriteOnce, volume type should be hostPath and set path to /mnt/itadmin (this directory is already created, you might not be able to access it directly, so you need not to worry about it).

apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-nautilus
spec:
capacity:
storage: 4Gi
accessModes:
- ReadWriteOnce
storageClassName: manual
hostPath:
path: /mnt/itadmin
type: “”

Create a PersistentVolumeClaim named as pvc-nautilus. Configure the spec as storage class should be manual, request 3Gi of the storage, set access mode to ReadWriteOnce.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-nautilus
spec:
accessModes:
- ReadWriteOnce
storageClassName: manual
resources:
requests:
storage: 3Gi

Create a pod named as pod-nautilus, mount the persistent volume you created with claim name pvc-nautilus at document root of the web server, the container within the pod should be named as container-nautilus using image httpd with latest tag only (remember to mention the tag i.e httpd:latest).

apiVersion: v1
kind: Pod
metadata:
name: pod-nautilus
spec:
containers:
- name: container-xfusion
image: httpd:latest
volumeMounts:
- name: data
mountPath: /usr/local/apache2/htdocs/
volumes:
- name: data
persistentVolumeClaim:
claimName: pvc-nautilus

Create a node port type service named web-nautilus using node port 30008 to expose the web server running within the pod.

apiVersion: v1
kind: Service
metadata:
name: web-nautilus
spec:
type: NodePort
selector:
app: nautilus
ports:
- name: http
port: 80
targetPort: 80
nodePort: 30008

application is not getting up showing 502 erorr

pods logs

AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 10.244.0.6. Set the ‘ServerName’ directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using 10.244.0.6. Set the ‘ServerName’ directive globally to suppress this message
[Thu Jan 30 10:52:33.028120 2025] [mpm_event:notice] [pid 1:tid 1] AH00489: Apache/2.4.63 (Unix) configured – resuming normal operations
[Thu Jan 30 10:52:33.028281 2025] [core:notice] [pid 1:tid 1] AH00094: Command line: ‘httpd -D FOREGROUND’

does your service have endpoints? I don’t see any labels in your pod yaml file, which will be used by selectors in your service yaml file.

Also while sharing code share it in code blocks as follows.

apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
...

Create a PersistentVolume named as pv-devops. Configure the spec as storage class should be manual, set capacity to 3Gi, set access mode to ReadWriteOnce, volume type should be hostPath and set path to /mnt/data (this directory is already created, you might not be able to access it directly, so you need not to worry about it).

apiVersion: v1
kind: PersistentVolume
metadata:
name: pv-devops
spec:
capacity:
storage: 3Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: manual
hostPath:
path: /mnt/data

Create a PersistentVolumeClaim named as pvc-devops. Configure the spec as storage class should be manual, request 1Gi of the storage, set access mode to ReadWriteOnce.

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pvc-devops
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storageClassName: manual

Create a pod named as pod-devops, mount the persistent volume you created with claim name pvc-devops at document root of the web server, the container within the pod should be named as container-devops using image httpd with latest tag only (remember to mention the tag i.e httpd:latest).

apiVersion: v1
kind: Pod
metadata:
name: pod-devops
labels:
app: web-devops
spec:
containers:
- name: container-devops
image: httpd:latest
volumeMounts:
- mountPath: /usr/local/apache2/htdocs
name: devops-volume
volumes:
- name: devops-volume
persistentVolumeClaim:
claimName: pvc-devops

apiVersion: v1
kind: Service
metadata:
name: web-devops
spec:
selector:
app: web-devops
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30008
type: NodePort

Create a node port type service named web-devops using node port 30008 to expose the web server running within the pod.

@Srikanth_Reddy Thanks for the suggestion and now issues is resolved now the main issues is the hostpath is not created in the /mnt/data is not created these where while doing claim it pod is searching for the path where it not created once again thank you :rocket::man_cartwheeling:

You’re welcome! :metal:
Happy learning.