OpenShift - Deploy an application from a JSON or YAML file

An image contains the code used to create a deployment. Then, a deployment can be created from an image, which should then create a replica set (which is the number of pods that should be created), and then the pods should be created.

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

There are various ways to deploy an app.

A  JSON or YAML file that contains key value pairs can be used to create an object, such as a config map, deployment, a project, a pod, a route, a secret, a service, et cetera. These files are known as templates. For example, let's say you have a YAML file named deployment.yml that contains the following markup. Notice "kind: Deployment", which means this template will be used to create a deployment.

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

 

The oc apply or oc create command with the -f or --filename option can be used to create the deployment using the template JSON or YAML file.

The oc replace command can be used to replace a deployment using a new or updated template JSON or YAML file.

The oc edit command can be used to update a deployments template YAML file.

~]$ oc create --filename deployment.yml
deployment.apps/hello-openshift created

 

The oc get deployments command can be used to list the deployments. The DESIRED, CURRENT, UP-TO-DATE and AVAILABLE columns represent the number of replicas for the deployment.

Replicas is the number of pods that should be created for the deployment.

~]# oc get deployments --namespace <some namespace>
NAME                DESIRED   CURRENT   UP-TO-DATE   AVAILABLE   AGE
hello-openshift     1         1         1            1           23s

 

The oc get pods command can be used to determine if the pod is up and running.

~]$ oc get pods
NAME                READY   STATUS      RESTARTS   AGE
hello-openshift     1/1     Running     0          23s

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.





Please enter f46c8 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |