Openshift: Unresolved Image
Asked Answered
L

4

9

i'm stuck with Openshift (Origin) and need some help.

Let's say i want to add a grafana deployment via CLI to a new started cluster.

What i do:

  1. Upload a template to my openshift cluster (oc create -f openshift-grafana.yml)

  2. Pull the necessary image from the docker hub (oc import-image --confirm grafana/grafana)

  3. Build a new app based on my template (oc new-app grafana)

These steps creates the deployment config and the routes. But then i'm not able to start a deployment via 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

In the openshift web console it looks like this:

The images is there, even the link is working. In the web console i can click "deploy" and it's working. But nevertheless i'm not able to rollout a new version via command line.

The only way it works is editing the deployment yml so openshift recognizes a change a starts a deployment based on "config change" (hint: i'm was not changing the image or image name)

There is nothing special in my template, it was just an export via oc export from a working config.

Any hint would be appreciated, i'm pretty much stuck. Thanks.

Lisette answered 1/7, 2017 at 11:46 Comment(5)
What is the list of resources which are created? Use oc get all. What events occur? Use oc get events. Where is the original openshift-grafana.yml template you are using found?Blackington
@GrahamDumpleton The openshift-grafana.yml can be found here : link This is my shell outputs: linkLisette
Where did the imagestream's come from? The template doesn't create an imagestream for grafana. If I was constructing a template I would have it create the image stream to trigger an import of the image. Am concerned that since you separately already have an imagestream called grafana that it is causing a conflict in some way with the use of grafana image direct from Docker Hub in the template.Blackington
@GrahamDumpleton Thanks for the hint, but it doesn't work. I've added an imagestream spec to my template. Now the grafana images gets pulled once i do oc new-app but with the same result updated_templateLisette
Be aware that you cannot use oc export --as-template output as is, it will need massaging. One of the things it gets wrong is how it references the internal image registry. Give me a bit of time and I will correct your template.Blackington
B
3

Included below is the template you can use as a starter. Just be aware that the grafana image appears to require it be run as root, else it will not startup. This means you have to override the default security model of OpenShift and enable allowing running of images as root in the project. This is not recommended. The grafana images should be fixed so as not to require they be run as root.

To enable running as root, you would need to run as a cluster admin:

oc adm policy add-scc-to-user anyuid -z default -n myproject

where myproject is the name of the project you are using.

I applied it to the default service account, but better you create a separate service account, apply it to that and then change the template so that only grafana runs as that service account.

It is possible that the intent is that you override the default settings through the grafana.ini file so it uses your mounted emptyDir directories and then it isn't an issue. I didn't attempt to provide any override config.

The template for grafana would then be as follows. Note I have used JSON as I find it easier to work with JSON, but also to avoid indenting being screwed up making the YAML impossible to use.

Before you use this template, you should obviously create the corresponding config map where name is of form ${APPLICATION_NAME}-config where ${APPLICATION_NAME} is grafana unless you override it when using the template. The key in the config map should be grafana.ini and then have as value the config file contents.

{
    "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
                }
            }
        }
    ]
}
Blackington answered 2/7, 2017 at 12:35 Comment(2)
Thanks. Your template works fine. I will use your file as base for futher modification. Thanks a lot, i would never thought that the oc export --as-template is broken. <3Lisette
It is a known issue. It isn't just creation of templates which is problematic, but also exporting everything from a project so that it can be recreated in a different OpenShift project, or even a separate cluster. Work is being done to improve these tools.Blackington
H
7

I had this same issue and I solved it by adding:

        lastTriggeredImage: >-
          mydockerrepo.com/repo/myimage@sha256:xxxxxxxxxxxxxxxx

On:

  triggers:
    - type: ImageChange
      imageChangeParams:

Of the deploymentconfig yaml. Looks like if it doesn't know what the last triggered image is, it wont be able to resolve it.

Heffner answered 16/4, 2018 at 19:19 Comment(3)
You shouldn't be touching that yourself. If you had to fiddle with that, you still have an issue elsewhere in the deployment config you are using. If you have an issue you are better off creating a new question which provides all the details and then someone can give a correct answer to your problem.Blackington
I am just trying to help, not trying to GET help, this is something that worked for me (while the above solutions didn't) and I wanted to share it. I am sorry if I broke some rule this is my first answer.Heffner
This indeed fixes the issue if you miss configured triggers section. And make sure to not add it in any quotes!Humpbacked
B
3

Included below is the template you can use as a starter. Just be aware that the grafana image appears to require it be run as root, else it will not startup. This means you have to override the default security model of OpenShift and enable allowing running of images as root in the project. This is not recommended. The grafana images should be fixed so as not to require they be run as root.

To enable running as root, you would need to run as a cluster admin:

oc adm policy add-scc-to-user anyuid -z default -n myproject

where myproject is the name of the project you are using.

I applied it to the default service account, but better you create a separate service account, apply it to that and then change the template so that only grafana runs as that service account.

It is possible that the intent is that you override the default settings through the grafana.ini file so it uses your mounted emptyDir directories and then it isn't an issue. I didn't attempt to provide any override config.

The template for grafana would then be as follows. Note I have used JSON as I find it easier to work with JSON, but also to avoid indenting being screwed up making the YAML impossible to use.

Before you use this template, you should obviously create the corresponding config map where name is of form ${APPLICATION_NAME}-config where ${APPLICATION_NAME} is grafana unless you override it when using the template. The key in the config map should be grafana.ini and then have as value the config file contents.

{
    "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
                }
            }
        }
    ]
}
Blackington answered 2/7, 2017 at 12:35 Comment(2)
Thanks. Your template works fine. I will use your file as base for futher modification. Thanks a lot, i would never thought that the oc export --as-template is broken. <3Lisette
It is a known issue. It isn't just creation of templates which is problematic, but also exporting everything from a project so that it can be recreated in a different OpenShift project, or even a separate cluster. Work is being done to improve these tools.Blackington
C
0

For me, I had the image name incorrectly under 'from':

triggers:
    - type: ConfigChange
    - imageChangeParams:
        automatic: true
        containerNames:
          - alcatraz-ha
        from:
          kind: ImageStreamTag
          name: 'alcatraz-haproxy:latest'
          namespace: alcatraz-ha-dev
      type: ImageChange

I had name: 'alcatraz-ha:latest' so it could not find the image

Counterchange answered 7/11, 2020 at 16:14 Comment(0)
S
0

Make sure that spec.triggers.imageChangeParams.from.name exists as image stream

triggers:
    - imageChangeParams:
        from:
          kind: ImageStreamTag
          name: 'myapp:latest' # Does "myapp" exist if you run oc get is ????!!!
Stage answered 19/3, 2021 at 3:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.