Question

Unable to attach or mount volumes

Posted December 23, 2021 260 views
NginxPHPUbuntu 16.04Block StorageKubernetes

Unable to attach or mount volumes: unmounted volumes=[code], unattached volumes=[code kube-api-access-fkxm9]: timed out waiting for the condition

Attach failed for volume “pvc” : Attach timeout for volume

Error from server (BadRequest): container “nginx” in pod “nginx-8589fdb7c-ktjcg” is waiting to start: ContainerCreating

Using this same content : https://www.digitalocean.com/community/tutorials/how-to-deploy-a-php-application-with-kubernetes-on-ubuntu-16-04

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hello,

Is this on a Managed Kubernetes cluster? If so, you would need to use the following configuration:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: my-csi-app-set
spec:
  selector:
    matchLabels:
      app: mypod
  serviceName: "my-frontend"
  replicas: 1
  template:
    metadata:
      labels:
        app: mypod
    spec:
      containers:
      - name: my-frontend
        image: busybox
        args:
        - sleep
        - infinity
        volumeMounts:
        - mountPath: "/data"
          name: csi-pvc
  volumeClaimTemplates:
  - metadata:
      name: csi-pvc
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
      storageClassName: do-block-storage

For more information on this, you could take a look at the official documentation here:

https://docs.digitalocean.com/products/kubernetes/how-to/add-volumes/

Best,
Bobby