9.2.4 Image Deployment

Container Image Deployment.

9.2.4.1 Lab

In this section we cover how to deploy an existing Docker Image from an private image registry. Besides we show how to create a ImageStream to track changes on the deployed image and trigger an update on the deployment.

We first check that the project is ready for the lab.

Ensure that the LAB_USER environment variable is set.

echo $LAB_USER

If the result is empty, set the LAB_USER environment variable.

command hint
export LAB_USER=<username>

Change to your main Project.

command hint
oc project $LAB_USER-build-types

Let’s start with the deployment configuration

apiVersion: apps.openshift.io/v1
kind: DeploymentConfig
metadata:
  labels:
    app: quarkus-techlab-data-producer-private
  name: quarkus-techlab-data-producer-private
spec:
  replicas: 1
  selector:
    app: quarkus-techlab-data-producer-private
    deploymentconfig: quarkus-techlab-data-producer-private
  template:
    metadata:
      labels:
        app: quarkus-techlab-data-producer-private
        deploymentconfig: quarkus-techlab-data-producer-private
    spec:
      containers:
      - image: 'quarkus-techlab-data-producer-private:latest'
        imagePullPolicy: IfNotPresent
        name: quarkus-techlab-data-producer-private
        ports:
        - containerPort: 8080
          protocol: TCP
  triggers:
  - imageChangeParams:
      automatic: true
      containerNames:
      - quarkus-techlab-data-producer-private
      from:
        kind: ImageStreamTag
        name: quarkus-techlab-data-producer-private:latest
    type: ImageChange
  strategy:
    type: Rolling

Source

oc create -f https://raw.githubusercontent.com/puzzle/amm-techlab/main/manifests/additional/image/deploymentConfig.yaml

Next we create the ImageStream definition. The important part is under the tags section. There we define a reference to an external Docker registry and define which image to track. Another important field is the import policy. If you query an image from an external registry, you can set scheduled import to true.

apiVersion: image.openshift.io/v1
kind: ImageStream
metadata:
  labels:
    app: quarkus-techlab-data-producer-private
  name: quarkus-techlab-data-producer-private
spec:
  lookupPolicy:
    local: false
  tags:
  - from:
      kind: DockerImage
      name: registry.puzzle.ch/techlab/quarkus-techlab-data-producer
    name: latest
    importPolicy:
      scheduled: true
    referencePolicy:
      type: Source

Source

oc create -f https://raw.githubusercontent.com/puzzle/amm-techlab/main/manifests/additional/image/imageStream.yaml

Credentials

In this section we create a docker secret to access the private registry and pull the docker image.

oc create secret docker-registry regcred --docker-server=registry.puzzle.ch --docker-username=techlab+amm_techlab --docker-password=<password> --docker-email=$LAB_USER@puzzle.ch

Next we link the secret with our default service account.

oc secrets link default regcred --for=pull