ποΈ 0οΈβ£ Architecture Overview¶




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¶
π¦ STEP 4 β Push to DockerHub¶
Now image is available publicly.
π STEP 5 β Login to OpenShift¶
π 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:
Check:
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:
π 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:
Check route:
Copy URL β open in browser π₯
π STEP 9 β Scaling¶
Check:
OpenShift service load balances automatically.
π STEP 10 β Rolling Update¶
Change message in deployment.yaml.
Build new version:
Update deployment:
Check rollout:
No downtime.
π STEP 11 β Debugging¶
Logs:
Describe:
Shell access:
π― 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.β