3
  1. I created a build config from the git repo (Docker based app).

    oc new-build <git-url> --name=myApp

  2. Created a deployment config using:

    oc create dc myApp --image=<image-stream-repo>

I am adding labels to this deployment config from the UI.

  1. Now when I deploy the application (from the UI) or use oc rollout, the POD is created and the application is running in the POD.

But the label (name: myApp) is not being applied to the POD. As a result the selector in the service is failing to identify the POD. The service is configured with label name: myApp as POD selector.

If I go to the created POD and edit yaml and add name: myApp in the labels section, only then the POD is being identified by the service.

In case if any one has faced similar issue, please provide your inputs in overcoming this problem.

snmaddula
  • 1,111
  • 1
  • 7
  • 21
  • Instead of ``oc create dc``, use ``oc new-app myApp``, or being more explicit, ``oc new-app --image-stream myApp``. Note that the name has to be all lower case. – Graham Dumpleton Nov 27 '18 at 21:56
  • 1
    There is rarely a need to create a ``dc`` explicitly using ``oc create`` like you are. If you use ``oc new-app`` to deploy the image, it will create the service with appropriate labels for you. – Graham Dumpleton Nov 27 '18 at 21:57
  • If you haven't already, suggest you read the free eBook at https://www.openshift.com/deploying-to-openshift/ – Graham Dumpleton Nov 27 '18 at 21:58

1 Answers1

1

To set a label on a Pod using a DeploymentConfig, the label must be placed in a much more deeply nested key, as shown below, or else it will be set on the DeploymentConfig itself, not the Pod:

objects:
  - kind: DeploymentConfig
    apiVersion: v1
    metadata:
      name: my-name
      # labels: NOT HERE (FOR DC ONLY)!
    spec:
        replicas: 1
        selector:
          app: my-name
        strategy:
          type: Rolling
        template:
          metadata:
            labels:
              app: my-name
              myAppsGroup: myApp

You can verify the correctness of pod labeling using oc describe pod my-name

mirekphd
  • 4,799
  • 3
  • 38
  • 59