Openshift Origin 作业是否需要对图像进行硬编码的内部注册表 URL?

Chr*_*tle 5 openshift openshift-origin

我无法找到一种命名空间可移植的方法来将图像构建到图像流中,然后可以将其用于OpenShift 项目命名空间中的作业,而无需在作业配置中对内部注册表 URL 进行硬编码。

与部署配置不同,作业配置不会自动构建具有内部注册表正确图像 URL 的 pod 配置。由于无法拉取映像,因此生成的作业永远不会运行。

Failed to pull image "is-copy-adaptermappings": Error: image library/is-copy-adaptermappings:latest not found
Run Code Online (Sandbox Code Playgroud)

工作示例生成 deployconfig 生成的 pod

...
 containers:
    - name: i2b2-webclient
      image: >-
        172.30.1.1:5000/c2/is-i2b2-webclient@sha256:51460a7b65ddd8cc32e41e9a3ac069efb587220364edc9285d06438b22e2ea47
      ports:
        - containerPort: 8080
          protocol: TCP
...
Run Code Online (Sandbox Code Playgroud)

失败示例生成的作业 pod 摘录

apiVersion: v1
kind: Pod
...
  containers:
    - name: copy-config-to-pv
      image: is-copy-adaptermappings
      resources: {}
      volumeMounts:
...
Run Code Online (Sandbox Code Playgroud)

作业配置 (json)

{
  "apiVersion": "batch/v1",
  "kind": "Job",
  "metadata": {
    "name": "configpod"
  },
  "spec": {
    "parallelism": 1,
    "completions": 1,
    "template": {
      "metadata": {
        "name": "copy-config-to-pv"
      },
      "spec": {
        "containers": [
          {
            "name": "copy-config-to-pv",
            "image": "is-copy-adaptermappings",
            "imagePullPolicy": "Always",
            "volumeMounts": [
              {
                "mountPath": "/dest",
                "name": "volume-config"
              }
            ]
          }
        ],
        "restartPolicy": "OnFailure",
        "volumes": [
          {
            "name": "volume-config",
            "persistentVolumeClaim": {
              "claimName": "pvc-configs"
            }
          }
        ]
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

是否有一种很好的方法来引用或生成内置本地注册表映像的 URL?

Gra*_*ton 4

据我了解,是这样的,因为你使用的实际上是 Kubernetes Job 对象。每当您在 Kubernetes 级别执行操作时,都必须引用映像注册表中的映像。Kubernetes 中不存在图像流的概念。这就是 OpenShift 对象(例如构建和部署配置)更加智能的地方,因为它们通过图像流对象工作,图像流对象充当索引或间接指针的形式。使用图像流作为中介使使用 OpenShift 时的事情变得更容易。

尽管如此,我还是被告知 OpenShift 3.6 中可能有一些东西可以让这件事变得更容易。但现在,显然还没有记录它是如何工作的。可能会告诉我详细信息的人正在休假直到月底,但我正在看看是否可以找到更多详细信息,并在知道后进行更新。


更新1

假设您使用的是 OpenShift 3.6,并且is-copy-adaptermappings是当前项目中的图像流,请尝试以下操作:

{
  "apiVersion": "batch/v1",
  "kind": "Job",
  "metadata": {
    "name": "configpod"
    "annotations": {
      "alpha.image.policy.openshift.io/resolve-names": "*"
    },
  },
  "spec": {
    "parallelism": 1,
    "completions": 1,
    "template": {
      "metadata": {
        "name": "copy-config-to-pv"
      },
      "spec": {
        "containers": [
          {
            "name": "copy-config-to-pv",
            "image": "is-copy-adaptermappings",
            "imagePullPolicy": "Always",
            "volumeMounts": [
              {
                "mountPath": "/dest",
                "name": "volume-config"
              }
            ]
          }
        ],
        "restartPolicy": "OnFailure",
        "volumes": [
          {
            "name": "volume-config",
            "persistentVolumeClaim": {
              "claimName": "pvc-configs"
            }
          }
        ]
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

alpha.image.policy.openshift.io/resolve-names添加的内容是作业元数据中带有名称的注释。

的值image可以是图像流名称(在这种情况下latest使用标签),也可以是name:tag并引用特定标签。

使用注释的方式具有 alpha 状态,因此注释的名称最终会更改。通常他们会尝试自动迁移包含 alpha/beta 标签的名称,但请注意,如果状态发生变化,它就会停止工作。


更新2

看起来使用现在可能存在的注释的另一种方法是设置is.spec.lookupPolicy并启用local查找。

$ oc explain is.spec.lookupPolicy
RESOURCE: lookupPolicy <Object>

DESCRIPTION:
     lookupPolicy controls how other resources reference images within this
     namespace.

    ImageLookupPolicy describes how an image stream can be used to override the image references used by pods, builds, and other resources in a namespace.

FIELDS:
   local    <boolean> -required-
     local will change the docker short image references (like "mysql" or
     "php:latest") on objects in this namespace to the image ID whenever they
     match this image stream, instead of reaching out to a remote registry. The
     name will be fully qualified to an image ID if found. The tag's
     referencePolicy is taken into account on the replaced value. Only works
     within the current namespace.
Run Code Online (Sandbox Code Playgroud)

也就是说,将其设置在要在图像字段中引用的图像流对象上。