Image Stream是OpenShift中的一种对象,它并不是用来存储Image的,而是用来记录并管理Image信息的。它就像是所有Image的虚拟视图,可以通过它统一访问存放在不同Image Registry(OpenShift外部独立运行的Registry、或是OpenShift内置的Registry)上的Image。通过这个视图可以简化对那些来自不同Registry的Image的访问。Image Stream会使用访问标签(Image Stream Tag)和指向信息(Image Stream Image)记录这种对应关系,其中指向Image的指针是由Image Stream Name和Image ID构成的。
根据Image Stream所在项目,可将其分为集群级和项目级的Image Stream。无论当前在哪个项目中,任何用户都可访问到集群级的Image Stream;而项目级Image Stream只能该项目用户或被授权用户才可访问。
如果我们跟随《OpenShift 4 Hands-on Lab (1) - 部署应用》成功创建应用后可以通过以下命令发现OpenShift会自动生成ImageStream对象,这就说明在运行应用前,OpenShift要创建ImageStream并建立App Image的指向关系。
oc get is
OpenShift除了可以自动创建ImageStream外,我们还可以从定义ImageStream的YAML文件创建它,但是我们通常用以下两种方法手工从Image生成ImageStream:
$ oc new-project USER-ID-imagestream-lab1
$ oc import-image --from=docker.io/openshift/deployment-example:v1 is-example:v1 --confirm
Name: is-example
Namespace: USER-ID-imagestream-lab1
Created: Less than a second ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2020-02-02T04:27:15Z
Image Repository: image-registry.openshift-image-registry.svc:5000/USER-ID-imagestream-lab1/is-example
Image Lookup: local=false
Unique Images: 1
Tags: 1
v1
tagged from docker.io/openshift/deployment-example:v1
* docker.io/openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
Less than a second ago
Image Name: is-example:v1
Docker Image: docker.io/openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
Name: sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
Created: Less than a second ago
Annotations: image.openshift.io/dockerLayersOrder=ascending
Image Size: 5.77MB in 6 layers
Layers: 0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
5.77MB sha256:50438f3701c47319ff1c8189ff19f5a8c779f2479aa2066979b930c7dbb3bde8
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Image Created: 4 years ago
Author: Clayton Coleman <[email protected]>
Arch: amd64
Entrypoint: /deployment v1
Working Dir: <none>
User: <none>
Exposes Ports: 8080/tcp
Docker Labels: <none>
Environment: COLOR=#006e9c
$ oc tag --source=docker openshift/deployment-example:v2 is-example:v2
Tag is-example:v2 set to openshift/deployment-example:v2.
$ oc get is
NAME IMAGE REPOSITORY TAGS UPDATED
is-example default-route-openshift-image-registry.apps.cluster-beijing-c70a.beijing-c70a.example.opentlc.com/USER-ID-imagestream-lab1/is-example v2,v1 9 minutes ag
$ oc describe is is-example
Name: is-example
Namespace: USER-ID-imagestream-lab1
Created: 12 minutes ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2020-02-02T04:33:29Z
Image Repository: default-route-openshift-image-registry.apps.cluster-beijing-c70a.beijing-c70a.example.opentlc.com/USER-ID-imagestream-lab1/is-example
Image Lookup: local=false
Unique Images: 2
Tags: 2
v1
tagged from docker.io/openshift/deployment-example:v1
*. docker.io/openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
12 minutes ago
v2
tagged from openshift/deployment-example:v2
*. openshift/deployment-example@sha256:1318f08b141aa6a4cdca8c09fe8754b6c9f7802f8fc24e4e39ebf93e9d58472b
12 minutes ago
$ oc get istag
NAME IMAGE REF UPDATED
is-example:v1 docker.io/openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b 10 minutes ago
is-example:v2 openshift/deployment-example@sha256:1318f08b141aa6a4cdca8c09fe8754b6c9f7802f8fc24e4e39ebf93e9d58472b 10 minutes ago
$ oc describe istag is-example:v1
Image Name: sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
Docker Image: docker.io/openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
Name: sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
Created: 2 hours ago
Annotations: image.openshift.io/dockerLayersOrder=ascending
Image Size: 5.77MB in 6 layers
Layers: 0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
5.77MB sha256:50438f3701c47319ff1c8189ff19f5a8c779f2479aa2066979b930c7dbb3bde8
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
0B sha256:a3ed95caeb02ffe68cdd9fd84406680ae93d633cb16422d00e8a7c22955b46d4
Image Created: 4 years ago
Author: Clayton Coleman <[email protected]>
Arch: amd64
Entrypoint: /deployment v1
Working Dir: <none>
User: <none>
Exposes Ports: 8080/tcp
Docker Labels: <none>
Environment: COLOR=#006e9c
$ oc adm top imagestreams -n USER-ID-imagestream-lab1
NAME STORAGE IMAGES LAYERS
USER-ID-imagestream-lab1/is-example 5.503MiB 2 12
$ oc tag --source=docker openshift/deployment-example:v2 is-example:v1
$ oc describe is is-example
Name: is-example
Namespace: USER-ID-imagestream-lab1
Created: 4 minutes ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2020-02-02T14:07:48Z
Image Repository: default-route-openshift-image-registry.apps.cluster-beijing-c70a.beijing-c70a.example.opentlc.com/USER-ID-imagestream-lab1/is-example
Image Lookup: local=false
Unique Images: 2
Tags: 2
v1
tagged from openshift/deployment-example:v2
* openshift/deployment-example@sha256:1318f08b141aa6a4cdca8c09fe8754b6c9f7802f8fc24e4e39ebf93e9d58472b
About a minute ago
docker.io/openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
4 minutes ago
v2
tagged from openshift/deployment-example:v2
* openshift/deployment-example@sha256:1318f08b141aa6a4cdca8c09fe8754b6c9f7802f8fc24e4e39ebf93e9d58472b
3 minutes ago
$ oc delete istag/is-example:v2
在使用“oc tag”和“oc import-image”命令生成ImageStream的时候,可以使用参数“–reference-policy=local”让OpenShift只在本地(其内部的Image Registry)找镜像;另外还可以用“–reference”参数让OpenShift只创建一个非导入的ImageStreamTag,即不导入目标Image的元数据。下面我们看看这两个选项对ImageStream有什么影响?
$ oc new-project USER-ID-imagestream-lab2
$ oc tag --source=docker openshift/deployment-example:v1 is-example:v1
$ oc tag --source=docker openshift/deployment-example:v1 is-example:v2 --reference-policy=local
$ oc tag --source=docker openshift/deployment-example:v1 is-example:v3 --reference=true
$ oc describe is is-example
Name: is-example
Namespace: imagestream-lab2
Created: 2 minutes ago
Labels: <none>
Annotations: openshift.io/image.dockerRepositoryCheck=2020-02-02T11:14:02Z
Image Repository: default-route-openshift-image-registry.apps.cluster-beijing-c70a.beijing-c70a.example.opentlc.com/USER-ID-imagestream-lab2/is-example
Image Lookup: local=false
Unique Images: 2
Tags: 3
v1
tagged from openshift/deployment-example:v1
* openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
2 minutes ago
v2
tagged from openshift/deployment-example:v1
prefer registry pullthrough when referencing this tag
* openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b
2 minutes ago
v3
reference to registry openshift/deployment-example:v1
* openshift/deployment-example:v1
2 minutes ago
$ oc get istag
NAME IMAGE REF UPDATED
is-example:v1 openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b 2 minutes ago
is-example:v2 image-registry.openshift-image-registry.svc:5000/USER-ID-imagestream-lab2/is-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b 2 minutes ago
oc tag --source=istag is-example:v1 is-example:v4 --reference=true
$ oc get istag
NAME IMAGE REF UPDATED
is-example:v1 openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b 22 minutes ago
is-example:v2 image-registry.openshift-image-registry.svc:5000/USER-ID-imagestream-lab2/is-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b 22 minutes ago
is-example:v4 openshift/deployment-example@sha256:c505b916f7e5143a356ff961f2c21aee40fbd2cd906c1e3feeb8d5e978da284b About a minute ago