I'm trying to attach a hard disk to Minikube. I can create a new hard drive by going to settings > storage and adding a new hard disk from there but I don't know how to attach it to Minikube. Anyone know how? any help will be appreciated!
I'm trying to attach a hard disk to Minikube. I can create a new hard drive by going to settings > storage and adding a new hard disk from there but I don't know how to attach it to Minikube. Anyone know how? any help will be appreciated!
Giving additional storage for your minikube instance can be done in multiple ways within Virtualbox environment.
Some of them are:
Create an additional Virtualbox disk and mount it to minikube instance
Mount Users host directory to minikube instance (done by default):
Use $ minikube mount ABSOLUTE_HOST_PATH:ABSOLUTE_MINIKUBE_PATH
Focusing on:
minikube instanceAssuming that:
minikube instance up and running with Virtualbox as a driverVMDK for example)Steps:
minikube instance is aware of new diskminikube instance is aware of new diskYou will need to connect to your minikube instance either with:
powershell/cmd/terminal following command:
$ minikube sshYou will need to identify the disk you've mounted earlier. You can do it with below command:
$ fdisk -lOutput of this command should look like that:
Disk /dev/sdb: 16 GiB, 17179869184 bytes, 33554432 sectors
Disk model: VBOX HARDDISK
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xb925daf0
You will need to create a partition table for this disk and format it.
$ fdisk /dev/sdbn,p,1,enter,enter - create a one partition for whole diskYou can use below guide for more reference:
You will also need to format this disk:
mkfs.ext4 /dev/sdb1 # please notice the numberYou can mount this disk with following commands:
mkdir /data/disk - create a folder to mount your disk intomount /dev/sdb1 /data/disk - mount your disk to specified location (not working after reboot)Disclaimer!
Creating an entry in
/etc/fstabto have this disk mounted between shutdowns/reboots will not work as/etc/fstabwill be overridden with each$ minikube start
To overcome /etc/fstab being overridden you will need to:
/var/lib/boot2docker/bootlocal.shmount /dev/sdb1 /data/diskThis steps will create a script that will be executed on each start of your minikube instance mounting your disk to a /data/disk.
Reference to startup commands in minikube:
By default minikube instance support hostPath:
You can create a PV and PVC with below example:
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0001
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
capacity:
storage: 1Gi
hostPath:
path: /data/disk/pv0001
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: pv0001-claim
spec:
storageClassName: standard
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
volumeName: pv0001
You can mount previously created PVC to a pod:
apiVersion: v1
kind: Pod
metadata:
name: ubuntu
spec:
volumes:
- name: storage-name
persistentVolumeClaim:
claimName: pv0001-claim
containers:
- name: ubuntu
image: ubuntu
command:
- sleep
- "infinity"
volumeMounts:
- mountPath: "/storage"
name: storage-name
I put a file in /data/disk/pv0001 to check if it's working:
$ kubectl exec -it ubuntu -- cat /storage/hello.txt
Hello there!