πŸš€ DevOps & SRE Certification Program πŸ“… Starting: 1st of Every Month 🀝 +91 8409492687 πŸ” Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

OpenShift Tutorial – Basic Learning Workflow

How to login?


oc login https://api.XXXXXXXXXXXXXX.centralindia.aroapp.io:6443 --username=kubeadmin --password=EgzIY-DJPw2-3NXke-HNYmJ

oc login --token=sha256~LLnTlPcjcNjWsQRqnSyTn99LSvxwQdm47gaiEdZJa20 --server=https://api.XXXXXXXXXXXXXX.centralindia.aroapp.io:6443

curl -H "Authorization: Bearer sha256~LLnTlPcjcNjWsQRqnSyTn99LSvxwQdm47gaiEdZJa20" "https://api.XXXXXXXXXXXXXX.centralindia.aroapp.io:6443/apis/user.openshift.io/v1/users/~

Login to the Web Console and CLI on CRC

crc console --credentials
eval $(crc oc-env)
oc login -u kubeadmin -p <password> --insecure-skip-tls-verify

Copy the admin URL and kubeadmin credentials β†’ open in browser.


βœ… Step 2: Understand Projects (Namespaces)

πŸ”Ή List All Projects:

oc get projects

πŸ”Ή Create Your Own:

oc new-project demo-app

βœ… Step 3: Deploy Your First Application

oc get images
oc new-app --name=my-java-app registry.access.redhat.com/ubi8/openjdk-8-runtime@sha256:00cf28cf9a6c427962f922855a6cc32692c760764ce2ce7411cf605dd510367f
oc expose svc/my-java-app


oc get imagestreams -n openshift
oc new-app --name=my-httpd --image-stream=openshift/httpd
oc expose svc/my-httpd
oc get route my-httpd

Test in browser using the exposed route.


βœ… Step 4: Work with the Developer Console

  1. Go to the Web Console β†’ Developer View
  2. Switch to demo-app project
  3. Click +Add β†’ Use β€œContainer Image”
  4. Search for image like node:latest, php:8.2-apache, or quay.io/...

This gives visual understanding of how apps, builds, and deployments connect.


βœ… Step 5: Build from Source (Git to Deployment)

πŸ”Ή Deploy from Git (Node.js example):

oc new-app https://github.com/sclorg/nodejs-ex.git

πŸ”Ή Monitor:

oc get builds
oc logs -f bc/nodejs-ex

πŸ”Ή Access:

oc expose svc/nodejs-ex
oc get route

βœ… Step 6: Scale Applications

πŸ”Ή Increase Pods:

oc scale --replicas=3 deployment/nginx

πŸ”Ή Check Pods:

oc get pods -o wide

βœ… Step 7: Access Pod Shell & Logs

oc rsh <pod-name>
oc logs <pod-name>

Use this for debugging and viewing container state.


βœ… Step 8: Set Resource Limits

oc set resources deployment nginx \
  --limits=cpu=500m,memory=256Mi \
  --requests=cpu=200m,memory=128Mi

βœ… Step 9: Understand and Apply YAML

  1. Export a deployment: oc get deployment nginx -o yaml > nginx.yaml
  2. Edit and apply: oc apply -f nginx.yaml

βœ… Step 10: Use Secrets and ConfigMaps

πŸ”Ή Create ConfigMap:

oc create configmap app-config --from-literal=ENV=prod

πŸ”Ή Create Secret:

oc create secret generic app-secret --from-literal=DB_PASS=admin123

πŸ”Ή Mount or Inject via ENV in deployment YAML.


βœ… Step 11: OpenShift Pipelines (Tekton)

  1. In OperatorHub, install OpenShift Pipelines Operator
  2. Create:
    • PipelineResource
    • Task
    • Pipeline
  3. Use the developer console’s Pipelines view to build CI/CD

βœ… Step 12: Monitor with Web UI

  • Use Observe β†’ Metrics
  • View Dashboard, Topology, and Builds
  • Use Pod terminal from console

βœ… Step 13: Delete a Project

oc delete project demo-app

πŸ“š Bonus Tips:

FeatureCLI Command
List all Podsoc get pods
View eventsoc get events
Port Forwardoc port-forward svc/nginx 8080:80
RoleBindingoc adm policy add-role-to-user admin developer
Enable Dev ViewUse toggle in OpenShift console UI

πŸ§ͺ Practice Ideas:

  • Deploy a multi-container app with mysql + wordpress
  • Create blue-green deployments
  • Use Tekton pipeline to auto-deploy from GitHub

To deploy an image in OpenShift using the openshift/httpd image, and configure different Kubernetes resources such as StatefulSets, Secrets, ConfigMaps, CronJobs, Jobs, DaemonSets, and HPA, here are the YAML configurations and relevant commands for each.

1. Deployment (for basic deployment)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: httpd-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: httpd
  template:
    metadata:
      labels:
        app: httpd
    spec:
      containers:
      - name: httpd
        image: openshift/httpd
        ports:
        - containerPort: 80

Command to deploy:

oc apply -f httpd-deployment.yaml

2. StatefulSet (for managing stateful workloads)

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: httpd-statefulset
spec:
  serviceName: "httpd"
  replicas: 3
  selector:
    matchLabels:
      app: httpd
  template:
    metadata:
      labels:
        app: httpd
    spec:
      containers:
      - name: httpd
        image: openshift/httpd
        ports:
        - containerPort: 80

Command to deploy:

oc apply -f httpd-statefulset.yaml

3. Secrets (for storing sensitive data like passwords)

apiVersion: v1
kind: Secret
metadata:
  name: httpd-secret
type: Opaque
data:
  password: cGFzc3dvcmQ=  # base64 encoded password

Command to create a secret:

oc apply -f httpd-secret.yaml

4. ConfigMap (for configuration files)

apiVersion: v1
kind: ConfigMap
metadata:
  name: httpd-config
data:
  httpd.conf: |
    ServerName localhost
    DocumentRoot /var/www/html

Command to create a config map:

oc apply -f httpd-config.yaml

5. CronJob (for scheduling periodic jobs)

apiVersion: batch/v1
kind: CronJob
metadata:
  name: httpd-cronjob
spec:
  schedule: "*/5 * * * *"  # Every 5 minutes
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: httpd
            image: openshift/httpd
          restartPolicy: OnFailure

Command to deploy a cron job:

oc apply -f httpd-cronjob.yaml

6. Job (for one-time tasks)

apiVersion: batch/v1
kind: Job
metadata:
  name: httpd-job
spec:
  template:
    spec:
      containers:
      - name: httpd
        image: openshift/httpd
      restartPolicy: Never

Command to deploy a job:

oc apply -f httpd-job.yaml

7. DaemonSet (for deploying a pod on every node)

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: httpd-daemonset
spec:
  selector:
    matchLabels:
      app: httpd
  template:
    metadata:
      labels:
        app: httpd
    spec:
      containers:
      - name: httpd
        image: openshift/httpd
        ports:
        - containerPort: 80

Command to deploy a daemon set:

oc apply -f httpd-daemonset.yaml

8. Horizontal Pod Autoscaler (HPA)

apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: httpd-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: httpd-deployment
  minReplicas: 1
  maxReplicas: 10
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

Command to deploy HPA:

oc apply -f httpd-hpa.yaml

Summary of Commands

To deploy each of the above resources, use the following commands:

  1. Deployment:

    oc apply -f httpd-deployment.yaml
  2. StatefulSet:

    oc apply -f httpd-statefulset.yaml
  3. Secrets:

    oc apply -f httpd-secret.yaml
  4. ConfigMap:

    oc apply -f httpd-config.yaml
  5. CronJob:

    oc apply -f httpd-cronjob.yaml
  6. Job:

    oc apply -f httpd-job.yaml
  7. DaemonSet:

    oc apply -f httpd-daemonset.yaml
  8. Horizontal Pod Autoscaler:

    oc apply -f httpd-hpa.yaml

These YAML files and commands cover the most common Kubernetes resources you may need while deploying an image on OpenShift. Adjust the values (e.g., replicas, resources, image, etc.) as needed for your use case.

view raw README.md hosted with ❀ by GitHub
Subscribe
Notify of
guest


0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

0
Would love your thoughts, please comment.x
()
x