I set up my volume and volume claims. I have my namespace and in there a deployment with php-fpm, nginx and mysql for local testing on Minikube
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
namespace: smt-local
spec:
replicas: 3
selector:
matchLabels:
app: web
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
minReadySeconds: 5
template:
metadata:
labels:
app: web
spec:
containers:
- name: laravel
image: smart48/smt-laravel:latest
ports:
- containerPort: 9000
resources:
requests:
cpu: 250m
limits:
cpu: 500m
volumeMounts:
- name: code-storage
mountPath: /data/smtapp
# examples
# - name: orientdb-config
# mountPath: /data/orientdb/config
# - name: orientdb-databases
# mountPath: /data/orientdb/databases
# - name: orientdb-backup
# mountPath: /data/orientdb/backup
- name: nginx
image: smart48/smt-nginx:latest
ports:
- containerPort: 9376
volumeMounts:
# example
- name: nginx-config
mountPath: /data/nginx/config
- name: laravel-horizon
image: smart48/smt-laravel-horizon:latest
# not sure if we need the port and volume here
# ports:
# - containerPort: 9377
# volumeMounts:
# - name: code
# mountPath: /code
command: ["/usr/local/bin/php", "artisan", "horizon"]
lifecycle:
preStop:
exec:
command: ["/usr/local/bin/php", "artisan", "horizon:terminate"]
- name: mysql
image: smart48/smt-mysql:latest
imagePullPolicy: Never
env:
- name: mysql_ROOT_PASSWORD
value: .sweetpwd.
- name: mysql_DATABASE
value: my_db
- name: mysql_USER
value: db_user
- name: mysql_PASSWORD
value: .mypwd
args: ["--default-authentication-plugin=mysql_native_password"]
ports:
- containerPort: 3306
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
volumes:
- name: code-storage
persistentVolumeClaim:
claimName: code-pv-claim
- name: nginx-config
persistentVolumeClaim:
claimName: code-pv-claim
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: mysql-pv-claim
However the data directories (empty atm and nothing added to /data) cannot be mounted:
kubectl describe pod app-67fc69b8d8-nkr6d -n smt-local
Name: app-67fc69b8d8-nkr6d
Namespace: smt-local
Priority: 0
Node: minikube/192.168.64.5
Start Time: Fri, 04 Dec 2020 13:54:56 +0700
Labels: app=web
pod-template-hash=67fc69b8d8
Annotations: <none>
Status: Pending
IP:
IPs: <none>
Controlled By: ReplicaSet/app-67fc69b8d8
Containers:
laravel:
Container ID:
Image: smart48/smt-laravel:latest
Image ID:
Port: 9000/TCP
Host Port: 0/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Limits:
cpu: 500m
Requests:
cpu: 250m
Environment: <none>
Mounts:
/data/smtapp from code-storage (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-cp4nw (ro)
nginx:
Container ID:
Image: smart48/smt-nginx:latest
Image ID:
Port: 9376/TCP
Host Port: 0/TCP
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/data/nginx/config from nginx-config (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-cp4nw (ro)
laravel-horizon:
Container ID:
Image: smart48/smt-laravel-horizon:latest
Image ID:
Port: <none>
Host Port: <none>
Command:
/usr/local/bin/php
artisan
horizon
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from default-token-cp4nw (ro)
mysql:
Container ID:
Image: smart48/smt-mysql:latest
Image ID:
Port: 3306/TCP
Host Port: 0/TCP
Args:
--default-authentication-plugin=mysql_native_password
State: Waiting
Reason: ContainerCreating
Ready: False
Restart Count: 0
Environment:
mysql_ROOT_PASSWORD: .sweetpwd.
mysql_DATABASE: my_db
mysql_USER: db_user
mysql_PASSWORD: .mypwd
Mounts:
/var/lib/mysql from mysql-persistent-storage (rw)
/var/run/secrets/kubernetes.io/serviceaccount from default-token-cp4nw (ro)
Conditions:
Type Status
Initialized True
Ready False
ContainersReady False
PodScheduled True
Volumes:
code-storage:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: code-pv-claim
ReadOnly: false
nginx-config:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: code-pv-claim
ReadOnly: false
mysql-persistent-storage:
Type: PersistentVolumeClaim (a reference to a PersistentVolumeClaim in the same namespace)
ClaimName: mysql-pv-claim
ReadOnly: false
default-token-cp4nw:
Type: Secret (a volume populated by a Secret)
SecretName: default-token-cp4nw
Optional: false
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 2m35s default-scheduler Successfully assigned smt-local/app-67fc69b8d8-nkr6d to minikube
Warning FailedMount 31s kubelet Unable to attach or mount volumes: unmounted volumes=[code-storage], unattached volumes=[code-storage default-token-cp4nw nginx-config mysql-persistent-storage]: timed out waiting for the condition
Here code pv
apiVersion: v1
kind: PersistentVolume
metadata:
name: code-pv
namespace: smt-local
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 20Gi
hostPath:
# minikube is configured to persist files stored under /data/ and a few
# other directories such as /var/lib/minikube in the _vm_
path: /data
and code pvc
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: code-pv-claim
namespace: smt-local
labels:
type: code
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
Why would I get
Warning FailedMount 31s kubelet Unable to attach or mount volumes: unmounted volumes=[code-storage], unattached volumes=[code-storage default-token-cp4nw nginx-config mysql-persistent-storage]: timed out waiting for the condition
And a little later these events:
vents:
Type Reason Age From Message
---- ------ ---- ---- -------
Warning FailedMount 9m54s (x42 over 3h8m) kubelet Unable to attach or mount volumes: unmounted volumes=[nginx-config], unattached volumes=[code-storage default-token-cp4nw nginx-config mysql-persistent-storage]: timed out waiting for the condition
Warning FailedMount 5m20s (x22 over 3h31m) kubelet Unable to attach or mount volumes: unmounted volumes=[nginx-config], unattached volumes=[default-token-cp4nw nginx-config mysql-persistent-storage code-storage]: timed out waiting for the condition
Warning FailedMount 50s (x15 over 166m) kubelet Unable to attach or mount volumes: unmounted volumes=[nginx-config], unattached volumes=[mysql-persistent-storage code-storage default-token-cp4nw nginx-config]: timed out waiting for the condition