Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 460
la3mmchen Avatar asked Jul 01 '17 11:07

la3mmchen


People also ask

What is an Imagestream?

Image stream images allow you to retrieve metadata about an image from a particular image stream where it is tagged. Image stream image objects are automatically created in OpenShift Container Platform whenever you import or tag an image into the image stream.

What is DeploymentConfig in OpenShift?

A DeploymentConfig or Deployment object, either of which describes the desired state of a particular component of the application as a pod template. DeploymentConfig objects involve one or more replication controllers, which contain a point-in-time record of the state of a deployment as a pod template.

How do I make a streaming picture?

Create an image stream using the oc import-image command. Give the image stream a name and then the image you want to import. This creates an image stream in your project, called approved-apache. It has one tag, 2.4, which points to the tag 2.4 on the image bitnami/apache.

What can image streams point to?

If the source image changes, the image stream tag will still point to a known-good version of the image, ensuring that your application will not break unexpectedly. You can configure security around who can view and use the images through permissions on the image stream objects.


2 Answers

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.

like image 128
Diego Garber Avatar answered Sep 22 '22 06:09

Diego Garber


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
                }
            }
        }
    ]
}
like image 31
Graham Dumpleton Avatar answered Sep 22 '22 06:09

Graham Dumpleton