Skip to content

Commit

Permalink
working on kubernetes deployment, and removed proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Fuller committed Jan 30, 2019
1 parent 61eaedf commit 8cbcb69
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 29 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ Then, point the frontend at your freshly deployed backend, and push it as well:
$ cd ../frontend
$ vim manifest.yml
...
# Enter the route of the backend application you just pushed
REACT_APP_API_URL: https://pong-backend.mycf.example
$ cf push
...
routes:
Expand Down
6 changes: 3 additions & 3 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ func main() {
port = 8080
}
q := queue.New(count)
http.HandleFunc("/list", List(q))
http.HandleFunc("/add", Add(q))
http.HandleFunc("/remove", Remove(q))
http.HandleFunc("/backend/list", List(q))
http.HandleFunc("/backend/add", Add(q))
http.HandleFunc("/backend/remove", Remove(q))
err = http.ListenAndServe(fmt.Sprintf(":%d", port), nil)
if err != nil {
fmt.Printf("Done serving, error: %s \n", err)
Expand Down
2 changes: 2 additions & 0 deletions backend/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ applications:
memory: 64M
buildpack: go_buildpack
command: backend
routes:
- route: https://pong-queue.cfapps.io/backend
env:
GOPACKAGENAME: github.com/benjamintf1/queue-app/backend
RESOURCE_COUNT: 2
3 changes: 2 additions & 1 deletion frontend/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
applications:
- name: pong-queue
memory: 256M
routes:
- route: https://pong-queue-staging-test.cfapps.io/
buildpack: https://github.com/pianohacker/create-react-app-buildpack.git
env:
OPTIMIZE_MEMORY: true
NODE_ENV: production
REACT_APP_API_URL: https://pong-backend.cfapps.io
3 changes: 1 addition & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"eslintConfig": {
"extends": "react-app",
"eqeqeq": 0
},
"proxy": "http://localhost:8080/"
}
}
11 changes: 5 additions & 6 deletions frontend/src/Pong.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import Favicon from './Favicon';
import Notifier from './Notifier';
import Queue from './Queue';

const API_URL = process.env.REACT_APP_API_URL || "http://localhost:8080";
const REFRESH_PERIOD = 5 * 1000;

function PongHeader({ availableResources }) {
Expand Down Expand Up @@ -59,16 +58,16 @@ class Pong extends Component {
const oldPosition = oldQueue.findIndex( ( { Name } ) => Name === lastAddedName );
const newPosition = newQueue.findIndex( ( { Name } ) => Name === lastAddedName );

if ( newPosition !== -1 &&
newPosition < oldPosition &&
if ( newPosition !== -1 &&
newPosition < oldPosition &&
oldPosition >= resourceCount &&
newPosition < resourceCount ) {
this.notifications.show();
}
}

refreshList() {
fetch(API_URL + "/list")
fetch("/backend/list")
.then(response => response.json())
.then(({ Queue: queue, ResourceCount: resourceCount }) => {
this.maybeNotify( queue );
Expand Down Expand Up @@ -98,7 +97,7 @@ class Pong extends Component {
return newQueue;
} );
fetch(
API_URL + "/remove",
"/backend/remove",
{
method: "POST",
body: JSON.stringify({ Name: name }),
Expand All @@ -114,7 +113,7 @@ class Pong extends Component {
lastAddedName: name,
}) );
fetch(
API_URL + "/add",
"/backend/add",
{
method: "POST",
body: JSON.stringify({ Name: name }),
Expand Down
74 changes: 59 additions & 15 deletions k8s/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,88 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: pong-queue
name: pong-backend
labels:
app: pong
app: pong-backend
spec:
replicas: 1
selector:
matchLabels:
app: pong
app: pong-backend
template:
metadata:
labels:
app: pong
app: pong-backend
spec:
containers:
- name: queue-backend
image: benjamintf1/queue-backend:latest
imagePullPolicy: Always
ports:
- containerPort: 8080
env:
- name: RESOURCE_COUNT
value: "2"
- name: PORT
value: "8080"
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: pong-frontend
labels:
app: pong-frontend
spec:
replicas: 1
selector:
matchLabels:
app: pong-frontend
template:
metadata:
labels:
app: pong-frontend
spec:
containers:
- name: queue-frontend
image: benjamintf1/queue-frontend:latest
imagePullPolicy: Always
ports:
- containerPort: 3000
env:
- name: REACT_APP_SHOW_TIME_STARTED
value: "true"
- name: REACT_APP_HIGHLIGHT_TIME_STARTED_AFTER
value: "20"
- name: REACT_APP_API_URL
value: " "
- name: DANGEROUSLY_DISABLE_HOST_CHECK
value: "true"

---
kind: Service
apiVersion: v1
metadata:
name: pong
name: pong-backend
annotations:
cloud.google.com/app-protocols: '{"frontend":"HTTPS","frontend":"HTTP"}'
service.alpha.kubernetes.io/app-protocols: '{"frontend":"HTTPS","frontend":"HTTP"}'
spec:
type: NodePort
selector:
app: pong
app: pong-backend
ports:
- name: backend
protocol: TCP
port: 8081
port: 8080
targetPort: 8080
---
kind: Service
apiVersion: v1
metadata:
name: pong-frontend
annotations:
cloud.google.com/app-protocols: '{"frontend":"HTTPS","frontend":"HTTP"}'
service.alpha.kubernetes.io/app-protocols: '{"frontend":"HTTPS","frontend":"HTTP"}'
spec:
type: NodePort
selector:
app: pong-frontend
ports:
- name: frontend
protocol: TCP
port: 8080
Expand All @@ -69,6 +97,22 @@ metadata:
spec:
tls:
- secretName: tls-secret
backend:
serviceName: pong
servicePort: 8080
rules:
- http:
paths:
- path: /*
backend:
serviceName: pong-frontend
servicePort: 8080
- path: /list
backend:
serviceName: pong-backend
servicePort: 8080
- path: /add
backend:
serviceName: pong-backend
servicePort: 8080
- path: /remove
backend:
serviceName: pong-backend
servicePort: 8080

0 comments on commit 8cbcb69

Please sign in to comment.