-
Notifications
You must be signed in to change notification settings - Fork 14
dsf deployment dsf4openshift manual configuration
In this section you will see how you can create a new environment instance in your OpenShift cluster to deploy devonfw projects using docker images.
Yo need to have a devonfw project in a git repository or a docker image uploaded to a docker registry.
First of all you need to download the OpenShift client, you can find it here.
Remember that what you need to download oc Client Tools and not OKD Server.
Note
|
This tutorial has been made with the version 3.10.0 of the client, it is recommended to use the most current client, but if it does not work, it is possible that the instructions have become obsolete or that the OpenShift used needs another older/newer version of the client. To download a specific version of the client you can find here the older versions and the version 3.10.0. |
Once you have downloaded the client you have to add it to the PATH environment variable.
You can log using a terminal and executing the next instructions:
oc login $OpenShiftUrl
Note
|
You need a valid user to log in. |
If you need to create docker images of your projects you could use OpenShift to do it (Off course only if you have enough rights).
To do it, follow the next steps.
The first thing you need to do for create a new environment is prepare the buildconfigs for the front and for the middleware and rise default memory limits for the middleware. You can do it using a terminal and executing the next instructions:
These are a summary about the parameters used in our commands:
-
${dockerRegistry}: The url of the docker repository.
-
${props.name}: The name of the project (for example could be find on package.json)
-
${dockerTag}: The tag of the image
Note
|
From now on you will refer to the name that you are going to give to the environment as $enviroment. Remember to modify it for the correct value in all instructions. |
You need to create nginx build config with docker.
oc new-build --strategy docker --binary --docker-image nginx:alpine-perl --name=${props.name}-$environment --to=${dockerRegistry}/${props.name}:${dockerTag} --to-docker=true
Note
|
You need nginx:alpine-perl to read the environment config file in openshift, if you are not going to use it, you could use nginx:latest instead. |
oc new-build --strategy docker --binary --docker-image node:lts --name=${props.name}-$environment --to=${dockerRegistry}/${props.name}:${dockerTag} --to-docker=true
oc new-build --strategy docker --binary --docker-image openjdk:<version> --name=${props.name}-$environment --to=${dockerRegistry}/${props.name}:${dockerTag} --to-docker=true
Note
|
You need to specify the <version> of java used for your project. Also you can use the -alpine image. This image is based on the popular Alpine Linux project. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general. More information on docker hub. |
In this step is where you will build a docker image from a compiled application.
To build the source in OpenShift, first of all you need to compile your source and obtain the artifacts "dist folder" or download it from a repository. Normally the artifacts have been built on Jenkins and have been stored in Nexus.
To download it, you can access to your registry, select the last version and download the ".tar". The next image shows an example of where is the link to download it, marked in yellow:
When you have the artifacts, you can send them to your openshift and build them using your buildconfig that you created on the previous step. This is going to create a new docker image and push it to your registry.
If your docker registry need credentials you should use a secret. You could add it to your buildconfig using the next command:
oc set build-secret --push bc/${props.name}-$environment ${nameForSecret}
Now you can use your build config and push the docker image to your registry. To do it you need to use a terminal and execute the following:
oc start-build ${props.name}-$environment --from-dir=${artifactsPath} --follow
Note
|
${artifactsPath} is the path where you have the artifacts of the prerequisite (On jenkins is the dist folder generated by the build). |
Note
|
Maybe you need to raise your memory or CPU limits. |
Now it is time to configure the environment.
You need a docker image of your application. You could create it using OpenShift as you see in the last step.
To create new app you need to use the next command.
oc new-app --docker-image=${artifactsPath} --name=${props.name}-$environment --source-secret=${nameForSecret}
Note
|
You could add environment variables using -e $name=$value
|
Note
|
If you do not need to use a secret remove the end part of the command --source-secret=${nameForSecret}
|
Finally, you need add a route to access the service.
Add http route
If you want to create an http route execute the following command in a terminal:
oc expose svc/${props.name}-$environment
Add https route
If you want to create an https route you can do it executing the following command:
oc create route edge --service=${props.name}-$environment
If you want to change the default route path you can use the command --hostname=$url. For example:
oc expose svc/${props.name}-$environment --hostname=$url
oc create route edge --service=${props.name}-$environment --hostname=$url
When you have new images in the registry you must import them to OpenShift. You could do it executing the next commands:
oc import-image ${props.name}-$environment --from=${dockerRegistry}/${props.name}:${dockerTag} --confirm
Note
|
Maybe you need to raise your memory or CPU limits. It is explained below. |
If you need to raise (or decrease) the memory or CPU limits that you need you could do it for your deployments and builders configurations following the next steps.
You could do it in OpenShift using the user interface. To do it you should enter in OpenShift and go to deployments.
At the right top, you could see a drop down actions, click on it and you could edit the resource limits of the container.
Maybe you should modify the resource limits of the pod too. To do it you should click on drop down actions and go to edit YAML. Then you could see something like the next image.
In the image, you could see that appear resources two times. One at the bottom of the image, this are the container resources that you modified on the previous paragraph and another one at the top of the image. The resources of the top are for the pod, you should give to it at least the same of the sum for all containers that the pod use.
Also you could do it using command line interface and executing the next command:
To modify pod limits
oc patch dc/boat-frontend-test --patch '{"spec":{"strategy":{"resources":{"limits":{"cpu": "100m", "memory": "100Mi"}, "requests":{"cpu": "100m", "memory": "100Mi"}}}}}'
To modify container limits
When this guide was written Openshift have a bug and you cannot do it from command line interface.
Note
|
If that command did not work and you received an error like this error: unable to parse "'{spec:…": yaml: found unexpected end of stream , try to use the patch using "" instead of ''. It looks like this: --patch "{\"spec\":…\"}}}}"
|
You could do it using command line interface and executing the next command:
oc patch bc/${props.name}${APP_NAME_SUFFIX} --patch '{"spec":{"resources":{"limits":{"cpu": "125m", "memory": "400Mi"},"requests":{"cpu": "125m", "memory": "400Mi"}}}}'
Note
|
If that command did not work and you received an error like this error: unable to parse "'{spec:…": yaml: found unexpected end of stream , try to use the patch using "" instead of ''. It looks like this: --patch "{\"spec\":…\"}}}}"
|
This documentation is licensed under the Creative Commons License (Attribution-NoDerivatives 4.0 International).
-
cicd configuration
-
Manual configuration
-
Automatic configuration
-
-
Custom Services
-
Azure DevOps