Create a persistent volume 

PVlogs.yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: logs
spec:
  storageClassName: rook-ceph-block
  accessModes:
    - ReadWriteMany
  volumeMode: Filesystem
  resources:
    requests:
      storage: 4Gi
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: topology.kubernetes.io/region
            operator: In
            values:
            - us-west


kubectl apply -f PVlogs.yaml
kubectl describe pvc logs

mount in a deployment 

Change the container name 

DepManage.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: managment-deployment
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ubuntu
  template:
    metadata:
      labels:
        app: ubuntu
    spec:
      containers:
        - name: management-ubuntu
          image: ubuntu
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: logs
              mountPath: /logs
          resources:
            limits:
              cpu: 1
              memory: 4Gi
            requests:
              cpu: 100m
              memory: 500Mi
          command:
            - sleep
            - "1000000"     

Note: This is a sort of persistent pod it will run for 100000 seconds because deployments in Nautilus are limited to 2 weeks


#apply the template

kubectl apply -f DepManage.yaml

#shell into the deployment

 kubectl exec -it managment-deployment -c management-ubuntu -- /bin/bash 

The PV should be mounted under /logs the data here is persistent, Note the access modes when creating these as they may have implications for what you are trying to do.  Most pods will use ReadWriteOnce

  • ReadWriteOnce
    • the volume can be mounted as read-write by a single node. ReadWriteOnce access mode still can allow multiple pods to access (read from or write to) that volume when the pods are running on the same node
  • ReadOnlyMany
    • the volume can be mounted as read-only by many nodes.
  • ReadWriteMany
    • the volume can be mounted as read-write by many nodes.

when done scale down the deployment 

kubectl scale deployment managment-deployment --replicas=0



See https://nrp.ai/documentation/userdocs/storage/intro/ for more information.

 
   



  • No labels