Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OSToy

## v1.5.0

A simple Node.js application that deploys to OpenShift. It is used to help
Expand All @@ -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: <MICROSERVICE_NAME>\_SERVICE\_HOST*): The static IP of the Service
* **MICROSERVICE_IP** (*default: <MICROSERVICE_NAME>\_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: <MICROSERVICE_NAME>\_SERVICE\_PORT*): The exposed port of the Service
* **MICROSERVICE_PORT** (*default: <MICROSERVICE_NAME>\_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
Expand Down Expand Up @@ -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
Expand Down
123 changes: 123 additions & 0 deletions deployment/yaml/deployment-fe.yaml
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions deployment/yaml/deployment-microservice.yaml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion microservice/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let pod = process.env.HOSTNAME || 'unknown-pod';

app.get('/', function(request, response) {
let randomColor = getRandomColor(); // <-- comment this
//let randomColor = getRandomGrayScaleColor(); // <-- uncomment this
// let randomColor = getRandomGrayScaleColor(); // <-- uncomment this

response.writeHead(200, {'Content-Type': 'application/json'});
response.end(JSON.stringify({
Expand Down