Skip to content

Latest commit

 

History

History
148 lines (110 loc) · 3.67 KB

6. Fireworks-Exercise-P2.md

File metadata and controls

148 lines (110 loc) · 3.67 KB

Fireworks Challange

SignalR based application that allows website users to light fireworks and display on all the connected site users. You can light single or multi shot using the app. There is also a button that can stimulate a crash /home/admin. Pressing the button again will make the application run again.

The application can only run as a single instance and does not support scaleout at present, unless backpane is setup using SIGNALR_CS environment variable

Port Exposed

  • 80

Images

  • Green: kunalbabre/fireworks:green

  • Blue: kunalbabre/fireworks:blue

  • Red: kunalbabre/fireworks:red

  • Yellow: kunalbabre/fireworks:yellow

  • Latest: kunalbabre/fireworks:latest

Trigger fireworks manually

  • Trigger Single - /home/singleshot
  • Trigger Multishot - /home/multishot

Health Monitoring

  • Liveness: /home/isRunning

    • returns HTTP 200 if the application is alive
    • returns HTTP 400 if the application has crashed
  • Readiness: /home/isRunning

    • returns HTTP 200 if the application is alive
    • returns HTTP 400 if the application has crashed

Environment variables

  • SIGNALR_CS: (optional) if you wish to scale-out you can provide connection string for Redis or Azure SignalR
  • APP_COLOR: (works with latest tag) you can specify theme color for the app (red,green, blue, yellow)

Exercise Part 2

  1. Scale App to 1 instance

  2. Simulate shooting of 10's of multishot every 1 minute, take advantage of parallel and completions properties of Job (tip: create CronJob)

hint

# generate YAML for CronJob to get started

kubectl run sleepycron --image=busybox --restart=OnFailure --schedule="*/1 * * * *" --dry-run -o yaml -- /bin/sh -c "for i in 1 2 3 4 5;do wget fireservice:80/home/multiShot; sleep 1;done" > firecron.yaml

# modify file and add completion and parallel attribute
code firecron.yaml

# apply changes
kubectl apply -f firecron.yaml

Sample CronJob with parallelism and Completion attributes.

apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: sleepycronjob
spec:
    parallelism: 2
    completions: 60
    template:
    metadata:
    spec:
        containers:
        - command:
        - /bin/sh
        - -c
        - for i in 1 2 3 4 5;do wget foo:80/home/multiShot; sleep 1;done
        image: busybox
        name: firecron
        resources: {}
        restartPolicy: OnFailure
    schedule: '*/1 * * * *'

Stretch goals

  1. Configure Backplane for Fireworks App to use Azure SignalR (you will have to deploy the Azure SignalR first from Azure)

    Fireworks app supports Signalr backplane allowing it to scale out and can be specified using an envirnment variable called SIGNALR_CS. The value should be a connection string for Redis or Azure SignalR

hint

apiVersion: v1
kind: Pod
metadata:
name: sample-pod
spec:
containers:
- name: mycontainer
    image: someImage
    env: #
    - name: SomeName #
      value: SomeValue #

  1. Modify the deployment to populate SIGNALR_CS env variable from Secrets config
hint

# create Secret 
kubectl create secret generic mysecret --from-literal=<name>=<value>

# modify your deployment and add env variable from secret under  
kubectl edit deploy 

Sample Pod using environment variable from secret

apiVersion: v1
kind: Pod
metadata:
name: sample-cret-env-pod
spec:
containers:
- name: mycontainer
    image: someImage
    env: #
    - name: SECRET_USERNAME #
        valueFrom: #
        secretKeyRef: #
            name: mysecret #
            key: username #