Can an openshift template parameter refer to the project name in which it is getting deployed?

8/25/2017

I am trying to deploy Kong API Gateway via template to my openshift project. The problem is that Kong seems to be doing some DNS stuff that causes sporadic failure of DNS resolution. The workaround is to use the FQDN (<name>.<project_name>.svc.cluster.local). So, in my template i would like to do:

    - env:
      - name: KONG_DATABASE
        value: postgres
      - name: KONG_PG_HOST
        value: "{APP_NAME}.{PROJECT_NAME}.svc.cluster.local"

I am just not sure how to get the current PROJECT_NAME of if perhaps there is a default set of available parameters...

-- Lucas
kubernetes
openshift
openshift-origin

1 Answer

8/25/2017

You can read the namespace(project name) from the Kubernetes downward API into an environment variable and then use that in the value perhaps.

See the OpenShift docs here for example.

Update based on Claytons comment:

Tested and the following snippet from the deployment config works.

- env:
    - name: MY_POD_NAMESPACE
      valueFrom:
        fieldRef:
          apiVersion: v1
          fieldPath: metadata.namespace
    - name: EXAMPLE
      value: example.$(MY_POD_NAMESPACE)

Inside the running container:

sh-4.2$ echo $MY_POD_NAMESPACE                                                                          
testing                                                                                                                            
sh-4.2$ echo $EXAMPLE                                                                                                             
example.testing

In the environment screen of the UI it appears as a string value such as example.$(MY_POD_NAMESPACE)

-- PhilipGough
Source: StackOverflow