OpenShift Image Registry
It's one thing building container images and running them locally but the core reason for working with containers is to ship them around. This is done by tagging images and pushing them to image registries. Then other users can pull application container images and run them on other platforms such as OpenShift.
Note
This guide was down using OpenShift Local, see OpenShift Local
OpenShift Registry
As kubeadmin
you can use this command to extract the register route:
Using Podman, log into the image registry using your OpenShift accounts by passing in the token, in this case the user developer
:
podman login -u $(oc whoami) -p $(oc whoami -t) --tls-verify=false default-route-openshift-image-registry.apps-crc.testing
Assuming the following local image:
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/fastapi-serve-static 1.0.0 e3b37b3e5276 13 minutes ago 1.37 GB
This needs to be tagged using the image registry route, project, image name and tag.
Simple Example
Create a new OpenShift project:
Tag a local image:
podman tag localhost/fastapi-serve-static:1.0.0 default-route-openshift-image-registry.apps-crc.testing/example-project/fastapi-serve-static:1.0.0
Push the image to OpenShift image registry:
Tip
Add --tls-verify=false
to work around any certificate issues.
For example:
podman push default-route-openshift-image-registry.apps-crc.testing/example-project/fastapi-serve-static:1.0.0 --tls-verify=false
You can view the image stream of a project with:
NAME IMAGE REPOSITORY TAGS UPDATED
fastapi-serve-static default-route-openshift-image-registry.apps-crc.testing/example-project/fastapi-serve-static 1.0.0 39 seconds ago
Deploy the application:
apiVersion: apps/v1
kind: Deployment
metadata:
name: fastapi-static-deploy
namespace: example-project
spec:
replicas: 1
selector:
matchLabels:
app: fastapi-static-app
template:
metadata:
labels:
app: fastapi-static-app
spec:
containers:
- name: fastapi-serve-static
image: image-registry.openshift-image-registry.svc:5000/example-project/fastapi-serve-static:1.0.0
ports:
- containerPort: 8080
Watch the pod progress with:
Create a service for the deployment:
apiVersion: v1
kind: Service
metadata:
name: fastapi-static-svc
namespace: example-project
labels:
app: fastapi-static-app
spec:
internalTrafficPolicy: Cluster
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
ports:
- name: web
port: 8080
protocol: TCP
targetPort: 8080
selector:
app: fastapi-static-app
sessionAffinity: None
type: ClusterIP
Create a route:
kind: Route
apiVersion: route.openshift.io/v1
metadata:
name: fastapi-static-route
namespace: example-project
spec:
to:
kind: Service
name: fastapi-static-svc
weight: 100
port:
targetPort: 8080
tls:
termination: edge
insecureEdgeTerminationPolicy: Allow
wildcardPolicy: None
You should now have the application deployed and exposed, for example https://fastapi-static-route-example-project.apps-crc.testing/.