OpenShift Downward API Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 55: Line 55:
       containers:
       containers:
       - name: printenv
       - name: printenv
         volumeMounts:
         <font color=teal>'''volumeMounts:'''</font>
           - name: downward-api-volume
           - <font color=teal>'''name: downward-api-volume'''</font>
             mountPath: /downward-info
             <font color=teal>'''mountPath: /downward-info'''</font>
             readOnly: false
             readOnly: false
       ...
       ...
       volumes:
       <font color=teal>'''volumes:'''</font>
         - name: downward-api-volume
         - <font color=teal>'''name: downward-api-volume'''</font>
             metadata:
             <font color=teal>'''metadata:'''</font>
               items:
               <font color=teal>'''items:'''</font>
                 - name: "pod-name"
                 - <font color=teal>'''name: "pod-name"'''</font>
                   fieldRef:
                   <font color=teal>'''fieldRef:'''</font>
                     fieldPath: metadata.name
                     <font color=teal>'''fieldPath: metadata.name'''</font>
 
 
 
 
 
        <font color=teal>'''env''':</font>
 
 





Revision as of 04:36, 23 November 2017

Internal

Overview

Expose OpenShift Information to Pod via Environment Variables

Edit the deployment configuration for the pod we want to expose data to:

oc edit dc/<dc-name>

Add the following environment entires:

...
spec:
  ...
  template:
    ...
    spec:
      containers:
      - name: printenv
        env:
          - name: POD_NAME
            valueFrom:
              fieldRef:
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace

The deployment configuration will produce a pod that contains the following environment properties in its environment:

POD_NAME=something-cm34t
POD_NAMESPACE=lab4

This can be verifying by oc rsh into the pod and executing "printenv".

Expose OpenShift Information to Pod via Volumes

Edit the deployment configuration for the pod we want to expose data to:

oc edit dc/<dc-name>

Add the following environment entires:

...
spec:
  ...
  template:
    ...
    spec:
      containers:
      - name: printenv
        volumeMounts:
          - name: downward-api-volume
            mountPath: /downward-info
            readOnly: false
      ...
      volumes:
        - name: downward-api-volume
           metadata:
             items:
               - name: "pod-name"
                 fieldRef:
                   fieldPath: metadata.name


The deployment configuration will produce a pod that contains the following environment properties in its environment:

POD_NAME=something-cm34t
POD_NAMESPACE=lab4

This can be verifying by oc rsh into the pod and executing "printenv".