Prerequisites:
- Access to the Developer Sandbox for Red Hat OpenShift
- This example uses data from the move2kube-demos repository on GitHub.
Deploy the application to Kubernetes
Now it’s time to deploy the application. Let's get inside the ./myproject
directory:
$ cd myproject/
$ ls
Readme.md deploy scripts source
Run the builddockerimages.sh
script inside the ./myproject/scripts
directory. (This step might take some time to complete.)
$ cd scripts
$ ./builddockerimages.sh
[+] Building 1.9s (8/8) FINISHED
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 747B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for registry.access.redhat.com/ubi8/nodejs-12:latest 1.7s
=> [internal] load build context 0.0s
=> => transferring context: 868B 0.0s
=> [1/3] FROM registry.access.redhat.com/ubi8/nodejs-12@sha256:1208ace959a40906e0e0e753b5ed5621c052a5a115e333d70ca8fa5e5c0dc0ca 0.0s
=> CACHED [2/3] COPY . . 0.0s
=> CACHED [3/3] RUN npm install 0.0s
=> exporting to image 0.0s
=> => exporting layers 0.0s
=> => writing image sha256:2d560a9a7b40f2d29447b57b619d55a5dd103ae5dd626cd517791f4ae8e61cbb 0.0s
=> => naming to docker.io/library/cfnodejsapp 0.0s
/Users/username/myproject
done
Now, using the pushimages.sh
script, we can push our application’s images to the registry we specified during the transform phase. For this step, you need to log in to your Docker registry. To log in to quay.io, run docker login quay.io
. To log in to the IBM Cloud us.icr.io registry, refer to the documentation.
$ ./pushimages.sh
Using default tag: latest
The push refers to repository [quay.io/danieloh30/cfnodejsapp]
44682b6a7ca8: Layer already exists
4d994360499e: Layer already exists
31226b9a7823: Layer already exists
718375ad3f65: Layer already exists
e0b9a99c51af: Layer already exists
ef5d9ad2a541: Layer already exists
93749af418e7: Layer already exists
latest: digest: sha256:197c820069a3691c727db3ccf0d544601035fdca6dba7b96bae16463068a5307 size: 1789
Note: If you pushed the image repository to quay.io, then in the Repository Visibility in the quay.io cfnodejsapp repository settings, select whether you want the repository to be public so that the Kubernetes cluster can properly access it.
Finally, we will deploy the application with the oc apply
command using the YAML files that Move2Kube created for us in the ./myproject/deploy/yamls
directory.
We'll use Developer Sandbox for Red Hat OpenShift, a shared multitenant OpenShift cluster that is preconfigured with a set of developer tools. To access the sandbox, visit Get started in the Sandbox and sign up for free.
We will create Kubernetes resources in the OpenShift cluster using the oc
command line tool instead of kubectl. If you haven't already installed the oc
CLI, follow the instructions in this article: Where can I download the OpenShift command line tool?
Before you deploy the application, you need to log in to the OpenShift cluster on the sandbox. You can copy the oc login
command with a valid token (Figure 1).