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.
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
2
Answers
That’s because you are asking container just to create symbolic links. So once those
symbolic links are created container is getting exited.
To avoid that add
"nginx" "-g" "daemon off;"
as following:The container is not running, because after the
command
block is executed, container is exiting, which is expected behaviour.Instead of playing with symbolic links in
command
in yaml template (which is not the best practice solution), why just don’t use solution builtin Kubernetes and do not usecommand
block at all?You should use
subPath
which is designed to share directories from one volume for multiple, different directories on the single pod:In your case, the deployment yaml should look like this:
Also if you want to mount only config files for NGINX, you may use ConfigMap instead of volume – check this answer for more information.