From 73b37fdd0be28a3728ec382454af24eedf8a21d4 Mon Sep 17 00:00:00 2001 From: Bruno Russi Lautenschlager Date: Tue, 25 Oct 2022 17:13:52 -0300 Subject: [PATCH 1/3] Update app.js --- microservice/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microservice/app.js b/microservice/app.js index e5e494c..4de11e5 100644 --- a/microservice/app.js +++ b/microservice/app.js @@ -5,8 +5,8 @@ app.set('port', process.env.PORT || 8080); let pod = process.env.HOSTNAME || 'unknown-pod'; app.get('/', function(request, response) { - let randomColor = getRandomColor(); // <-- comment this - //let randomColor = getRandomGrayScaleColor(); // <-- uncomment this +// let randomColor = getRandomColor(); // <-- comment this + let randomColor = getRandomGrayScaleColor(); // <-- uncomment this response.writeHead(200, {'Content-Type': 'application/json'}); response.end(JSON.stringify({ From 79c68151a78de7760163853f880da4ea0fde8082 Mon Sep 17 00:00:00 2001 From: Bruno Russi Lautenschlager Date: Tue, 25 Oct 2022 17:21:03 -0300 Subject: [PATCH 2/3] Update app.js --- microservice/app.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microservice/app.js b/microservice/app.js index 4de11e5..617d9f8 100644 --- a/microservice/app.js +++ b/microservice/app.js @@ -5,8 +5,8 @@ app.set('port', process.env.PORT || 8080); let pod = process.env.HOSTNAME || 'unknown-pod'; app.get('/', function(request, response) { -// let randomColor = getRandomColor(); // <-- comment this - let randomColor = getRandomGrayScaleColor(); // <-- uncomment this + let randomColor = getRandomColor(); // <-- comment this +// let randomColor = getRandomGrayScaleColor(); // <-- uncomment this response.writeHead(200, {'Content-Type': 'application/json'}); response.end(JSON.stringify({ From 44b48fb26e56c21dc14b59edd371b586622f6d97 Mon Sep 17 00:00:00 2001 From: Bruno Russi Lautenschlager Date: Wed, 26 Oct 2022 10:11:58 -0300 Subject: [PATCH 3/3] feat: add deployment files for app --- README.md | 45 +++++-- deployment/yaml/deployment-fe.yaml | 123 +++++++++++++++++++ deployment/yaml/deployment-microservice.yaml | 45 +++++++ 3 files changed, 200 insertions(+), 13 deletions(-) create mode 100644 deployment/yaml/deployment-fe.yaml create mode 100644 deployment/yaml/deployment-microservice.yaml diff --git a/README.md b/README.md index 832c759..8e819c3 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # OSToy + ## v1.5.0 A simple Node.js application that deploys to OpenShift. It is used to help @@ -15,30 +16,29 @@ which you can: * increase the load to test out Horizontal Pod Autoscaler * if deployed to AWS, use the app to read the contents of an S3 bucket created with the AWS Controller for Kubernetes +## Configuration -# Configuration -## Environment Variables +### Environment Variables -- **PORT** (*default: 8080*): The port to expose the application on -- **MICROSERVICE_NAME** (*default: none*): The upper-cased name of the Service object associated +* **PORT** (*default: 8080*): The port to expose the application on +* **MICROSERVICE_NAME** (*default: none*): The upper-cased name of the Service object associated with the microservice application (be sure to also replace any `-` with `_`) -- **MICROSERVICE_IP** (*default: \_SERVICE\_HOST*): The static IP of the Service +* **MICROSERVICE_IP** (*default: \_SERVICE\_HOST*): The static IP of the Service object associated with the microservice application. This will be looked up from automatic OpenShift environment variables if `MICROSERVICE_NAME` is provided -- **MICROSERVICE_PORT** (*default: \_SERVICE\_PORT*): The exposed port of the Service +* **MICROSERVICE_PORT** (*default: \_SERVICE\_PORT*): The exposed port of the Service object associated with the microservice application. This will be looked up from automatic OpenShift environment variables if `MICROSERVICE_NAME` is provided -- **CONFIG_FILE** (*default: /var/config/config.json*): The fully-qualified path to the file created by +* **CONFIG_FILE** (*default: /var/config/config.json*): The fully-qualified path to the file created by the ConfigMap object -- **SECRET_FILE** (*default: /var/secret/secret.txt*): The fully-qualified path to the file created by +* **SECRET_FILE** (*default: /var/secret/secret.txt*): The fully-qualified path to the file created by the Secret object -- **PERSISTENT_DIRECTORY** (*default: /var/demo\_files*): The fully-qualified path to the directory mounted +* **PERSISTENT_DIRECTORY** (*default: /var/demo\_files*): The fully-qualified path to the directory mounted with the PersistentVolume +## Deployment -# Deployment - -## Using `oc` commands +### Using `oc` commands and `new-app` ```bash # Add Secret to OpenShift @@ -147,8 +147,27 @@ route "ostoy" created $ python -m webbrowser "$(oc get route ostoy -o template --template='https://{{.spec.host}}')" ``` +### Using `oc` commands and kubernetes files + +```bash +# Create the project on OpenShift +oc new-project ostoy + +# Deploy all the microservices artficts from backend service (deployment and service) + +$ oc create -f ./deployment/yaml/deplyment-microservice.yaml + + +# Deploy all the front-end artficts +# (Persistent Volume Claim, Deployment Object, Service, Route ConfigMaps, Secrets) + +$ oc create -f ./deployment/yaml/deplyment-fe.yaml + +# Get the route to the application and open it on web browser +$ oc get route ostoy -o template --template='https://{{.spec.host}}' +``` -### Changes from KubeToy +## Changes from KubeToy * Remove IBM CoS integration * Remove references to IBM Private Cloud diff --git a/deployment/yaml/deployment-fe.yaml b/deployment/yaml/deployment-fe.yaml new file mode 100644 index 0000000..5d17a91 --- /dev/null +++ b/deployment/yaml/deployment-fe.yaml @@ -0,0 +1,123 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: ostoy-pvc +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ostoy-frontend + labels: + app: ostoy +spec: + selector: + matchLabels: + app: ostoy-frontend + strategy: + type: Recreate + replicas: 1 + template: + metadata: + labels: + app: ostoy-frontend + spec: + containers: + - name: ostoy-frontend + image: quay.io/ostoylab/ostoy-frontend:1.5.0 + imagePullPolicy: IfNotPresent + ports: + - name: ostoy-port + containerPort: 8080 + resources: + requests: + memory: "256Mi" + cpu: "100m" + limits: + memory: "512Mi" + cpu: "200m" + volumeMounts: + - name: configvol + mountPath: /var/config + - name: secretvol + mountPath: /var/secret + - name: datavol + mountPath: /var/demo_files + livenessProbe: + httpGet: + path: /health + port: 8080 + initialDelaySeconds: 10 + periodSeconds: 5 + env: + - name: ENV_TOY_SECRET + valueFrom: + secretKeyRef: + name: ostoy-secret-env + key: ENV_TOY_SECRET + - name: MICROSERVICE_NAME + value: OSTOY_MICROSERVICE_SVC + volumes: + - name: configvol + configMap: + name: ostoy-configmap-files + - name: secretvol + secret: + defaultMode: 420 + secretName: ostoy-secret + - name: datavol + persistentVolumeClaim: + claimName: ostoy-pvc +--- +apiVersion: v1 +kind: Service +metadata: + name: ostoy-frontend-svc + labels: + app: ostoy-frontend +spec: + type: ClusterIP + ports: + - port: 8080 + targetPort: ostoy-port + protocol: TCP + name: ostoy + selector: + app: ostoy-frontend +--- +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: ostoy-route +spec: + to: + kind: Service + name: ostoy-frontend-svc +--- +apiVersion: v1 +kind: Secret +metadata: + name: ostoy-secret-env +type: Opaque +data: + ENV_TOY_SECRET: VGhpcyBpcyBhIHRlc3Q= +--- +kind: ConfigMap +apiVersion: v1 +metadata: + name: ostoy-configmap-files +data: + config.json: '{ "default": "123" }' +--- +apiVersion: v1 +kind: Secret +metadata: + name: ostoy-secret +data: + secret.txt: VVNFUk5BTUU9bXlfdXNlcgpQQVNTV09SRD1AT3RCbCVYQXAhIzYzMlk1RndDQE1UUWsKU01UUD1sb2NhbGhvc3QKU01UUF9QT1JUPTI1 +type: Opaque diff --git a/deployment/yaml/deployment-microservice.yaml b/deployment/yaml/deployment-microservice.yaml new file mode 100644 index 0000000..9fdaa54 --- /dev/null +++ b/deployment/yaml/deployment-microservice.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ostoy-microservice + labels: + app: ostoy +spec: + selector: + matchLabels: + app: ostoy-microservice + replicas: 1 + template: + metadata: + labels: + app: ostoy-microservice + spec: + containers: + - name: ostoy-microservice + image: quay.io/ostoylab/ostoy-microservice:1.5.0 + imagePullPolicy: IfNotPresent + ports: + - containerPort: 8080 + protocol: TCP + resources: + requests: + memory: "128Mi" + cpu: "50m" + limits: + memory: "256Mi" + cpu: "100m" +--- +apiVersion: v1 +kind: Service +metadata: + name: ostoy-microservice-svc + labels: + app: ostoy-microservice +spec: + type: ClusterIP + ports: + - port: 8080 + targetPort: 8080 + protocol: TCP + selector: + app: ostoy-microservice