<p>I am trying to make an nginx deployment and during the container creation, I want to create multiply symbolic links. But for some reason, it doesn't work and the container crashes.</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: tcc
    component: nginx
  name: tcc-nginx-deployment
  namespace: dev2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tcc
      component: nginx
  template:
    metadata:
      labels:
        app: tcc
        component: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        command:
              - /bin/sh
              - -c
              - |
                ln -s /shared/apps/ /var/www
                rm -r /etc/nginx/conf.d
                ln -s /shared/nginx-config/ /etc/nginx/conf.d

        ports:
        - containerPort: 80
          protocol: TCP
        volumeMounts:
        - mountPath: /shared
          name: efs-pvc
      volumes:
      - name: efs-pvc
        persistentVolumeClaim:
          claimName: tcc-efs-storage-claim
</code></pre>

<p>The container is not running, because after the <code>command</code> block is executed, container is exiting, which is expected behaviour.</p>
<p>Instead of playing with symbolic links in <code>command</code> in yaml template (which is not the best practice solution), why just don't use solution builtin Kubernetes and do not use <code>command</code> block at all?</p>
<p>You should use <a href="https://kubernetes.io/docs/concepts/storage/volumes/#using-subpath" rel="nofollow noreferrer"><code>subPath</code> which is designed to share directories from one volume for multiple, different directories on the single pod</a>:</p>
<blockquote>
<p>Sometimes, it is useful to share one volume for multiple uses in a single pod. The <code>volumeMounts.subPath</code> property specifies a sub-path inside the referenced volume instead of its root.</p>
</blockquote>
<p>In your case, the deployment yaml should look like this:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: tcc
    component: nginx
  name: tcc-nginx-deployment
  namespace: dev2
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tcc
      component: nginx
  template:
    metadata:
      labels:
        app: tcc
        component: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        ports:
        - containerPort: 80
          protocol: TCP
        volumeMounts:
        - mountPath: /shared
          name: efs-pvc
        - mountPath: /etc/nginx/conf.d
          name: efs-pvc
          subPath: nginx-config
        - mountPath: /var/www
          name: efs-pvc
          subPath: apps
      volumes:
      - name: efs-pvc
        persistentVolumeClaim:
          claimName: tcc-efs-storage-claim
</code></pre>
<p>Also if you want to mount only config files for NGINX, you may use ConfigMap instead of volume - check <a href="https://stackoverflow.com/a/42078899/16391991">this answer</a> for more information.</p>
