Copy command crash pod startup on Kubernetes

12/13/2018

I'm new with Kubernetes and I'm trying to understand about the commands. Basically what I'm trying to do is to create a Tomcat deployment, add an nfs and after that I copy the war file to the tomcat webapps.
But its failing

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: webapp11-deployment
spec:
  replicas: 2
  template:
    metadata:
      labels:
        app: webapp11
    spec:
      volumes:
        - name: www-persistent-storage
          persistentVolumeClaim:
            claimName: claim-webapp11
      containers:
      - name: webapp11-pod
        image: tomcat:8.0
        volumeMounts:
          - name: www-persistent-storage
            mountPath: /apps/build
        command: ["sh","-c","cp /apps/build/v1/sample.war /usr/local/tomcat/webapps"]
        ports:
        - containerPort: 8080

As far as I understand when the image when an image has a command, like catalina.sh run on the Tomcat image, it will have a conflict with a command from the kubernetes.
Is that correct?
There is anyway to run a command after the pod starts?

thanks

-- radicaled
command
kubernetes
kubernetes-pod

1 Answer

12/13/2018

No, what you want is probably something like this:

command: ["sh","-c","cp /apps/build/v1/sample.war /usr/local/tomcat/webapps && exec /whatever/catalina.sh"]

Or you could move the cp into an initContainer so you don't have to override the default command for your Tomcat container.

-- coderanger
Source: StackOverflow