How to use image stream in deployment configuration for OpenShift

I want my deployment setup to use an image that was the result of an assembly configuration.

I am currently using something like this:

- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
    creationTimestamp: null
    labels:
      app: myapp
    name: myapp
  spec:
    replicas: 1
    selector:
      app: myapp
      deploymentconfig: myapp
    strategy:
      resources: {}
    template:
      metadata:
        annotations:
          openshift.io/container.myapp.image.entrypoint: '["python3"]'
          openshift.io/generated-by: OpenShiftNewApp
        creationTimestamp: null
        labels:
          app: myapp
          deploymentconfig: myapp
      spec:
        containers:
        - name: myapp
          image: 123.123.123.123/myproject/myapp-staging:latest
          resources: {}
          command:
            - scripts/start_server.sh
          ports:
            - containerPort: 8000
    test: false
    triggers: []
  status: {}

I had to hardcode the integrated docker registry IP address; otherwise Kubernetes / OpenShift will not be able to find the snapshot. I would not like to hardcode the integrated IP address of the docker registry, but instead use something like this:

- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
    creationTimestamp: null
    labels:
      app: myapp
    name: myapp
  spec:
    replicas: 1
    selector:
      app: myapp
      deploymentconfig: myapp
    strategy:
      resources: {}
    template:
      metadata:
        annotations:
          openshift.io/container.myapp.image.entrypoint: '["python3"]'
          openshift.io/generated-by: OpenShiftNewApp
        creationTimestamp: null
        labels:
          app: myapp
          deploymentconfig: myapp
      spec:
        containers:
        - name: myapp
          from:
            kind: "ImageStreamTag"
            name: "myapp-staging:latest"
          resources: {}
          command:
            - scripts/start_server.sh
          ports:
            - containerPort: 8000
    test: false
    triggers: []
  status: {}

But this makes Kubernetes / OpenShift complain about:

The DeploymentConfig "myapp" is invalid.
spec.template.spec.containers[0].image: required value

How can I specify assembly configuration output as an image for use in deployment configuration?

Thank you for your time!

, , , Kubernetes/OpenShift , :

- apiVersion: v1
  kind: DeploymentConfig
  metadata:
    annotations:
      openshift.io/generated-by: OpenShiftNewApp
    creationTimestamp: null
    labels:
      app: myapp-staging
    name: myapp-staging
  spec:
    replicas: 1
    selector:
      app: myapp-staging
      deploymentconfig: myapp-staging
    strategy:
      resources: {}
    template:
      metadata:
        annotations:
          openshift.io/container.myapp.image.entrypoint: '["python3"]'
          openshift.io/generated-by: OpenShiftNewApp
        creationTimestamp: null
        labels:
          app: myapp-staging
          deploymentconfig: myapp-staging
      spec:
        containers:
        - name: myapp-staging
          image: myapp-staging:latest
          resources: {}
          command:
            - scripts/start_server.sh
          ports:
            - containerPort: 8000
    test: false
    triggers:
    - type: "ImageChange"
      imageChangeParams:
        automatic: true
        containerNames:
        - myapp-staging
        from:
          kind: ImageStreamTag
          name: myapp-staging:latest
  status: {}

...

1 (11/21/2016): , (, ), :

$ oc describe pod myapp-1-oodr5
Name:                   myapp-1-oodr5
Namespace:              myproject
Security Policy:        restricted
Node:                   node.url/123.123.123.123
Start Time:             Mon, 21 Nov 2016 09:20:26 -1000
Labels:                 app=myapp
                        deployment=myapp-1
                        deploymentconfig=myapp
Status:                 Pending
IP:                     123.123.123.123
Controllers:            ReplicationController/myapp-1
Containers:
  myapp:
    Container ID:
    Image:              myapp-staging:latest
    Image ID:
    Port:               8000/TCP
    Command:
      scripts/start_server.sh
    State:              Waiting
      Reason:           ImagePullBackOff
    Ready:              False
    Restart Count:      0
    Volume Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-goe98 (ro)
    Environment Variables:
      ALLOWED_HOSTS:    myapp-myproject.url
Conditions:
  Type          Status
  Ready         False 
Volumes:
  default-token-goe98:
    Type:       Secret (a volume populated by a Secret)
    SecretName: default-token-goe98
QoS Tier:       BestEffort
Events:
  FirstSeen     LastSeen        Count   From                                    SubobjectPath                           Type            Reason          Message
  ---------     --------        -----   ----                                    -------------                           --------        ------          -------
  42s           42s             1       {scheduler }                                                                                    Scheduled       Successfully assigned myapp-1-oodr5 to node.url
  40s           40s             1       {kubelet node.url}  implicitly required container POD                       Pulled          Container image "openshift3/ose-pod:v3.1.1.7" already present on machine
  40s           40s             1       {kubelet node.url}  implicitly required container POD                       Created         Created with docker id d3318e880e4a
  40s           40s             1       {kubelet node.url}  implicitly required container POD                       Started         Started with docker id d3318e880e4a
  40s           24s             2       {kubelet node.url}  spec.containers{myapp}                            Pulling         pulling image "myapp-staging:latest"
  38s           23s             2       {kubelet node.url}  spec.containers{myapp}                            Failed          Failed to pull image "myapp-staging:latest": Error: image library/myapp-staging:latest not found
  35s           15s             2       {kubelet node.url}  spec.containers{myapp}                            Back-off        Back-off pulling image "myapp-staging:latest"

2 (08/23/2017): , , .

triggers:    
- type: "ImageChange"
  imageChangeParams:
    automatic: true # this is required to link the build and deployment
    containerNames:
    - myapp-staging
    from:
      kind: ImageStreamTag
      name: myapp-staging:latest

automatic true, .

, , , . :

, automatic false. :

  • automatic true
  • automatic false
  • , ( , , )

- - . , . , -. .

, !

+4
1

?

oc new-build, oc new-app, - . , oc new-app.

, , :

oc new-app --name myapp <repository-url>

:

oc new-build --name myapp <repository-url>
oc new-app myapp

- , , --dry-run -o yaml, , , . , , . , , .

BTW. , , python3. . , , , - , OpenShift. OpenShift , docker run. , , .

+2

Source: https://habr.com/ru/post/1660725/


All Articles