Middle
How did you deploy the application using OpenShift?
sobes.tech AI
Answer from AI
When deploying an application in OpenShift, I usually followed these steps:
- Preparing the application artifact: Ensured I had a ready Docker image of the application or the source code that OpenShift could build.
- Authenticating in the cluster: Used the
oc logincommand to connect to the desired OpenShift environment. - Creating a new project (namespace): If the project did not exist, I created it:
# Creating a new project oc new-project my-application-project - Creating a BuildConfig resource: Defined how OpenShift should build the application image. This could be a Dockerfile build or an S2I (Source-to-Image) build from source code.
Then I applied it:# Example BuildConfig for S2I build from a Git repository apiVersion: build.openshift.io/v1 kind: BuildConfig metadata: name: my-app-build spec: source: git: uri: https://github.com/my-org/my-app.git # Repository URL strategy: sourceStrategy: from: kind: ImageStreamTag name: 'nodejs:latest' # Base image for build namespace: openshift output: to: kind: ImageStreamTag name: 'my-app:latest' # Tag for the output image# Applying BuildConfig oc apply -f buildconfig.yaml - Starting the build: Initiated the image build process.
# Starting build by BuildConfig name oc start-build my-app-build --follow - Creating a DeploymentConfig resource: Described how the application should be deployed and managed in the cluster.
I applied it:# Example DeploymentConfig apiVersion: apps.openshift.io/v1 kind: DeploymentConfig metadata: name: my-app spec: replicas: 3 # Desired number of instances selector: app: my-app # Selector for Pods strategy: type: Rolling # Deployment strategy template: metadata: labels: app: my-app spec: containers: - name: my-app image: 'image-registry.openshift-image-registry.svc:5000/my-application-project/my-app:latest' # Image from ImageStream ports: - containerPort: 8080 # Application port triggers: - type: ConfigChange # Trigger on DeploymentConfig change - type: ImageChange # Trigger on image change in ImageStream imageChangeParams: automatic: true containerNames: - my-app from: kind: ImageStreamTag name: 'my-app:latest'# Applying DeploymentConfig oc apply -f deploymentconfig.yaml - Creating a Service resource: Defined how the application Pods would be accessible within the cluster.
I applied it:# Example Service apiVersion: v1 kind: Service metadata: name: my-app-service spec: selector: app: my-app # Selector for Pods ports: - protocol: TCP port: 80 # External port of the service targetPort: 8080 # Target port in the Pod# Applying Service oc apply -f service.yaml - Creating a Route resource: Made the application accessible externally.
I applied it:# Example Route apiVersion: route.openshift.io/v1 kind: Route metadata: name: my-app-route spec: to: kind: Service name: my-app-service # Service to route traffic to port: targetPort: 80 # Target port of the service# Applying Route oc apply -f route.yaml - Monitoring deployment: Watched the deployment and Pod statuses.
# Viewing DeploymentConfig status oc rollout status dc/my-app # Viewing list of Pods oc get pods # Viewing Pod logs oc logs <pod_name>
Depending on specific requirements, Kubernetes Deployment could be used instead of OpenShift DeploymentConfig, along with other resources like PersistentVolumeClaims for storage management or Secrets and ConfigMaps for configuration injection. These steps are often automated with CI/CD pipelines (e.g., OpenShift Pipelines, Jenkins, GitLab CI).