I'm learning Kubernetes and following Jeff Geerling's 101 tutorial. While I was still using default storage class and ReadWriteOnce for this deployment I'm trying to create drupal deployment:
---
kind: ConfigMap
apiVersion: v1
metadata:
name: drupal-config
namespace: drupal
data:
# Note: This is NOT secure. Don't use this in production!
settings.php: |-
<?php
$databases['default']['default'] = [
'database' => 'drupal',
'username' => 'drupal',
'password' => 'drupal',
'prefix' => '',
'host' => 'mariadb',
'port' => '3306',
'namespace' => 'Drupal\\Core\\Database\\Driver\\mysql',
'driver' => 'mysql',
];
$settings['hash_salt'] = 'OTk4MTYzYWI4N2E2MGIxNjlmYmQ2MTA4';
$settings['trusted_host_patterns'] = ['^.+$'];
$settings['config_sync_directory'] = 'sites/default/files/config_OTk4MTYzY';
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: drupal-files-pvc
namespace: drupal
spec:
accessModes:
- ReadWriteMany # Was ReadWriteOnce before!
resources:
requests:
storage: 1Gi
storageClassName: nfs-client
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: drupal
namespace: drupal
spec:
replicas: 1
selector:
matchLabels:
app: drupal
template:
metadata:
labels:
app: drupal
spec:
initContainers:
- name: init-files
image: 'drupal:9-apache'
command: ['/bin/bash', '-c']
args: ['cp -r /var/www/html/sites/default/files /data; chown www-data:www-data /data/ -R']
volumeMounts:
- mountPath: /data
name: drupal-files
containers:
- name: drupal
image: 'drupal:9-apache'
ports:
- containerPort: 80
livenessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 30
readinessProbe:
tcpSocket:
port: 80
initialDelaySeconds: 10
volumeMounts:
- mountPath: /var/www/html/sites/default/
name: drupal-settings
- mountPath: /var/www/html/sites/default/files/
name: drupal-files
resources:
limits:
cpu: '500m'
memory: '512Mi'
requests:
cpu: '250m'
memory: '256Mi'
volumes:
- name: drupal-settings
configMap:
name: drupal-config
- name: drupal-files
persistentVolumeClaim:
claimName: drupal-files-pvc
nfs subdir provisioner is installed with following command:
helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner --set nfs.server=10.128.0.10 --set nfs.path=/mnt/nfs_share
NAME: nfs-subdir-external-provisioner
LAST DEPLOYED: Wed Aug 23 10:57:10 2023
NAMESPACE: default
STATUS: deployed
REVISION: 1
TEST SUITE: None
Pods fail with
NAME READY STATUS RESTARTS AGE
drupal-75467d6cbd-8xp4k 0/1 Init:CrashLoopBackOff 7 (3m49s ago) 14m
describe pod:
Name: drupal-75467d6cbd-8xp4k
Namespace: drupal
Priority: 0
Service Account: default
Node: gke-my-first-cluster-1-default-pool-4ea087fd-jlpd/10.128.0.9
Start Time: Wed, 23 Aug 2023 10:58:46 +0200
Labels: app=drupal
pod-template-hash=75467d6cbd
Annotations: <none>
Status: Pending
IP: 10.104.2.24
IPs:
IP: 10.104.2.24
Controlled By: ReplicaSet/drupal-75467d6cbd
Init Containers:
init-files:
Container ID: containerd://a5c836a2c535b9baea31dcf049d29883e4fd88e6771bcab3bda74eeb135971e3
Image: drupal:9-apache
Image ID: docker.io/library/drupal@sha256:fa233c4153e7c76bce96861557e25bde34c67bb87083279a88863c0b2aa98b0e
Port: <none>
Host Port: <none>
Command:
/bin/bash
-c
Args:
cp -r /var/www/html/sites/default/files /data; chown www-data:www-data /data/ -R
State: Terminated
Reason: Error
Exit Code: 1
Started: Wed, 23 Aug 2023 10:59:30 +0200
Finished: Wed, 23 Aug 2023 10:59:30 +0200
Last State: Terminated
Reason: Error
Exit Code: 1
Started: Wed, 23 Aug 2023 10:59:03 +0200
Finished: Wed, 23 Aug 2023 10:59:03 +0200
Ready: False
Restart Count: 3
Environment: <none>
Mounts:
/data from drupal-files (rw)
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-lq8qf (ro)
Containers:
drupal:
Container ID:
Image: drupal:9-apache
Image ID:
Port: 80/TCP
Host Port: 0/TCP
State: Waiting
Reason: PodInitializing
Ready: False
Restart Count: 0
Limits:
cpu: 500m
memory: 512Mi
Requests:
cpu: 250m
memory: 256Mi
Liveness: tcp-socket :80 delay=30s timeout=1s period=10s #success=1 #failure=3
Readiness: tcp-socket :80 delay=10s timeout=1s period=10s #success=1 #failure=3
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-lq8qf (ro)
/var/www/html/sites/default/ from drupal-settings (rw)
/var/www/html/sites/default/files/ from drupal-files (rw)
Conditions:
Type Status
Initialized False
Ready False
ContainersReady False
PodScheduled True
Volumes:
drupal-settings:
Type: ConfigMap (a volume populated by a ConfigMap)
Name: drupal-config
Optional: false
drupal-files:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: drupal-files-pvc
ReadOnly: false
kube-api-access-lq8qf:
Type: Projected (a volume that contains injected data from multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: Burstable
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 57s default-scheduler Successfully assigned drupal/drupal-75467d6cbd-8xp4k to gke-my-first-cluster-1-default-pool-4ea087fd-jlpd
Normal Pulled 14s (x4 over 57s) kubelet Container image "drupal:9-apache" already present on machine
Normal Created 14s (x4 over 57s) kubelet Created container init-files
Normal Started 14s (x4 over 57s) kubelet Started container init-files
Warning BackOff 0s (x5 over 55s) kubelet Back-off restarting failed container init-files in pod drupal-75467d6cbd-8xp4k_drupal(600b8ffc-9b06-41b4-ab2f-91039df1893c)
container logs:
cp: cannot stat '/var/www/html/sites/default/files': No such file or directory
chown: changing ownership of '/data/': Operation not permitted
kubectl -n drupal get pv
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
drupal-files-pvc 1Gi RWX Retain Released drupal/drupal-files-pvc nfs 29m
pvc-fcc2af3b-5486-429b-bde6-5447e239b7aa 1Gi RWX Delete Bound drupal/drupal-files-pvc nfs-client 17m
kubectl get pvc -n drupal
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
drupal-files-pvc Bound pvc-fcc2af3b-5486-429b-bde6-5447e239b7aa 1Gi RWX nfs-client 15m
mariadb-pvc Pending standard-rwo 15m
kubectl get storageclass
NAME PROVISIONER RECLAIMPOLICY VOLUMEBINDINGMODE ALLOWVOLUMEEXPANSION AGE
enterprise-multishare-rwx filestore.csi.storage.gke.io Delete WaitForFirstConsumer true 3h36m
enterprise-rwx filestore.csi.storage.gke.io Delete WaitForFirstConsumer true 3h36m
nfs-client cluster.local/nfs-subdir-external-provisioner Delete Immediate true 24m
premium-rwo pd.csi.storage.gke.io Delete WaitForFirstConsumer true 6h26m
premium-rwx filestore.csi.storage.gke.io Delete WaitForFirstConsumer true 3h37m
standard kubernetes.io/gce-pd Delete Immediate true 6h26m
standard-rwo (default) pd.csi.storage.gke.io Delete WaitForFirstConsumer true 6h26m
standard-rwx filestore.csi.storage.gke.io Delete WaitForFirstConsumer true 3h37m
I see folders getting created on the NFS server, but they are always empty:
root@gke-my-first-cluster-1-default-pool-4ea087fd-jlpd:/mnt# ls -lah
total 12K
drwxrwxrwx 3 nobody nogroup 4.0K Aug 23 09:10 .
drwxr-xr-x 21 root root 4.0K Aug 21 10:32 ..
drwxrwxrwx 2 nobody nogroup 4.0K Aug 23 09:18 drupal-drupal-files-pvc-pvc-fcc2af3b-5486-429b-bde6-5447e239b7aa
going to the node, mounting that share and creating file there, however, is possible:
root@gke-my-first-cluster-1-default-pool-4ea087fd-jlpd:~# mount -t nfs 10.128.0.10:/mnt/nfs_share /mnt/
root@gke-my-first-cluster-1-default-pool-4ea087fd-jlpd:~# touch /mnt/testfile
root@gke-my-first-cluster-1-default-pool-4ea087fd-jlpd:~# cd /mnt/drupal-drupal-files-pvc-pvc-fcc2af3b-5486-429b-bde6-5447e239b7aa/
I have tried this both on minikube and in GKE with same results. Any help would be highly appriciated.