OpenShift Downward API Operations: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * OpenShift Operations * Downward API")
 
 
(15 intermediate revisions by the same user not shown)
Line 3: Line 3:
* [[OpenShift_Operations#Subjects|OpenShift Operations]]
* [[OpenShift_Operations#Subjects|OpenShift Operations]]
* [[OpenShift_Concepts#Downward_API|Downward API]]
* [[OpenShift_Concepts#Downward_API|Downward API]]
=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
        <font color=teal>env:</font>
          - <font color=teal>name: POD_NAME</font>
            <font color=teal>valueFrom:</font>
              <font color=teal>fieldRef:</font>
                <font color=teal>fieldPath: metadata.name</font>
          - <font color=teal>name: POD_NAMESPACE</font>
            <font color=teal>valueFrom:</font>
              <font color=teal>fieldRef:</font>
                <font color=teal>fieldPath: metadata.namespace</font>
The deployment configuration will produce a pod that contains the following environment properties in its environment:
POD_NAME=printenv-3-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
        <font color=teal>volumeMounts:</font>
        - <font color=teal>name: downward-api-volume</font>
          <font color=teal>mountPath: /downward-info</font>
          readOnly: false
      ...
      volumes:
      - <font color=teal>name: downward-api-volume</font>
        <font color=teal>metadata:</font>
            <font color=teal>items:</font>
            - <font color=teal>name: "pod-name"</font>
              <font color=teal>fieldRef:</font>
                <font color=teal>fieldPath: metadata.name</font>
            - <font color=teal>name: "pod-namespace"'''</font>
              <font color=teal>fieldRef:</font>
                <font color=teal>fieldPath: metadata.namespace</font>
            - <font color=teal>name: "pod-label"</font>
              <font color=teal>fieldRef:</font>
                <font color=teal>fieldPath: metadata.labels</font>
            - <font color=teal>name: "pod-annotations"</font>
              <font color=teal>fieldRef:</font>
                <font color=teal>fieldPath: metadata.annotations</font>
The deployment configuration will produce a pod will mount a /downward-info volume, which contains four files:
pod-name:
printenv-3-tm5m4
pod-namespace:
lab4
pod-label:
app="printenv"
deployment="printenv-3"
deploymentconfig="printenv"
pod-annotations:
kubernetes.io/config.seen="2017-11-22T20:53:05.131680613-08:00"
kubernetes.io/config.source="api"
kubernetes.io/created-by="{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"lab4\",\"name\":\"printenv-3\",\"uid\":\"2dc22525-d00a-11e7-947c-525400360e56\",\"apiVersion\":\"v1\",\"resourceVersion\":\"517382\"}}\n"
openshift.io/deployment-config.latest-version="3"
openshift.io/deployment-config.name="printenv"
openshift.io/deployment.name="printenv-3"
openshift.io/generated-by="OpenShiftNewApp"
openshift.io/scc="restricted"

Latest revision as of 04:56, 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=printenv-3-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
           - name: "pod-namespace"
             fieldRef:
               fieldPath: metadata.namespace
           - name: "pod-label"
             fieldRef:
               fieldPath: metadata.labels
           - name: "pod-annotations"
             fieldRef:
               fieldPath: metadata.annotations


The deployment configuration will produce a pod will mount a /downward-info volume, which contains four files:

pod-name:

printenv-3-tm5m4

pod-namespace:

lab4

pod-label:

app="printenv"
deployment="printenv-3"
deploymentconfig="printenv"

pod-annotations:

kubernetes.io/config.seen="2017-11-22T20:53:05.131680613-08:00"
kubernetes.io/config.source="api"
kubernetes.io/created-by="{\"kind\":\"SerializedReference\",\"apiVersion\":\"v1\",\"reference\":{\"kind\":\"ReplicationController\",\"namespace\":\"lab4\",\"name\":\"printenv-3\",\"uid\":\"2dc22525-d00a-11e7-947c-525400360e56\",\"apiVersion\":\"v1\",\"resourceVersion\":\"517382\"}}\n"
openshift.io/deployment-config.latest-version="3"
openshift.io/deployment-config.name="printenv"
openshift.io/deployment.name="printenv-3"
openshift.io/generated-by="OpenShiftNewApp"
openshift.io/scc="restricted"