OpenShift: An Open-Source Container Application Platform
Overview of OpenShift
OpenShift is a powerful Platform as a Service (PaaS) that enables developers to build, deploy, and manage applications quickly and efficiently. It integrates with Docker and Kubernetes to provide a comprehensive container orchestration and management solution, offering several variations depending on your needs:
OpenShift Origin: A Deep Dive
OpenShift Origin builds on top of Docker and Kubernetes, adding tools that cater to both developers and operations teams. It accelerates the application lifecycle by providing:
Installing and Starting OpenShift
To get started with OpenShift, you can follow the official installation guide available at OpenShift Documentation.
Steps to Install and Start OpenShift:
minishift.exe start --vm-driver virtualbox
Accessing OpenShift
OpenShift can be accessed in three different ways:
Working with OpenShift CLI (oc)
The oc command-line client is a powerful tool for interacting with OpenShift. Below are some common commands and explanations:
oc-env
This command configures your shell environment for the oc client.
oc login -u admin -p password
This logs you in as an administrator.
oc login -u developer -p password
This logs you in as a developer user.
oc logout
This logs you out of your current OpenShift session.
oc whoami -t
This command returns the current user and authentication token being used.
oc get projects
oc project dev-2
The first command lists all projects you have access to. The second command switches to a specific project (dev-2).
领英推荐
oc rollout latest dc/simple-webapp-docker
oc rollout history dc/simple-webapp-docker
oc rollout describe dc/simple-webapp-docker
oc rollout undo dc/simple-webapp-docker
These commands are used for managing deployments, including initiating a rollout, viewing the rollout history, describing the current state, and undoing the last deployment.
oc get pvc
oc delete pvc db
These commands allow you to manage persistent storage claims, which are used to store data persistently across pod restarts.
oc create -f app.yml -n project-1
oc export service db
These commands create resources from a YAML configuration file and export services for easier replication.
Example: Starting and Managing Minishift
To work with Minishift, the following commands are useful:
minishift.exe start --vm-driver virtualbox
This command starts the Minishift VM using VirtualBox as the driver.
minishift oc-env
Configures your shell environment for the Minishift oc client.
minishift delete
Removes the Minishift VM and any associated data.
minishift status
Displays the current status of the Minishift VM.
minishift openshift restart
Restarts the OpenShift cluster running within Minishift.
Using REST API with OpenShift
The REST API is a powerful way to interact with OpenShift programmatically. For example, to get user information or list all projects:
oc whoami -t
curl https://locahost:8443/oapi/v1/users -H "Authorization: Bearer <Token>"
curl https://192.168.99.100:8443/oapi/v1/projects -k -H "Authorization: Bearer fbegqvmGfxVH-1yC2d74FStFXotypp6FO8o0sWtGOyI"
Building and Deploying Applications
OpenShift supports multiple deployment strategies and provides robust CI/CD capabilities. Here’s how a typical deployment pipeline might look:
Deployment Strategies:
I launch, scale, and sell businesses (and help other founders do the same)
1 个月Ali - Great post - thanks for sharing!