How can I avoid hardcoding the image url in a cronjob?

8/5/2017

I'm attempting to start a cronjob with an image Openshift has built from my build config.

The following yaml works, but it is not portable. I don't want to have to specify the entire url.

# crontest.yaml
apiVersion: batch/v2alpha1
kind: CronJob
metadata:
    name: test-job
spec:
    schedule: "* * * * *"
    jobTemplate:
        spec:
            template:
                metadata:
                    labels:
                        parent: "cronjobtest"
                spec:
                    containers:
                     - name: myimage
                       image: 172.30.1.1:5000/test/myimage # This is not portable
                    restartPolicy: Never

I want to access my image in a way similar to how I'm able to specify dockerhub images. E.g.

# Example from https://docs.openshift.com/container-platform/3.5/dev_guide/cron_jobs.html
spec:
  containers:
  - name: pi
    image: perl

I expected to be able to do this by changing the spec.containers.image value but have not yet been able to find an effective way. It appears this only works with Dockerhub images from the examples I've found so far.

I tried test/myimage but that is causing the deployment to fail with the following:

Failed to pull image "myimage": Error response from daemon: {"message":"repository myimage not found: does not exist or no pull access"}
Error syncing pod, skipping: failed to "StartContainer" for "myimage" with ErrImagePull: "Error response from daemon: {\"message\":\"repository myimage not found: does not exist or no pull access\"}"

Is there a way of referencing my image that I'm missing?

-- James
kubernetes
openshift
openshift-origin

1 Answer

8/7/2017

Would using a domain name work for you? Then you wouldn't need to hardcode the address.

-- Javier Salmeron
Source: StackOverflow