Openshift:未解析的图像

la3*_*hen 7 openshift openshift-origin

我被 Openshift (Origin) 困住了,需要一些帮助。

假设我想通过 CLI 将 grafana 部署添加到新启动的集群。

我所做的:

  1. 将模板上传到我的 openshift 集群(oc create -f openshift-grafana.yml)

  2. 从 docker hub 拉取必要的镜像 (oc import-image --confirm grafana/grafana)

  3. 基于我的模板构建一个新应用程序 (oc new-app grafana)

这些步骤创建部署配置和路由。但是后来我无法通过 CLI 开始部署。

# oc deploy grafana                                                                                                                                            
grafana deployment #1 waiting on image or update
# oc rollout latest grafana                                                                                                                                    
Error from server (BadRequest): cannot trigger a deployment for "grafana" because it contains unresolved imagesenter code here
Run Code Online (Sandbox Code Playgroud)

在 openshift Web 控制台中,它看起来像这样:

图像在那里,甚至链接也有效。在 Web 控制台中,我可以单击“部署”并且它正在工作。但尽管如此,我还是无法通过命令行推出新版本。

它工作的唯一方法是编辑部署 yml,以便 openshift 识别更改并根据“配置更改”开始部署(提示:我没有更改图像或图像名称)

我的模板没有什么特别之处,它只是通过 oc export 从工作配置导出。

任何提示将不胜感激,我几乎卡住了。谢谢。

Die*_*ber 6

我有同样的问题,我通过添加解决了它:

        lastTriggeredImage: >-
          mydockerrepo.com/repo/myimage@sha256:xxxxxxxxxxxxxxxx
Run Code Online (Sandbox Code Playgroud)

在:

  triggers:
    - type: ImageChange
      imageChangeParams:
Run Code Online (Sandbox Code Playgroud)

deploymentconfig yaml 的。看起来如果它不知道最后触发的图像是什么,它将无法解决它。

  • 我只是想提供帮助,而不是试图获得帮助,这对我有用(而上述解决方案没有),我想分享它。如果我违反了一些规则,我很抱歉这是我的第一个答案。 (2认同)

Gra*_*ton 3

下面包含您可以用作入门的模板。请注意,grafana 映像似乎要求它以 root 身份运行,否则它将无法启动。这意味着您必须覆盖 OpenShift 的默认安全模型,并启用允许在项目中以 root 身份运行映像。不建议这样做。grafana 镜像应该被修复,这样就不需要它们以 root 身份运行。

要启用以 root 身份运行,您需要以集群管理员身份运行:

oc adm policy add-scc-to-user anyuid -z default -n myproject
Run Code Online (Sandbox Code Playgroud)

其中myproject是您正在使用的项目的名称。

我将其应用到默认服务帐户,但最好创建一个单独的服务帐户,将其应用到该帐户,然后更改模板,以便只有 grafana 作为该服务帐户运行。

其目的可能是您通过grafana.ini文件覆盖默认设置,以便它使用您安装的emptyDir目录,这样就不是问题了。我没有尝试提供任何覆盖配置。

grafana 的模板如下所示。注意我使用了 JSON,因为我发现使用 JSON 更容易,而且还可以避免缩进被搞砸,导致 YAML 无法使用。

在使用此模板之前,您显然应该创建相应的配置映射,其中 name 的形式为${APPLICATION_NAME}-configwhere ${APPLICATION_NAME}grafana除非您在使用模板时覆盖它。配置映射中的键应该是grafana.ini配置文件内容的值。

