Hi All,
I have Ubuntu 22.04 installed with Docker Desktop 4.35.1 with Kubernetes engine enabled.
Docker container with volume mount works perfect but switching to deploy the same container in Kubernetes with persistent volume fails - the mount point in the pod is empty. any advise will be appreciated.
Below are the deployment file and status
Thanks,
Itamar
The deployment file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: imnginx-deploy
labels:
app: imnginx-deploy
spec:
progressDeadlineSeconds: 600
replicas: 1
selector:
matchLabels:
app: imnginx-deploy
template:
metadata:
labels:
app: imnginx-deploy
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- name: tmp-volume-name
mountPath: /usr/share/nginx/html
ports:
- containerPort: 80
volumes:
- name: tmp-volume-name
persistentVolumeClaim:
claimName: nginxpv
---
#Create PV and PVC for local storage
apiVersion: v1
kind: PersistentVolume
metadata:
name: nginxpv
labels:
type: local
spec:
storageClassName: hostpath
capacity:
storage: 1Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/nginx/html"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nginxpv
spec:
accessModes:
- ReadWriteOnce
storageClassName: hostpath
resources:
requests:
storage: 1Gi
---
# Create external Service for external IP (localhost - 127.0.0.1)
apiVersion: v1
kind: Service
metadata:
name: imnginx-service
spec:
selector:
app: imnginx-deploy
type: LoadBalancer
ports:
- protocol: TCP
port: 80
targetPort: 80
nodePort: 30000
Status of Persistent Volume:
$ k describe pv nginxpv
Name: nginxpv
Labels: type=local
Annotations: pv.kubernetes.io/bound-by-controller: yes
Finalizers: [kubernetes.io/pv-protection]
StorageClass: hostpath
Status: Bound
Claim: default/nginxpv
Reclaim Policy: Retain
Access Modes: RWO
VolumeMode: Filesystem
Capacity: 1Gi
Node Affinity: <none>
Message:
Source:
Type: HostPath (bare host directory volume)
Path: /mnt/nginx/html
HostPathType:
Events: <none>
PV Claims:
$ k describe pvc nginxpv
Name: nginxpv
Namespace: default
StorageClass: hostpath
Status: Bound
Volume: nginxpv
Labels: <none>
Annotations: pv.kubernetes.io/bind-completed: yes
pv.kubernetes.io/bound-by-controller: yes
Finalizers: [kubernetes.io/pvc-protection]
Capacity: 1Gi
Access Modes: RWO
VolumeMode: Filesystem
Used By: imnginx-deploy-56fcdf46dd-nqztw
Events: <none>
Empty mount in POD:
$ k get pod
NAME READY STATUS RESTARTS AGE
imnginx-deploy-56fcdf46dd-nqztw 1/1 Running 0 2m21s
$ k exec -it imnginx-deploy-56fcdf46dd-nqztw -- bash
root@imnginx-deploy-56fcdf46dd-nqztw:/# ls -la /usr/share/nginx/html
total 4
drwxr-xr-x 2 root root 40 Nov 14 12:15 .
drwxr-xr-x 3 root root 4096 Nov 12 02:03 ..
root@imnginx-deploy-56fcdf46dd-nqztw:/# exit
exit
File do exists in host folder:
$ ls -la /mnt/nginx/html/
total 12
drwxr-xr-x 2 admin domain users 4096 Nov 14 14:16 .
drwxr-xr-x 3 admin domain users 4096 Nov 14 14:15 ..
-rw-r--r-- 1 admin domain users 647 Nov 14 14:16 index.html