OpenShift Hands on Labs

Hands-on Labs with Red Hat Code Ready Container:

Download all the PDF files

Reference: Red Hat CRC reference (How to do)

Hands On Labs:

1. Learn and experiment HTPasswd Lab

2. Deploy your nginx operator Lab

3. Deploy Jenkins Operators Lab

4. Deploy OpenShift Compliance Opeator Lab

5. Explore OpenShift Admin Console

6. Top 100 OpenShift CLI commands Lab

What can you do with CRC?

  1. Installation and Setup
  2. Create a Simple Web Application
  3. Container Basics
  4. Multi-Container Applications
  5. Persistent Storage
  6. Networking in Code Ready Containers
  7. Resource Management
  8. Scaling Applications
  9. Service Discovery
  10. Security Practices
  11. Continuous Integration and Deployment
  12. Rolling Updates
  13. Fault Tolerance
  14. Monitoring and Logging
  15. Customizing Base Images
  16. Secrets and Configuration Management
  17. Integration with External Services
  18. Load Balancing
  19. Container Orchestration
  20. CI/CD Integration with Jenkins
  21. Database Containers
  22. Ingress Controllers
  23. Health Checks
  24. Container Image Vulnerability Scanning
  25. Distributed Tracing
  26. Serverless Containers
  27. Multi-Environment Deployment
  28. GitOps Practices
  29. Automated Testing in Containers
  30. Explore Operator Framework

CRC Specific Commands:

openshift-crc-hands-on-labsCRC Specific Commands:

crc setup – Set up the hypervisor and install the necessary components.
crc start – Start the CodeReady Containers virtual machine.
crc stop – Stop the CodeReady Containers virtual machine.
crc delete – Delete the CodeReady Containers virtual machine.
crc status – Display the status of the CRC VM.
crc config set cpus 4 – Set the number of CPUs for CRC VM.
crc config set memory 8192 – Set the memory allocation for CRC VM.
crc config view – View the current configuration settings.
crc console – Open the OpenShift web console in the default browser.
crc oc-env – Display command to set up the oc environment.

OpenShift CLI (oc) Commands:

oc login -u developer – Log in as a developer.
oc login -u kubeadmin – Log in as the admin user.
oc new-project myproject – Create a new project.
oc get projects – List all projects.
oc project myproject – Switch to a specific project.
oc get pods – Get all pods in the current namespace.
oc create -f pod.yaml – Create a resource from a YAML file.
oc apply -f deployment.yaml – Apply a configuration to a resource.
oc delete pod mypod – Delete a specific pod.
oc scale –replicas=3 deployment/myapp – Scale a deployment.

Working with Applications

oc new-app –docker-image=myimage – Create a new app from a Docker image.
oc expose svc/myapp – Expose a service as a route.
oc get routes – Get all the routes.
oc logs pod/mypod – Get logs for a specific pod.
oc exec -it mypod — bash – Execute a command in a container.
oc set env deployment/myapp ENV_VAR=value – Set an environment variable for a deployment.
oc rollout status deployment/myapp – Watch the status of the latest rollout.
oc rollout history deployment/myapp – Check the history of rollouts.
oc rollout undo deployment/myapp – Rollback to the previous deployment.
oc describe pod/mypod – Describe detailed information about a pod.

Resource Management

oc get svc – Get all services.
oc get deployments – Get all deployments.
oc get rs – Get all ReplicaSets.
oc get nodes – Get all nodes.
oc get namespaces – Get all namespaces.
oc get events – Get events in the current namespace.
oc label pods mypod key=value – Add a label to a pod.
oc annotate pods mypod key=value – Add an annotation to a pod.
oc edit pod mypod – Edit a pod configuration.
oc patch pod mypod -p ‘{“metadata”:{“labels”:{“key”:”value”}}}’ – Patch a pod.

Networking and Security

oc get networkpolicy – List all network policies.
oc create serviceaccount mysa – Create a new service account.
oc policy add-role-to-user edit user1 – Add a role to a user.
oc adm policy add-scc-to-user privileged -z mysa – Add SCC to a service account.
oc get secrets – List all secrets.
oc create secret generic mysecret –from-literal=key1=value1 – Create a new secret.
oc secrets link default mysecret –for=pull – Link secrets to a service account.
oc adm top pods – Show metrics for pods.
oc adm top nodes – Show metrics for nodes.
oc adm node-logs node1 – Get logs from a specific node.

Advanced Operations

oc adm drain node1 – Prepare a node for maintenance.
oc adm uncordon node1 – Mark node as schedulable.
oc adm manage-node node1 –list-pods – List pods on a specific node.
oc adm manage-node node1 –evacuate – Evacuate pods

Hands On Labs:

1. Setting Up CodeReady Containers

  • Objective: Install and configure CRC on your local machine.
  • Steps:
    1. Download CRC for your operating system from the Red Hat OpenShift website.
    2. Unpack the downloaded file.
    3. Run the crc setup command.
    4. Start the cluster with crc start.
    5. Access the OpenShift console using the URL and credentials provided by crc console.

2. Deploying Your First Application

  • Objective: Deploy a sample application on the CRC cluster.
  • Steps:
    1. Access the OpenShift console.
    2. Create a new project.
    3. Select “From Catalog” and choose a sample application.
    4. Follow the wizard to deploy the application.
    5. Access the application using the route URL provided.

3. Exploring the Command Line Interface (CLI)

  • Objective: Use the OpenShift CLI (oc) to interact with your CRC cluster.
  • Steps:
    1. Install the oc CLI tool.
    2. Use oc login to authenticate.
    3. Explore various commands like oc get pods, oc describe, etc.
    4. Create and delete resources using the CLI.

4. Container Image Management

  • Objective: Learn to manage container images in CRC.
  • Steps:
    1. Pull an image from a registry using oc.
    2. Tag and push the image to the OpenShift integrated registry.
    3. Deploy an application using the new image.
    4. Monitor the deployment process.

5. Configuring Persistent Storage

  • Objective: Understand persistent storage in CRC.
  • Steps:
    1. Create a Persistent Volume Claim (PVC).
    2. Attach the PVC to an application.
    3. Test data persistence by restarting the application.
    4. Explore data retention after pod deletion.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *