Red Hat OpenShift: Complete Enterprise Kubernetes Platform Guide
Red Hat OpenShift Container Platform is an enterprise Kubernetes distribution that provides a complete application platform for developing and deploying containerized applications. This comprehensive guide covers OpenShift architecture, installation, and production deployment patterns.
What is OpenShift?
OpenShift is Red Hat’s enterprise Kubernetes platform that adds:
Key Features
- Integrated Developer Experience: Built-in CI/CD, source-to-image (S2I)
- Enterprise Security: SELinux, role-based access control, secrets management
- Operator Framework: Automated application lifecycle management
- Multi-Tenancy: Project isolation and quotas
- Integrated Registry: Built-in container registry
- Service Mesh: Istio-based service mesh
- Monitoring: Prometheus and Grafana out-of-the-box
- Logging: EFK stack integration
- Storage: Dynamic provisioning with CSI
- Virtualization: Run VMs alongside containers
OpenShift vs. Kubernetes
| Feature | OpenShift | Vanilla Kubernetes |
|---|---|---|
| Distribution | Enterprise, supported | Community |
| Installation | Automated installer | Manual/various tools |
| Registry | Built-in | External |
| CI/CD | OpenShift Pipelines | External tools |
| Security | SELinux, SCCs | Pod Security Standards |
| Routing | OpenShift Router | Ingress controllers |
| Web Console | Comprehensive | Dashboard (basic) |
| Updates | Automated | Manual |
| Support | Red Hat support | Community |
| Cost | Commercial license | Free |
Architecture
┌─────────────────────────────────────────────────────────────┐│ OpenShift Control Plane ││ ││ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ││ │ API │ │ etcd │ │ Scheduler │ ││ │ Server │ │ │ │ │ ││ └──────────────┘ └──────────────┘ └──────────────┘ ││ ││ ┌──────────────────────────────────────────────────────┐ ││ │ OpenShift-Specific Components │ ││ │ │ ││ │ • OAuth Server │ ││ │ • Image Registry │ ││ │ • Router (HAProxy) │ ││ │ • Web Console │ ││ │ • Monitoring (Prometheus) │ ││ └──────────────────────────────────────────────────────┘ │└─────────────────────────────────────────────────────────────┘ │ ┌──────────────┴──────────────┐ ▼ ▼┌──────────────────────────┐ ┌──────────────────────────┐│ Worker Nodes │ │ Infrastructure Nodes ││ │ │ ││ • Container Runtime │ │ • Registry ││ • kubelet │ │ • Router ││ • Application Pods │ │ • Monitoring │└──────────────────────────┘ └──────────────────────────┘Installation Methods
OpenShift Container Platform (OCP)
Prerequisites
- RHEL CoreOS (RHCOS) nodes
- DNS records configured
- Load balancer for API and apps
- Persistent storage
- Red Hat account for pull secret
Installer-Provisioned Infrastructure (IPI)
# Download OpenShift installerwget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-install-linux.tar.gztar xvf openshift-install-linux.tar.gzsudo mv openshift-install /usr/local/bin/
# Create install-config.yamlmkdir ~/openshift-installcd ~/openshift-install
cat > install-config.yaml << 'EOF'apiVersion: v1baseDomain: example.commetadata: name: production
compute:- name: worker replicas: 3 platform: aws: type: m5.xlarge zones: - us-east-1a - us-east-1b - us-east-1c
controlPlane: name: master replicas: 3 platform: aws: type: m5.xlarge zones: - us-east-1a - us-east-1b - us-east-1c
platform: aws: region: us-east-1
pullSecret: '{"auths":{"cloud.openshift.com": {...}}}'sshKey: 'ssh-rsa AAAA...'
networking: networkType: OVNKubernetes clusterNetwork: - cidr: 10.128.0.0/14 hostPrefix: 23 serviceNetwork: - 172.30.0.0/16 machineNetwork: - cidr: 10.0.0.0/16
fips: false
publish: ExternalEOF
# Backup config (installer consumes it)cp install-config.yaml install-config.yaml.backup
# Create clusteropenshift-install create cluster --dir ~/openshift-install --log-level=info
# Wait for installation (30-45 minutes)# Installer will output kubeconfig and login detailsUser-Provisioned Infrastructure (UPI)
# Generate manifestsopenshift-install create manifests --dir ~/openshift-install
# Customize manifests if needed# Remove master machinesrm -f ~/openshift-install/openshift/99_openshift-cluster-api_master-machines-*.yaml
# Remove worker MachineSetrm -f ~/openshift-install/openshift/99_openshift-cluster-api_worker-machineset-*.yaml
# Generate ignition configsopenshift-install create ignition-configs --dir ~/openshift-install
# Copy ignition files to web serversudo cp ~/openshift-install/*.ign /var/www/html/sudo chmod 644 /var/www/html/*.ign
# Boot nodes with ignition configs# Bootstrap: bootstrap.ign# Masters: master.ign# Workers: worker.ignOpenShift Local (formerly CodeReady Containers)
# Download CRCwget https://developers.redhat.com/content-gateway/file/pub/openshift-v4/clients/crc/latest/crc-linux-amd64.tar.xztar xvf crc-linux-amd64.tar.xzsudo mv crc-linux-*/crc /usr/local/bin/
# Setupcrc setup
# Start cluster (requires 9 GB RAM, 4 CPUs)crc start
# Get credentialscrc console --credentials
# Access consolecrc consoleOKD (Community Distribution)
# Download OKD installerwget https://github.com/okd-project/okd/releases/download/4.14.0-0.okd-2024-01-27-070424/openshift-install-linux-4.14.0-0.okd-2024-01-27-070424.tar.gz
# Follow same IPI/UPI process as OCP# Uses Fedora CoreOS instead of RHCOSCLI Tools
oc CLI
# Download ocwget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/latest/openshift-client-linux.tar.gztar xvf openshift-client-linux.tar.gzsudo mv oc kubectl /usr/local/bin/
# Loginoc login https://api.cluster.example.com:6443 \ --username=admin \ --password=password
# Or with tokenoc login --token=sha256~xxxxx --server=https://api.cluster.example.com:6443
# Basic commandsoc get nodesoc get pods -Aoc projectsoc project myprojectoc vs kubectl
# oc includes kubectl functionality plus:
# Projects (namespaces with additional features)oc new-project myappoc project myapp
# New application from sourceoc new-app https://github.com/openshift/ruby-hello-world
# Buildsoc start-build myappoc logs -f bc/myapp
# Deployments (DeploymentConfig)oc rollout latest dc/myappoc rollout status dc/myappoc rollout undo dc/myapp
# Routes (Ingress alternative)oc expose svc/myappoc get routes
# Login and usersoc loginoc whoamioc get users
# All standard kubectl commands workoc get podsoc describe pod mypodoc logs mypodoc exec -it mypod -- /bin/bashProjects and Multi-Tenancy
Create Project
# Create projectoc new-project production \ --display-name="Production Applications" \ --description="Production environment"
# Set resource quotascat <<EOF | oc apply -f -apiVersion: v1kind: ResourceQuotametadata: name: production-quota namespace: productionspec: hard: requests.cpu: "10" requests.memory: 20Gi limits.cpu: "20" limits.memory: 40Gi persistentvolumeclaims: "10" services: "10" services.loadbalancers: "2"EOF
# Set limit rangescat <<EOF | oc apply -f -apiVersion: v1kind: LimitRangemetadata: name: production-limits namespace: productionspec: limits: - max: cpu: "2" memory: 4Gi min: cpu: 100m memory: 128Mi default: cpu: 500m memory: 512Mi defaultRequest: cpu: 250m memory: 256Mi type: ContainerEOFProject Templates
# Custom project templateapiVersion: template.openshift.io/v1kind: Templatemetadata: name: project-request namespace: openshift-configobjects:- apiVersion: project.openshift.io/v1 kind: Project metadata: name: ${PROJECT_NAME} annotations: openshift.io/description: ${PROJECT_DESCRIPTION} openshift.io/display-name: ${PROJECT_DISPLAYNAME} openshift.io/requester: ${PROJECT_REQUESTING_USER}
- apiVersion: v1 kind: ResourceQuota metadata: name: default-quota namespace: ${PROJECT_NAME} spec: hard: requests.cpu: "4" requests.memory: 8Gi persistentvolumeclaims: "5"
- apiVersion: v1 kind: LimitRange metadata: name: default-limits namespace: ${PROJECT_NAME} spec: limits: - type: Container default: cpu: 500m memory: 512Mi defaultRequest: cpu: 100m memory: 128Mi
- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: admin namespace: ${PROJECT_NAME} roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: admin subjects: - kind: User name: ${PROJECT_ADMIN_USER}
parameters:- name: PROJECT_NAME- name: PROJECT_DISPLAYNAME- name: PROJECT_DESCRIPTION- name: PROJECT_ADMIN_USER- name: PROJECT_REQUESTING_USERBuilding Applications
Source-to-Image (S2I)
# Create app from Git repositoryoc new-app https://github.com/sclorg/nodejs-ex \ --name=nodejs-app
# From specific branch/tagoc new-app https://github.com/example/app#v1.0 \ --name=myapp
# Specify builder imageoc new-app nodejs:16-ubi8~https://github.com/example/nodejs-app
# From local directoryoc new-app . --name=myapp
# With environment variablesoc new-app https://github.com/example/app \ --env=NODE_ENV=production \ --env=API_KEY=secret
# Monitor buildoc logs -f bc/nodejs-appoc get buildsoc describe build nodejs-app-1BuildConfig
apiVersion: build.openshift.io/v1kind: BuildConfigmetadata: name: myapp namespace: productionspec: source: type: Git git: uri: https://github.com/example/myapp ref: main contextDir: /app
strategy: type: Source sourceStrategy: from: kind: ImageStreamTag name: nodejs:16-ubi8 namespace: openshift env: - name: NPM_MIRROR value: https://registry.npmjs.org
output: to: kind: ImageStreamTag name: myapp:latest
triggers: - type: GitHub github: secret: ${WEBHOOK_SECRET} - type: Generic generic: secret: ${WEBHOOK_SECRET} - type: ConfigChange - type: ImageChange imageChange: {}
runPolicy: Serial
resources: limits: cpu: "1" memory: 2Gi requests: cpu: 500m memory: 1GiDocker Build
apiVersion: build.openshift.io/v1kind: BuildConfigmetadata: name: docker-buildspec: source: type: Git git: uri: https://github.com/example/app contextDir: /
strategy: type: Docker dockerStrategy: dockerfilePath: Dockerfile env: - name: BUILD_ENV value: production
output: to: kind: ImageStreamTag name: myapp:latestDeployment Strategies
DeploymentConfig
apiVersion: apps.openshift.io/v1kind: DeploymentConfigmetadata: name: myapp namespace: productionspec: replicas: 3 selector: app: myapp deploymentconfig: myapp
strategy: type: Rolling rollingParams: updatePeriodSeconds: 1 intervalSeconds: 1 timeoutSeconds: 600 maxUnavailable: 25% maxSurge: 25%
template: metadata: labels: app: myapp deploymentconfig: myapp spec: containers: - name: myapp image: image-registry.openshift-image-registry.svc:5000/production/myapp:latest ports: - containerPort: 8080 protocol: TCP env: - name: DATABASE_URL valueFrom: secretKeyRef: name: database-credentials key: url resources: limits: cpu: 500m memory: 512Mi requests: cpu: 250m memory: 256Mi livenessProbe: httpGet: path: /health port: 8080 initialDelaySeconds: 30 periodSeconds: 10 readinessProbe: httpGet: path: /ready port: 8080 initialDelaySeconds: 5 periodSeconds: 5
triggers: - type: ConfigChange - type: ImageChange imageChangeParams: automatic: true containerNames: - myapp from: kind: ImageStreamTag name: myapp:latest namespace: productionBlue-Green Deployment
# Deploy blue versionoc new-app --name=blue --docker-image=myapp:blue
# Deploy green versionoc new-app --name=green --docker-image=myapp:green
# Create route pointing to blueoc expose svc/blue --name=myapp
# Switch to greenoc patch route/myapp -p '{"spec":{"to":{"name":"green"}}}'
# Rollback to blue if neededoc patch route/myapp -p '{"spec":{"to":{"name":"blue"}}}'Canary Deployment
# Route with traffic splitapiVersion: route.openshift.io/v1kind: Routemetadata: name: myapp-canaryspec: host: myapp.apps.cluster.example.com to: kind: Service name: myapp-stable weight: 90 alternateBackends: - kind: Service name: myapp-canary weight: 10 port: targetPort: 8080 tls: termination: edgeNetworking
Routes
# Expose serviceoc expose svc/myapp
# Custom hostnameoc expose svc/myapp --hostname=myapp.example.com
# With TLSoc create route edge myapp \ --service=myapp \ --hostname=myapp.example.com \ --cert=tls.crt \ --key=tls.key
# Passthrough TLSoc create route passthrough myapp \ --service=myapp \ --hostname=myapp.example.com# Route with all optionsapiVersion: route.openshift.io/v1kind: Routemetadata: name: myapp namespace: productionspec: host: myapp.apps.cluster.example.com to: kind: Service name: myapp weight: 100 port: targetPort: 8080 tls: termination: edge certificate: | -----BEGIN CERTIFICATE----- ... -----END CERTIFICATE----- key: | -----BEGIN PRIVATE KEY----- ... -----END PRIVATE KEY----- insecureEdgeTerminationPolicy: Redirect wildcardPolicy: NoneNetwork Policies
apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: allow-same-namespace namespace: productionspec: podSelector: {} policyTypes: - Ingress ingress: - from: - podSelector: {}---apiVersion: networking.k8s.io/v1kind: NetworkPolicymetadata: name: allow-from-router namespace: productionspec: podSelector: matchLabels: app: myapp policyTypes: - Ingress ingress: - from: - namespaceSelector: matchLabels: network.openshift.io/policy-group: ingress ports: - protocol: TCP port: 8080Security
Security Context Constraints (SCCs)
# Custom SCCapiVersion: security.openshift.io/v1kind: SecurityContextConstraintsmetadata: name: custom-sccallowHostDirVolumePlugin: falseallowHostIPC: falseallowHostNetwork: falseallowHostPID: falseallowHostPorts: falseallowPrivilegeEscalation: falseallowPrivilegedContainer: falseallowedCapabilities: []defaultAddCapabilities: []fsGroup: type: MustRunAs ranges: - min: 1000 max: 65535readOnlyRootFilesystem: falserequiredDropCapabilities:- ALLrunAsUser: type: MustRunAsRange uidRangeMin: 1000 uidRangeMax: 65535seLinuxContext: type: MustRunAssupplementalGroups: type: RunAsAnyvolumes:- configMap- downwardAPI- emptyDir- persistentVolumeClaim- projected- secretusers:- system:serviceaccount:production:myappService Account
# Create service accountoc create sa myapp -n production
# Grant SCCoc adm policy add-scc-to-user custom-scc \ system:serviceaccount:production:myapp
# Use in deploymentoc set serviceaccount deployment/myapp myappStorage
PersistentVolumeClaim
apiVersion: v1kind: PersistentVolumeClaimmetadata: name: database-storage namespace: productionspec: accessModes: - ReadWriteOnce resources: requests: storage: 100Gi storageClassName: gp3-csiDynamic Provisioning
# StorageClassapiVersion: storage.k8s.io/v1kind: StorageClassmetadata: name: fast-ssdprovisioner: ebs.csi.aws.comparameters: type: gp3 iops: "3000" throughput: "125" encrypted: "true"volumeBindingMode: WaitForFirstConsumerallowVolumeExpansion: trueOperators
Install Operator
# Operator SubscriptionapiVersion: operators.coreos.com/v1alpha1kind: Subscriptionmetadata: name: mongodb-enterprise namespace: openshift-operatorsspec: channel: stable name: mongodb-enterprise source: certified-operators sourceNamespace: openshift-marketplace installPlanApproval: AutomaticUse Operator
# MongoDB instanceapiVersion: mongodb.com/v1kind: MongoDBmetadata: name: production-db namespace: productionspec: members: 3 type: ReplicaSet version: "6.0.5"
persistent: true storage: storageClass: gp3-csi size: 100Gi
credentials: mongodb-credentials
resources: limits: cpu: "2" memory: 4Gi requests: cpu: "1" memory: 2GiMonitoring
Prometheus Queries
# Access Prometheusoc get routes -n openshift-monitoring
# Custom ServiceMonitorcat <<EOF | oc apply -f -apiVersion: monitoring.coreos.com/v1kind: ServiceMonitormetadata: name: myapp-metrics namespace: productionspec: selector: matchLabels: app: myapp endpoints: - port: metrics interval: 30s path: /metricsEOFCustom Alerts
apiVersion: monitoring.coreos.com/v1kind: PrometheusRulemetadata: name: myapp-alerts namespace: productionspec: groups: - name: myapp rules: - alert: HighErrorRate expr: | rate(http_requests_total{status=~"5.."}[5m]) > 0.05 for: 5m labels: severity: critical annotations: summary: "High error rate on {{ $labels.pod }}"Best Practices
Resource Management
- Set resource requests and limits
- Use HorizontalPodAutoscaler
- Implement PodDisruptionBudgets
- Configure appropriate health checks
Security
- Use dedicated service accounts
- Apply principle of least privilege
- Enable pod security policies (SCCs)
- Rotate secrets regularly
- Use network policies
High Availability
- Run 3+ control plane nodes
- Spread worker nodes across zones
- Use ReadWriteMany for shared storage
- Configure pod anti-affinity
- Implement proper backup strategy
Conclusion
Red Hat OpenShift provides a comprehensive, enterprise-ready Kubernetes platform with enhanced security, integrated development tools, and automated operations. Its opinionated approach and extensive feature set make it ideal for organizations requiring enterprise support and a complete application platform.
Master OpenShift with our comprehensive training programs. Contact us for customized enterprise training.