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?
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: ["/bin/sh"]
args: ["-c", "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"]
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
I want to add these terminal commands (Specified above also)
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
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
Try using postStart
container lifecycle event as show here
cat > postStart.sh <<
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
EOF
lifecycle:
postStart:
exec:
command:
- /bin/bash
- postStart.sh
You can use poststart hook here
lifecycle:
postStart:
exec:
command:
- "sh"
- "-c"
- |
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
I added sleep after all my bash commands since those files were taking time to execute.
exec:
command:
- "sh"
- "-c"
- |
alias rspm='/opt/rstudio-pm/bin/rspm' &&
sleep 5 &&
rspm create repo --name=prod-cran --description='Access CRAN packages' &&
sleep 5 &&
rspm subscribe --repo=prod-cran --source=cran &&
sleep 5 &&
rspm sync
And it got worked!