<p>I have a statefulset, I want to add another container-2 for that statefulset &amp; I want that container-2 to access container-1's pv's (created using <strong>volumeClaimTemplates:</strong>)</p>

<p>Any way we can achieve above?</p>

sudhir tataraju
<p>You asked quite general question without any specific requirements (only GKE tags) and 2 containers using the same PV.</p>

<p>I've tested very simple example of <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/" rel="nofollow noreferrer">statefulset</a>.
When you are using <code>statefulset</code> you must remember about some <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#limitations" rel="nofollow noreferrer">statefulset limitations</a>.</p>

<p>To this test I've used Kubernetes docs example from <a href="https://kubernetes.io/docs/concepts/workloads/controllers/statefulset/#components" rel="nofollow noreferrer">here</a> (using busybox instead of nginx) and <code>GKE</code> cluster <code>v1.14.10-gke.36</code>.
Please keep in mind that </p>

<p><strong>Statefulset and service yaml below:</strong></p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: busybox-service
  labels:
    app: busybox
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: busybox
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: busybox
spec:
  serviceName: busybox
  replicas: 1
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
    spec:
      containers:
        - image: busybox
          args: [/bin/sh, -c, 'sleep 9999' ]
          volumeMounts:
            - mountPath: /test
              name: busybox-volume 
          name: busybox
        - image: busybox
          args: [/bin/sh, -c, 'sleep 9999' ]
          volumeMounts:
            - mountPath: /test
              name: busybox-volume  
          name: busybox-two
  volumeClaimTemplates:
  - metadata:
      name: busybox-volume 
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
</code></pre>

<p><strong>Output:</strong></p>

<pre><code>$ kubectl get pods,pv,pvc
NAME            READY   STATUS    RESTARTS   AGE
pod/busybox-0   2/2     Running   0          2m38s
NAME                                                        CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM                              STORAGECLASS   REASON   AGE
persistentvolume/pvc-3fe7dbe8-96ce-11ea-ae2e-42010a9a012f   1Gi        RWO            Delete           Bound    default/busybox-volume-busybox-0   standard                2m36s
NAME                                             STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
persistentvolumeclaim/busybox-volume-busybox-0   Bound    pvc-3fe7dbe8-96ce-11ea-ae2e-42010a9a012f   1Gi        RWO            standard       2m39s
</code></pre>

<p><strong>Test:</strong></p>

<pre><code>$ kubectl exec -ti busybox-0 -c busybox -- /bin/sh
/ # ls
bin   dev   etc   home  proc  root  sys   test  tmp   usr   var
/ # cd test
/test # ls
lost+found
/test # echo "This is test message, container buxybox" &gt;&gt; msg.txt
/test # cat msg.txt
This is test message, container buxybox
/test # exit
$ kubectl exec -ti busybox-0 -c busybox-two -- /bin/sh
/ # ls
bin   dev   etc   home  proc  root  sys   test  tmp   usr   var
/ # cd test/
/test # ls
lost+found  msg.txt
/test # cat msg.txt
This is test message, container buxybox
/test # echo "This is message from container busybox-two" &gt;&gt; msg.txt
/test # exit
$ kubectl exec -ti busybox-0 -c busybox -- /bin/sh
/ # cat /test/msg.txt
This is test message, container buxybox
This is message from container busybox-two
</code></pre>

<p>This example was tested on <code>GKE</code> so you didn't need to create PV and PVC as Cloud Provider did it.
Hope this answerd your question.</p>
