la3mmchen
la3mmchen

Reputation: 133

Openshift: Unresolved Image

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.

Upvotes: 9

Views: 19383

Answers (4)

Abdennour TOUMI
Abdennour TOUMI

Reputation: 93163

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 ????!!!

Upvotes: 0

theNoble247
theNoble247

Reputation: 516

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

Upvotes: 0

Diego Garber
Diego Garber

Reputation: 71

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.

Upvotes: 7

Graham Dumpleton
Graham Dumpleton

Reputation: 58523

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
                }
            }
        }
    ]
}

Upvotes: 3

Related Questions