当前位置:网站首页>Openshift build image
Openshift build image
2022-07-02 08:36:00 【freesharer】
OpenShift Build a mirror image
Use image and warehouse as source and output
1、 Prepare one git Warehouse , Contains a Dockerfile, The following only contains one line for the simplest demonstration .
FROM docker.io/bitnami/nginx:1.21.6
With gitlab Warehouse, for example , You can use github Other warehouses
2、 establish BuildConfig file
Click on the building , Select build configuration , Create build configuration .
The construction configuration is as follows , Be careful source by git Warehouse address .
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: mywebsite
labels:
app: mywebsite
spec:
source:
type: Git
git:
ref: main
uri: http://192.168.72.20:8929/root/nginx-demo
contextDir: ./
strategy:
type: Docker
dockerStrategy:
dockerfilePath: Dockerfile
output:
to:
kind: DockerImage
name: registry.example.com:8443/library/nginx-helloworld:v1.0
among output Specify to push the image to the local after it is built harbor Mirror warehouse , Push image needs to be openshift Configure permissions and ca certificate :
Reference resources :https://docs.openshift.com/container-platform/4.10/cicd/builds/setting-up-trusted-ca.html
oc create configmap registry-cas -n openshift-config \
--from-file=registry.example.com..8443=/etc/docker/certs.d/registry.example.com:8443/ca.crt
oc patch image.config.openshift.io/cluster --patch '{"spec":{"additionalTrustedCA":{"name":"registry-cas"}}}' --type=merge
Click to start building , Automatically generate a new build task
Click on the building , View the build log , Successfully complete the build and push the image to harbor Warehouse :
Use mirror stream as source and output
If you want to output to the image stream after the construction , You need to enable openshift built-in registry Warehouse ,openshif Default not enabled registry, Do the following to enable , A quick solution using temporary storage ( There is no storage class for persistence ):
Reference resources :https://docs.openshift.com/container-platform/4.10/registry/configuring-registry-operator.html
1、 Switch to openshift-image-registry project
oc project openshift-image-registry
2、 edit configs.imageregistry.operator.openshift.io
oc edit configs.imageregistry.operator.openshift.io
Modify the following
...
managementState: Managed
...
...
replica: 1
...
...
storage:
emptyDir: {
}
Confirm the new deployment image-registry pod
[email protected]:~# oc -n openshift-image-registry get pods
NAME READY STATUS RESTARTS AGE
cluster-image-registry-operator-ddd96d697-p4fdx 1/1 Running 0 2d2h
image-pruner-27486720-ddzxx 0/1 Completed 0 31h
image-pruner-27488160-vxmmb 0/1 Completed 0 7h6m
image-registry-746b8888d4-6pdbb 1/1 Running 0 61s
node-ca-7zt48 1/1 Running 0 2d2h
node-ca-8fb9j 1/1 Running 0 2d2h
node-ca-dtsrl 1/1 Running 0 2d2h
node-ca-kn4pl 1/1 Running 0 2d2h
node-ca-vt6fm 1/1 Running 0 2d2h
Then publish the registry access address outside the cluster :
oc patch configs.imageregistry.operator.openshift.io/cluster --patch '{"spec":{"defaultRoute":true}}' --type=merge
Check access address
[email protected]:~# oc get routes
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
default-route default-route-openshift-image-registry.apps.okd4.example.com image-registry <all> reencrypt None
Local pull image
Reference resources :https://access.redhat.com/solutions/4308191
mkdir -p /etc/docker/certs.d/default-route-openshift-image-registry.apps.okd4.example.com/
oc extract secret/router-ca --keys=tls.crt -n openshift-ingress-operator
cp tls.crt /etc/docker/certs.d/default-route-openshift-image-registry.apps.okd4.example.com/
# token It can be downloaded from console User management interface access
export USERNAME=admin
export TOKEN=sha256~uC0tBK7zzeOM9dsoQ0kWIZO5W_ILPzhLvqc5qnTpZG0
docker login -u $USERNAME -p $TOKEN default-route-openshift-image-registry.apps.okd4.example.com
docker pull default-route-openshift-image-registry.apps.okd4.example.com/demo/local-image
Deploy applications using an internal warehouse
oc create configmap registry-local -n openshift-config \
--from-file=registry.example.com..8443=/etc/docker/certs.d/registry.example.com:8443/ca.crt \
--from-file=default-route-openshift-image-registry.apps.okd4.example.com=/etc/docker/certs.d/default-route-openshift-image-registry.apps.okd4.example.com/tls.crt
oc patch image.config.openshift.io/cluster --patch '{"spec":{"additionalTrustedCA":{"name":"registry-local"}}}' --type=merge
2、 Use imagestreamTag
establish imagestream
oc import-image bitnami-nginx:1.20.2 --from="docker.io/bitnami/nginx:1.20.2" --confirm
oc import-image mywebsite2:latest --from="docker.io/bitnami/nginx:1.20.2" --confirm
establish BuildConfig,source and output Configure to ImageStreamTag
apiVersion: build.openshift.io/v1
kind: BuildConfig
metadata:
name: mywebsite2
labels:
app: mywebsite2
spec:
source:
type: Git
git:
ref: master
uri: http://192.168.72.20:8929/root/nginx-demo
contextDir: ./
strategy:
type: Docker
dockerStrategy:
dockerfilePath: Dockerfile
from:
kind: ImageStreamTag
namespace: demo
name: bitnami-nginx:1.20.2
output:
to:
kind: ImageStreamTag
name: mywebsite2:latest
triggers:
- type: ImageChange
Now? , When the build runs ,OpenShift Will Dockerfile Medium FROM Replace the row with the image from the image stream .
In the log , You can see OpenShift To replace the FROM Instructions :
Cloning "http://192.168.72.20:10880/gogs/nginx-demo.git" ...
Commit: 031ff4e5124c8cb057c0576bed21fce88dc60e52 ( to update 'Dockerfile')
Author: gogs <[email protected]>
Date: Thu Apr 7 02:27:13 2022 +0000
Replaced Dockerfile FROM image docker.io/bitnami/nginx:1.21.6
边栏推荐
- Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
- CarSim learning experience - rough translation 1
- Deep understanding of JVM
- What are the platforms for selling green label domain names? What is the green label domain name like?
- Animation synchronization of CarSim real-time simulation
- Carsim problem failed to start Solver: Path Id Obj (X) was set to y; Aucune valeur de correction de xxxxx?
- OpenShift 部署应用
- Use of opencv3 6.2 low pass filter
- OpenFeign 简单使用
- Simple implementation scheme of transcoding and streaming (I)
猜你喜欢
Simple implementation scheme of transcoding and streaming (I)
Sentinel 简单使用
k8s入门:Helm 构建 MySQL
IP协议与IP地址
Application of kotlin - higher order function
c语言将字符串中的空格替换成%20
What is SQL injection
Animation synchronization of CarSim real-time simulation
Carsim-問題Failed to start Solver: PATH_ID_OBJ(X) was set to Y; no corresponding value of XXXXX?
Matlab mathematical modeling tool
随机推荐
Learning C
Web安全--核心防御机制
HCIA - data link layer
Honeypot attack and defense drill landing application scheme
Deep understanding of JVM
Call Stack
Zipkin is easy to use
How to apply for a secondary domain name?
【无标题】
CarSim learning experience - rough translation 1
Chinese garbled code under vscade
Solid principle: explanation and examples
Jz-061-serialized binary tree
sqli-labs第12关
Summary of one question per day: String article (continuously updated)
Use the numbers 5, 5, 5, 1 to perform four operations. Each number should be used only once, and the operation result value is required to be 24
Smart agriculture solutions smart agriculture system development
方法递归(斐波那契数列,青蛙跳台阶,汉诺塔问题)
The best blog to explain the basics of compilation (share)
Carla-ue4editor import Roadrunner map file (nanny level tutorial)