<p>I am trying to create a StatefulSet. I want to create a file on the attached volume so i am using this command <strong>touch /data/test.txt</strong> but it seems like the container crashes because of that. Why would it do that? If i don't use the command everything works fine. What are the properties of the /data directory mounted to volume? Like read/write permissions.</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  ports:
  - port: 80
    name: web
  clusterIP: None
  selector:
    app: nginx
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: web
spec:
  selector:
    matchLabels:
      app: nginx # has to match .spec.template.metadata.labels
  serviceName: "nginx"
  replicas: 3 # by default is 1
  template:
    metadata:
      labels:
        app: nginx # has to match .spec.selector.matchLabels
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: nginx
        image: k8s.gcr.io/nginx-slim:0.8
        ports:
        - containerPort: 80
          name: web
        volumeMounts:
        - name: www
          mountPath: /data
        args:
          - /bin/sh
          - -c
          - touch /data/test.txt
  volumeClaimTemplates:
  - metadata:
      name: www
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 1Gi
</code></pre>

Arpan Solanki
<p>Because the default <a href="https://docs.docker.com/engine/reference/builder/#entrypoint" rel="nofollow noreferrer">ENTRYPOINT</a> of <strong>k8s.gcr.io/nginx-slim:0.8</strong> would be <code>nginx start</code> or something likely.</p>

<p>So, if you want to inject the image, you need to set <strong>command</strong></p>

<pre><code>        command: ["/bin/sh","-c"]
        args:
          - |
            touch /data/test.txt
</code></pre>

<p>And you can <code>kubectl describe</code> or <code>kubectl logs</code> to see what's wrong with your pod/deployment.</p>
