apiVersion: v1 kind: PersistentVolume metadata: name: mosquitto-data-pv spec: capacity: storage: 3Ti volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Retain storageClassName: local-storage local: path: /path/to/files/mosquitto/data # This must exist on the host nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - example_host
microk8s kubectl apply -f mosquitto-data-pv.yaml
1
persistentvolume/mosquitto-data-pv created
Verify PV
microk8s kubectl get pv
1 2 3
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE mosquitto-configinc-pv 3Ti RWO Retain Available local-storage 97s mosquitto-data-pv 3Ti RWO Retain Available local-storage 35s
Persistent Volume Claims
configinc
mosquitto-configinc-pvc.yaml
mosquitto-configinc-pvc.yaml Bonds to mosquitto-configinc-pv
1 2 3 4 5 6 7 8 9 10 11 12
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mosquitto-configinc-pvc spec: storageClassName: local-storage # Empty string must be explicitly set otherwise default StorageClass will be set accessModes: - ReadWriteOnce volumeName: mosquitto-configinc-pv resources: requests: storage: 3Ti
microk8s status microk8s kubectl show pods microk8s kubectl microk8s kubectl logs microk8s kubectl describe pods
Common Errors
Error from server (BadRequest): container in pod is waiting to start: ContainerCreating You probably need to change the permissions on the PV directory. This path is what is written in the PersistentVolume in the path varaibale. A quick chmod -R 777 to this path will most likely fix the issue. The conatiner should update the permissions once it runs.
Service yaml file
We need to expose the service to the outside world. Thankfully microk8s has a built in loadbalancer called metallb
Replace Y with the MQTT port number. Default 1883 Replace Z with the MQTT API number Default 9001