-
-
Save welshstew/4f9532fd8737de1a43277c9154caa95e to your computer and use it in GitHub Desktop.
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 |
I just tried it and it still works..!
$ 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
pod/some-pod created
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..!
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
Hello - I found your post and I'm trying it with OpenShift 3.11.146, oc v3.11.59. The result I get is image pull error: docker.io/dummy not found. Realize your post is a couple years old - do you use this technique presently?