Kahibaro
Discord Login Register

Container-based deployments

Key Concepts of Container-Based Deployments in OpenShift

Container-based deployments in OpenShift are centered around running your own pre-built container images (from Dockerfile or other image build systems), rather than relying on Source-to-Image (S2I). In practice this means:

This chapter focuses on how to work with existing container images in OpenShift, not on how to build them or on the general application deployment concepts already covered elsewhere.

Image Sources and Registries

In a container-based deployment you typically pull images from:

Typical reference forms:

For private registries, you usually need:

This enables OpenShift to authenticate when pulling images for your pods.

Pods from Container Images

The most basic container-based deployment in OpenShift is a pod that directly references an image.

Example minimal pod spec:

apiVersion: v1
kind: Pod
metadata:
  name: my-nginx
spec:
  containers:
  - name: nginx
    image: quay.io/example/my-nginx:1.0
    ports:
    - containerPort: 80

In practice you rarely deploy “bare” Pods for real applications. Instead, you typically use higher-level controllers (Deployments or DeploymentConfigs) that manage pod lifecycles and scaling. However, understanding that these controllers ultimately run pods from container images is crucial.

Creating Container-Based Apps via `oc` and Web Console

OpenShift offers streamlined flows to deploy a container from an image without manually writing YAML.

Using `oc new-app` with an Image

oc new-app can create the full set of resources (Deployment/DeploymentConfig, Service, optionally Route) based on a container image:

bash
  oc new-app quay.io/example/myapi:1.0 --name=myapi
bash
  oc new-app image-registry.openshift-image-registry.svc:5000/myproj/myimage:latest \
    --name=myapp

Useful flags:

oc new-app infers:

Using the Web Console

The web console provides workflows such as:

This is a convenient way for beginners to deploy a container-based app without writing YAML or using the CLI.

Image Configuration vs OpenShift Configuration

Container images encode some defaults:

OpenShift configuration can override or extend these defaults at deployment time.

Key distinctions:

This separation allows one image to be reused in multiple deployments with different runtime configurations (e.g. staging vs production).

Core Pod Settings for Container-Based Deployments

When deploying a container image in OpenShift, you typically configure several pod-level properties. These are configured in the pod template of your Deployment/DeploymentConfig and are specific to container-based deployments.

Container Ports and Services

Define which ports your container listens on so that Services and Routes can be created correctly:

spec:
  containers:
  - name: myapp
    image: quay.io/example/myapp:1.0
    ports:
    - name: http
      containerPort: 8080

Environment Variables

Environment variables configure the container at runtime:

env:
- name: APP_ENV
  value: "production"
- name: DB_HOST
  valueFrom:
    configMapKeyRef:
      name: db-config
      key: host

For container-based deployments, it is common to parameterize the image using environment variables rather than rebuilding the image for each environment.

Resource Requests and Limits

Resource settings control scheduling and help prevent resource contention:

resources:
  requests:
    cpu: "100m"
    memory: "256Mi"
  limits:
    cpu: "500m"
    memory: "512Mi"

With pre-built images, you often do not control how resource-efficient the code is; appropriate requests and limits are important to ensure stability.

Command and Arguments Overrides

If the image’s default command is not suitable, you can override it:

command: ["python", "app.py"]
args: ["--log-level=info"]

Typical use cases:

Probes (Liveness/Readiness/Startup)

For container-based deployments, probes are critical to integrate the generic container with the OpenShift platform’s health model.

Example readiness and liveness probes:

livenessProbe:
  httpGet:
    path: /healthz
    port: http
  initialDelaySeconds: 20
  periodSeconds: 10
readinessProbe:
  httpGet:
    path: /ready
    port: http
  initialDelaySeconds: 10
  periodSeconds: 5

When you bring your own image, you must ensure the application exposes suitable endpoints or behaviors for these probes to work (HTTP endpoints, TCP ports, or command-based checks).

Image Pull Policy and Tag Strategy

How and when OpenShift pulls images affects rollout behavior and reproducibility.

Image Pull Policy

Common pull policies:

Example:

imagePullPolicy: IfNotPresent

Best practice for container-based deployments:

Image Tags vs Digests

In OpenShift deployments:

Image Pull Secrets and Private Registries

For private registries, you need credentials to allow the cluster to pull your images.

Typical workflow:

  1. Create a pull secret:
bash
   oc create secret docker-registry my-regcred \
     --docker-server=registry.example.com \
     --docker-username=myuser \
     --docker-password=mypassword \
     --docker-email=me@example.com
  1. Attach the secret to a service account:
bash
   oc secrets link default my-regcred --for=pull
  1. Ensure your deployment uses that service account (or default):
   spec:
     serviceAccountName: default

The pods using that service account will be able to pull from the configured registry during deployment.

Sidecar and Multi-Container Pods

Container-based deployments often use multiple containers in a single pod to extend or adapt a base image without rebuilding it.

Common patterns:

Example with a sidecar container:

spec:
  containers:
  - name: app
    image: quay.io/example/webapp:2.3
    ports:
    - containerPort: 8080
  - name: log-forwarder
    image: quay.io/example/log-sender:1.0
    args: ["--source=/var/log/app.log"]
    volumeMounts:
    - name: applogs
      mountPath: /var/log
  volumes:
  - name: applogs
    emptyDir: {}

This allows you to keep a standard “vanilla” app image but enrich its behavior within OpenShift by adding containers around it.

Integrating with OpenShift Services, Routes, and Storage

Container-based deployments in OpenShift are typically part of a larger platform configuration:

From the perspective of a container-based deployment:

Best Practices for Container-Based Deployments in OpenShift

Specific to using “bring-your-own-image” style deployments:

These practices ensure that your container-based deployments behave predictably in OpenShift and integrate smoothly with the platform’s orchestration, security, and observability features.

Views: 21

Comments

Please login to add a comment.

Don't have an account? Register now!