<p>I have a application of workload deployment and need to change it to statefulset</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: app
  labels:
    app: app
spec:
  replicas: 1
  selector:
    matchLabels:
      app: app
  template:
    metadata:
      labels:
        app: app
    spec:
      containers:
      - name: app
        image: nginx:1.14.2
        ports:
        - containerPort: 80 
        volumeMounts:
        - name: data
          subPath: app/log
          mountPath: /opt/app/log
      volumes:
      - name: data
        peristentVolumeClaim:
           claimName: pv-app-claim

</code></pre>
<p><strong>PV</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-app
  labels:
    pv: app
spec:
  storageClassName: &quot;default&quot;
  capacity:
    storage: 8Gi
  accessModes:
  - ReadWriteMany
  persistentVolumeclaimPolicy: Retain
  nfs:
     server: someIP
     path: &quot;/somepath&quot;
</code></pre>
<p><strong>PVC</strong></p>
<pre><code>apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-app-claim
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: 8Gi
  selector:
    matchLabels:
        pv: app
</code></pre>
<p>I have tried to change the required file but struck in a place where I need the data in the volume to be there even when I'm moving to statefulset. In statefulset we use volumeclaimtemplate this is where i'm struck how to retain the data and claim  with volumeclaimtemplate.</p>
<p>Note: I'm going to use only one pod</p>

<ul>
<li>If you want to use existing PVC in statefulset then you should not mention it under
<code>volumeclaimtemplate </code> as <code>volumeclaimtemplate </code> will create a new PVC .</li>
<li>You should mention it under <code>pod spec</code> just like you mention in a deployment</li>
</ul>
<p>Example:</p>
<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web1
spec:
  selector:
    matchLabels:
      app: nginx
  serviceName: &quot;nginx&quot;
  replicas: 1 
  template:
    metadata:
      labels:
        app: nginx 
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx1
        imagePullPolicy: IfNotPresent
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web1
        volumeMounts:
        - name: www1
          mountPath: /usr/share/nginx/html
      volumes:
      - name: www1
        peristentVolumeClaim:
           claimName: pv-app-claim
</code></pre>
