Last active
March 5, 2020 12:09
-
-
Save welshstew/4f9532fd8737de1a43277c9154caa95e to your computer and use it in GitHub Desktop.
Use oc run and mount volumes using overrides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apiVersion: v1 | |
kind: PersistentVolumeClaim | |
metadata: | |
name: bash-claim | |
spec: | |
accessModes: | |
- ReadWriteOnce | |
resources: | |
requests: | |
storage: 512Mi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
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
I just tried it and it still works..!
$ oc run some-pod --overrides='
with a later version of oc though...
$ oc version
Client Version: 4.3.2
Server Version: 4.3.3
Kubernetes Version: v1.16.2
Seems odd "--image" should really be ignored because the overrides would override it..!