Skip to content

πŸ—οΈ 0️⃣ Architecture Overview

Image

Image

Image

Image

Flow:

Developer β†’ Docker Build β†’ DockerHub β†’ OpenShift Deployment β†’ Service β†’ Route β†’ User


🧩 STEP 1 β€” Create Web Application

πŸ“„ main.go

package main

import (
    "fmt"
    "net/http"
    "os"
)

func handler(w http.ResponseWriter, r *http.Request) {
    message := os.Getenv("MESSAGE")
    if message == "" {
        message = "Hello from OpenShift πŸš€"
    }
    fmt.Fprintf(w, message)
}

func main() {
    http.HandleFunc("/", handler)
    http.ListenAndServe(":8080", nil)
}

Important:

  • Uses port 8080 (OpenShift safe)
  • Reads env variable

🐳 STEP 2 β€” Create OpenShift-Compatible Dockerfile

# ---------- Build Stage ----------
FROM golang:1.22-alpine AS builder

WORKDIR /opt/app

COPY main.go .

RUN go mod init demo && \
    go mod tidy && \
    CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o app && \
    chmod 755 app

# ---------- Runtime Stage ----------
FROM alpine:latest

WORKDIR /opt/app
RUN mkdir -p /opt/app && chmod -R 777 /opt/app

COPY --from=builder /opt/app/app .

EXPOSE 8080

CMD ["./app"]

Why this works:

  • No root requirement
  • Arbitrary UID safe
  • Proper permissions
  • Uses 8080

πŸ—οΈ STEP 3 β€” Build Docker Image

docker build -t yuvaraiden001/web-demo:v1 .

πŸ“¦ STEP 4 β€” Push to DockerHub

docker login
docker push yuvaraiden001/web-demo:v1

Now image is available publicly.


πŸ” STEP 5 β€” Login to OpenShift

oc login --token=<token> --server=<server>
oc project romanyuvan-dev

πŸš€ STEP 6 β€” Deploy Using YAML (Production Style)

πŸ“„ deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: web-demo
spec:
  replicas: 2
  selector:
    matchLabels:
      app: web-demo
  template:
    metadata:
      labels:
        app: web-demo
    spec:
      containers:
        - name: web-demo
          image: yuvaraiden001/web-demo:v1
          ports:
            - containerPort: 8080
          env:
            - name: MESSAGE
              value: "Hello Yuva from OpenShift πŸ”₯"

Apply:

oc apply -f deployment.yaml

Check:

oc get pods

Wait until Running.


🌐 STEP 7 β€” Create Service

πŸ“„ service.yaml

apiVersion: v1
kind: Service
metadata:
  name: web-demo-service
spec:
  selector:
    app: web-demo
  ports:
    - port: 8080
      targetPort: 8080
  type: ClusterIP

Apply:

oc apply -f service.yaml

🌍 STEP 8 β€” Create Route (External Access)

πŸ“„ route.yaml

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: web-demo-route
spec:
  to:
    kind: Service
    name: web-demo-service
  port:
    targetPort: 8080
  tls:
    termination: edge

Apply:

oc apply -f route.yaml

Check route:

oc get route

Copy URL β†’ open in browser πŸ”₯


πŸ”„ STEP 9 β€” Scaling

oc scale deployment web-demo --replicas=3

Check:

oc get pods

OpenShift service load balances automatically.


πŸ” STEP 10 β€” Rolling Update

Change message in deployment.yaml.

Build new version:

docker build -t yuvaraiden001/web-demo:v2 .
docker push yuvaraiden001/web-demo:v2

Update deployment:

oc set image deployment/web-demo web-demo=yuvaraiden001/web-demo:v2

Check rollout:

oc rollout status deployment/web-demo

No downtime.


πŸ”Ž STEP 11 β€” Debugging

Logs:

oc logs <pod-name>

Describe:

oc describe pod <pod-name>

Shell access:

oc rsh <pod-name>

🎯 What You Achieved

You now used:

  • Container Runtime (CRI-O)
  • Deployment
  • ReplicaSet
  • Service
  • Route (HAProxy)
  • Scaling
  • Rolling updates
  • Environment variables
  • TLS termination

That’s full OpenShift application lifecycle.


🧠 Interview Summary Answer

β€œOpenShift application deployment flow consists of building a container image, pushing it to a registry, creating a Deployment for pods, exposing it via a Service for internal communication, and creating a Route for external access with TLS termination.”