Shrinking a Metrics service volume with data loss

To shrink a Metrics service volume with data loss:

  1. Get the name of the volume used by the Metrics service. You will need this volume name to locate volume data and volume replicas. Replica names begin with the volume name.

    sudo k0s kubectl get pvc metrics -n kuma -o json | jq '.spec.volumeName'

  2. Stop the Metrics service.

    sudo k0s kubectl scale deployment/metrics -n kuma --replicas=0

  3. Make sure that the metrics-<UID> pod of the Metrics service is not present in the command output.

    sudo k0s kubectl get pods -n kuma

  4. If the pod does not disappear within a few minutes, force its deletion. The pod name must be taken from the output of the previous command.

    sudo k0s kubectl delete pod metrics-<UID> -n kuma --force

  5. Make sure that the Metrics service volume is in the detached state.

    sudo k0s kubectl get volume <volume_name> -n longhorn-system -o json | jq '.status.state'

  6. Delete the PVC of the Metrics service.

    sudo k0s kubectl delete pvc metrics -n kuma

  7. Make sure the Metrics service volume is not present in the output of the following command:

    sudo k0s kubectl get volume <volume_name> -n longhorn-system

    On all worker nodes, directories with names beginning with the name of the deleted volume should disappear from the /opt/longhorn/replicas directory. If this does not happen, you need to delete them manually. Take care not to delete replicas that belong to other volumes by mistake.

  8. Specify the value in the 'storage' line, then create a PVC for the Metrics service.

    sudo k0s kubectl apply -f - <<EOF

    ---

    apiVersion: v1

    kind: PersistentVolumeClaim

    metadata:

    name: metrics

    namespace: kuma

    spec:

    accessModes:

    - ReadWriteOnce

    storageClassName: kuma-network-storage

    resources:

    requests:

    storage: 30Gi

    EOF

  9. Start the Metrics service, increasing the number of replicas to 1.

    sudo k0s kubectl scale deployment/metrics -n kuma --replicas=1

  10. Make sure that the Metrics service is running and that the metrics are available in the KUMA web interface.

The Metrics service volume is successfully shrunk with data loss.

Page top