relief.melone
relief.melone

Reputation: 3322

Openshift - Variables in Config for different Environments

I am currently trying to make deployments on two different openshift clusters, but I only want to use one deploymentconfig file. Is there a good way to overcome the current problem

apiVersion: v1
kind: DeploymentConfig
metadata:
  labels:
    app: my-app
    deploymentconfig: my-app
  name: my-app
spec:
  selector:
    app: my-app
    deploymentconfig: my-app
  strategy:
    type: Rolling
    rollingParams:
      intervalSeconds: 1
      maxSurge: 25%
      maxUnavailability: 25%
      timeoutSeconds: 600
      updatePeriodSeconds: 1
  replicas: 1
  template:
    metadata:
      labels:
        app: my-app
        deploymentconfig: my-app
    spec:
      containers:
        - name: my-app-container
          image: 172.0.0.1:5000/int-myproject/my-app:latest
          imagePullPolicy: Always
          ports:
            - containerPort: 8080
              protocol: TCP
          env:
            - name: ROUTE_PATH
              value: /my-app
            - name: HTTP_PORT
              value: "8080"
            - name: HTTPS_PORT
              value: "8081"
    restartPolicy: Always
    dnsPolicy: ClusterFirst

Now if you look at spec.template.spec.containers[0].image there are two problems with this

Nr.1

172.0.0.1:5000/int-myproject/my-app:latest

The IP of the internal registry will differ between the two environments

Nr.2

172.0.0.1:5000/int-myproject/my-app:latest

The namespace will also not be the same. In this scenario I want this to be int-myproject or prod-myproject depending on the environment i want to deploy to. I was thinking maybe there is a way to use parameters in the yaml and pass them to openshift somehow similar to this

oc create -f deploymentconfig.yaml --namespace=int-myproject

and have a parameter like ${namespace} in my yaml file. Is there a good way to achieve this?

Upvotes: 0

Views: 3561

Answers (1)

PhilipGough
PhilipGough

Reputation: 1769

Firstly, to answer your question, yes you can use parameters with OpenShift templates and pass the value and creation time.

To do this, you will add the required template values to your yaml file and instead of using oc create you will use oc new-app -f deploymentconfig.yaml --param=SOME_KEY=someValue. Check out oc new-app --help for more info here.

Some other points to note though: IF you are referencing images from internal registry you might be better off to use imagestreams. These provide an abstraction for images pulled from internal docker registry on OpenShift, as is the case you have outlined.

Finally, the namespace value is available via the downward API in every Pod and you should not need to (typically) inject that manually.

Upvotes: 2

Related Questions