<p>I have multiple micro services in my project. I want to dynamically pause and resume them without losing the data.</p>

<p>For example: I am deploying an theia ide and user created a folder. I want to down this service for sometime and resume again with the data.</p>

<p>References: 
<a href="https://github.com/theia-ide/theia" rel="nofollow noreferrer">https://github.com/theia-ide/theia</a></p>

<p>I have already tried with reducing replicas to 0 and 1. It removes the data. I want the data to be persistent.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: servicetest
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      run: servicetest
  template:
    metadata:
      labels:
        run: servicetest
    spec:
      containers:
      - image: gcr.io/YYYY-ZZZZ-249311/test
        imagePullPolicy: IfNotPresent
        name: servicetest
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
            - name: data
              mountPath: /data/
      volumes:
      - name: data
        persistentVolumeClaim:
          claimName: service-pv-claim
---
apiVersion: v1
kind: Service
metadata:
  labels:
    run: servicetest
  name: servicetest
spec:
  ports:
  - name: web
    port: 80
    protocol: TCP
    targetPort: 3000
  - name: deployport
    port: 8080
    protocol: TCP
    targetPort: 8080
  selector:
    run: servicetest
  type: LoadBalancer


kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: service-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 3Gi
</code></pre>

Imrahamed
<p>Whether your underlying storage gets deleted depends on the persistent volume's <a href="https://kubernetes.io/docs/tasks/administer-cluster/change-pv-reclaim-policy/#why-change-reclaim-policy-of-a-persistentvolume" rel="nofollow noreferrer">reclaim policy</a>. 
If you set the policy to <code>Retain</code>, it should keep your pod's PV around for later rather than deleting it's contents and purging the volume.</p>

<p>Also worth looking into <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#deployment-and-scaling-guarantees" rel="nofollow noreferrer">statefulset</a> if you're using this deployment of size 1, because deployments are "at least N" as opposed to statefulsets being "at most N" replicas. Statefulsets also let you have a different volume associated with each replica.</p>
