Skip to content

Instantly share code, notes, and snippets.

@welshstew
Last active March 5, 2020 12:09
Show Gist options
  • Save welshstew/4f9532fd8737de1a43277c9154caa95e to your computer and use it in GitHub Desktop.
Save welshstew/4f9532fd8737de1a43277c9154caa95e to your computer and use it in GitHub Desktop.
Use oc run and mount volumes using overrides
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: bash-claim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 512Mi
oc run some-pod --overrides='
{
"spec": {
"containers": [
{
"command": [
"/bin/bash",
"-c",
"for i in {1..5}; do echo hi stuff; sleep 5; done"
],
"image": "registry.access.redhat.com/rhel7/rhel:latest",
"name": "some-pod",
"volumeMounts": [{
"mountPath": "/opt/scripts",
"name": "some-data"
}]
}
],
"volumes": [
{
"name": "some-data",
"persistentVolumeClaim": {
"claimName": "bash-claim"
}
}
]
}
}
' --image=dummy --restart=Never
@aceeric
Copy link

aceeric commented Mar 5, 2020

And working now. I went back through my notes but couldn't find what I had been doing wrong. I extended your example based on info found elsewhere to support using YAML as the override instead of JSON:

JSON=$(python -c 'import json,sys,yaml; y=yaml.safe_load(sys.stdin.read()); print(json.dumps(y))' <<EOF
spec:
  containers:
  - name: testcontainer
    image: ubuntu
  dnsPolicy: ClusterFirst
  volumes:
  - name: test
    persistentVolumeClaim:
      claimName: foo
  ...
EOF
)
oc -n namespace run test-pod --image=dummy --overrides=<<<"$JSON" --restart=Never

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment