<p>I wanted to run an application called rstudio package manager. It has some terminal commands to be run after the deployment. Is there any way to add those commands within the deployment file? I tried this way and I am getting crashloopback error. I am entirely new to writing the deployment file. Am I doing anything wrong or messing up with syntax?</p>
<pre><code>apiVersion: apps/v1 
kind: Deployment
metadata:
  name: rspm-deployment
spec:
  selector:
    matchLabels:
      app: rspm
  replicas: 1 
  template:
    metadata:
      labels:
        app: rspm
    spec:
      nodeSelector:
        kubernetes.io/hostname: nckaoepekin.local
      containers:
      - env:
        - name: RSPM_LICENSE
          value: my_license_key
        image: rstudio/rstudio-package-manager:latest
        name: rstudio-package-manager
        command: [&quot;/bin/sh&quot;]
        args: [&quot;-c&quot;, &quot;alias rspm='/opt/rstudio-pm/bin/rspm'; rspm create repo --name=prod-cran --description='Access CRAN packages'; rspm subscribe --repo=prod-cran --source=cran; rspm sync&quot;]
        ports:
        - containerPort: 4242
        resources: {}
        securityContext:
          privileged: true
      restartPolicy: Always
status: {}

---
kind: Service
apiVersion: v1
metadata:
  name: rstudio-pm
spec:
  selector:
    app: rspm
  ports:
  - protocol: TCP
    port: 4242
    targetPort: 4242
    nodePort: 31010
  type: NodePort
</code></pre>
<p>I want to add these terminal commands (Specified above also)</p>
<pre><code>alias rspm='/opt/rstudio-pm/bin/rspm'
rspm create repo --name=prod-cran --description='Access CRAN packages'
rspm subscribe --repo=prod-cran --source=cran
rspm sync
</code></pre>
<p>When I remove command and args specified, the deployment file is working. But when I add the command and args, I am getting crashloopback error. Any leads would be appreciated. Thanks</p>

Siddharth
<p>You can use poststart hook <a href="https://kubernetes.io/docs/tasks/configure-pod-container/attach-handler-lifecycle-event/" rel="nofollow noreferrer">here</a></p>
<pre><code>lifecycle:
  postStart:
    exec:
      command:
        - &quot;sh&quot;
        - &quot;-c&quot;
        - |
          alias rspm='/opt/rstudio-pm/bin/rspm' &amp;&amp;
          rspm create repo --name=prod-cran --description='Access CRAN packages'&amp;&amp;
          rspm subscribe --repo=prod-cran --source=cran &amp;&amp;
          rspm sync
</code></pre>