{
    "apiVersion": "v1",
    "kind": "Template",
    "metadata": {
        "name": "grafana"
    },
    "parameters": [
        {
            "name": "APPLICATION_NAME",
            "value": "grafana",
            "from": "[a-zA-Z0-9]",
            "required": true
        }
    ],
    "objects": [
        {
            "apiVersion": "v1",
            "kind": "ImageStream",
            "metadata": {
                "name": "${APPLICATION_NAME}-img",
                "labels": {
                    "app": "${APPLICATION_NAME}"
                }
            },
            "spec": {
                "tags": [
                    {
                        "name": "latest",
                        "from": {
                            "kind": "DockerImage",
                            "name": "grafana/grafana"
                        }
                    }
                ]
            }
        },
        {
            "apiVersion": "v1",
            "kind": "DeploymentConfig",
            "metadata": {
                "name": "${APPLICATION_NAME}",
                "labels": {
                    "app": "${APPLICATION_NAME}",
                    "type": "monitoring"
                }
            },
            "spec": {
                "replicas": 1,
                "selector": {
                    "app": "${APPLICATION_NAME}",
                    "deploymentconfig": "${APPLICATION_NAME}"
                },
                "template": {
                    "metadata": {
                        "labels": {
                            "app": "${APPLICATION_NAME}",
                            "deploymentconfig": "${APPLICATION_NAME}",
                            "type": "monitoring"
                        }
                    },
                    "spec": {
                        "containers": [
                            {
                                "name": "grafana",
                                "image": "${APPLICATION_NAME}-img:latest",
                                "imagePullPolicy": "Always",
                                "livenessProbe": {
                                    "failureThreshold": 3,
                                    "httpGet": {
                                        "path": "/",
                                        "port": 3000,
                                        "scheme": "HTTP"
                                    },
                                    "periodSeconds": 10,
                                    "successThreshold": 1,
                                    "timeoutSeconds": 1
                                },
                                "ports": [
                                    {
                                        "containerPort": 3000,
                                        "protocol": "TCP"
                                    }
                                ],
                                "volumeMounts": [
                                    {
                                        "mountPath": "/etc/grafana",
                                        "name": "grafana-1"
                                    },
                                    {
                                        "mountPath": "/var/lib/grafana",
                                        "name": "grafana-2"
                                    },
                                    {
                                        "mountPath": "/var/log/grafana",
                                        "name": "grafana-3"
                                    }
                                ]
                            }
                        ],
                        "volumes": [
                            {
                                "configMap": {
                                    "defaultMode": 420,
                                    "name": "${APPLICATION_NAME}-config"
                                },
                                "name": "grafana-1"
                            },
                            {
                                "emptyDir": {},
                                "name": "grafana-2"
                            },
                            {
                                "emptyDir": {},
                                "name": "grafana-3"
                            }
                        ]
                    }
                },
                "test": false,
                "triggers": [
                    {
                        "type": "ConfigChange"
                    },
                    {
                        "imageChangeParams": {
                            "automatic": true,
                            "containerNames": [
                                "grafana"
                            ],
                            "from": {
                                "kind": "ImageStreamTag",
                                "name": "${APPLICATION_NAME}-img:latest"
                            }
                        },
                        "type": "ImageChange"
                    }
                ]
            }
        },
        {
            "apiVersion": "v1",
            "kind": "Service",
            "metadata": {
                "name": "${APPLICATION_NAME}",
                "labels": {
                    "app": "${APPLICATION_NAME}",
                    "type": "monitoring"
                }
            },
            "spec": {
                "ports": [
                    {
                        "name": "3000-tcp",
                        "port": 3000,
                        "protocol": "TCP",
                        "targetPort": 3000
                    }
                ],
                "selector": {
                    "deploymentconfig": "${APPLICATION_NAME}"
                },
                "type": "ClusterIP"
            }
        },
        {
            "apiVersion": "v1",
            "kind": "Route",
            "metadata": {
                "name": "${APPLICATION_NAME}",
                "labels": {
                    "app": "${APPLICATION_NAME}",
                    "type": "monitoring"
                }
            },
            "spec": {
                "host": "",
                "port": {
                    "targetPort": "3000-tcp"
                },
                "to": {
                    "kind": "Service",
                    "name": "${APPLICATION_NAME}",
                    "weight": 100
                }
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)