<p>I'm creating a pod for Databse server first and then an application server pod in openshift.
And I'm doing it in Jenkinsfile, with openshift deployments handled by Kustomize.</p>
<p>And the database routeurl varibale -DATABASE_DYNAMIC_ROUTEURL is in jenkinsfile.</p>
<p>Below are my manifest files for deployment.</p>
<p><strong>kustomization.yaml</strong></p>
<pre><code>kind: Kustomization
resources:
- deployment.yaml

</code></pre>
<p><strong>deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp
spec:
  progressDeadlineSeconds: 30
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - name: myapp
        image: myregistry.com/myapp:5c3dda6b
        ports:
        - containerPort: 80
        imagePullPolicy: Always
         env:
        - name: DATABASE_DYNAMIC_ROUTEURL
          value:https://xyz-1234-databaseurl.com
        imagePullSecrets:
        - name: myregistry.com-registry-key
        readinessProbe:
          httpGet:
            path: /
            port: 8080

</code></pre>
<p>I tried using kustomize patch to replace the value but it's not understanding the exact position to replace the value.</p>
<pre><code>- patch: 
      - op: replace
        path: /spec/template/spec/containers/0/image/0/value
        value: DATABASE_DYNAMIC_ROUTEURL
</code></pre>
<p>I am new to kustomize, can someone suggest which approach is good to implement the dynamic environment variable in deployment.yaml of application server file.
Thanks in advance</p>

<p>You can try out something like</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: demo
  labels:
    app: demo
spec:
  selector:
    matchLabels:
      app: demo
  template:
    metadata:
      name: demo
      annotations: {} # initially unset. You may provide default values if you wish.
      labels:
        app: demo
    spec:
      containers:
      - name: demo
        image: demoimage
        env:
        - name: DOTNET_ENVIRONMENT
          valueFrom:
            fieldRef:
              fieldPath: metadata.annotations['environment']
</code></pre>
<p><strong>kustomization.yaml</strong> file</p>
<pre><code>- op: replace
  path: /spec/template/metadata/annotations/environment
  value: Production
</code></pre>
<p>You can also use the <strong>config map</strong> to store the environment config and add or inject it further to deployment.</p>
<p>You can checkout this nice article : <a href="https://blog.stack-labs.com/code/kustomize-101/" rel="nofollow noreferrer">https://blog.stack-labs.com/code/kustomize-101/</a></p>
