From 455158c9429858011992c0ac48ac7d86bb51c0a6 Mon Sep 17 00:00:00 2001 From: David Currie Date: Mon, 2 Oct 2017 22:23:24 +0100 Subject: [PATCH] Initial Kubernetes support --- docker-build | 44 +++ docker-push | 10 + front-end-ui/Dockerfile | 3 + .../src/app/auth/services/auth.service.ts | 4 +- .../src/app/group/services/group.service.ts | 3 +- .../src/app/login/services/login.service.ts | 4 +- .../app/occasion/services/occasion.service.ts | 7 +- .../src/app/user/services/user.service.ts | 5 +- kubernetes.yml | 353 ++++++++++++++++++ microservice-auth/Dockerfile | 2 + microservice-group/Dockerfile | 4 + microservice-notification/Dockerfile | 2 + microservice-notification/pom.xml | 2 +- microservice-notification_v1_1/Dockerfile | 2 + microservice-occasion/Dockerfile | 4 + microservice-user/Dockerfile | 3 + shared-keystore/pom.xml | 2 +- 17 files changed, 439 insertions(+), 15 deletions(-) create mode 100755 docker-build create mode 100755 docker-push create mode 100644 front-end-ui/Dockerfile create mode 100644 kubernetes.yml create mode 100644 microservice-auth/Dockerfile create mode 100644 microservice-group/Dockerfile create mode 100644 microservice-notification/Dockerfile create mode 100644 microservice-notification_v1_1/Dockerfile create mode 100644 microservice-occasion/Dockerfile create mode 100644 microservice-user/Dockerfile diff --git a/docker-build b/docker-build new file mode 100755 index 0000000..2f98664 --- /dev/null +++ b/docker-build @@ -0,0 +1,44 @@ +#!/bin/bash + +MONGO_HOSTNAME="mongo" +MONGO_PORT=27017 +DOMAIN="default.svc.cluster.local" + +mvn -Dmaven.test.skip=true \ + -Duser.mongo.hostname=$MONGO_HOSTNAME \ + -Duser.mongo.port=$MONGO_PORT \ + -Duser.http.port=9080 \ + -Duser.https.port=9443 \ + -Duser.hostname=user.$DOMAIN \ + -Dgroup.mongo.hostname=$MONGO_HOSTNAME \ + -Dgroup.mongo.port=$MONGO_PORT \ + -Dgroup.http.port=9080 \ + -Dgroup.https.port=9443 \ + -Dgroup.hostname=group.$DOMAIN \ + -Doccasion.mongo.hostname=$MONGO_HOSTNAME \ + -Doccasion.mongo.port=$MONGO_PORT \ + -Doccasion.http.port=9080 \ + -Doccasion.https.port=9443 \ + -Doccasion.hostname=occasion.$DOMAIN \ + -Dnotification.http.port=9080 \ + -Dnotification.https.port=9443 \ + -Dnotification.hostname=notification.$DOMAIN \ + -Dnotification_1_1.http.port=9080 \ + -Dnotification_1_1.https.port=9443 \ + -Dnotification_1_1.hostname=notification11.$DOMAIN \ + -Dfrontend.http.port=9080 \ + -Dfrontend.https.port=9443 \ + -Dfrontend.hostname=frontend.$DOMAIN \ + -Dauth.http.port=9080 \ + -Dauth.https.port=9443 \ + -Dauth.hostname=auth.$DOMAIN \ + clean package install + +NAMESPACE="acmegifts" +docker build -t $NAMESPACE/front-end-ui:latest front-end-ui +docker build -t $NAMESPACE/microservice-auth:latest microservice-auth +docker build -t $NAMESPACE/microservice-group:latest microservice-group +docker build -t $NAMESPACE/microservice-notification:latest microservice-notification +docker build -t $NAMESPACE/microservice-notification-v1-1:latest microservice-notification_v1_1 +docker build -t $NAMESPACE/microservice-occasion:latest microservice-occasion +docker build -t $NAMESPACE/microservice-user:latest microservice-user \ No newline at end of file diff --git a/docker-push b/docker-push new file mode 100755 index 0000000..bef3796 --- /dev/null +++ b/docker-push @@ -0,0 +1,10 @@ +#!/bin/bash + +NAMESPACE="acmegifts" +docker push $NAMESPACE/front-end-ui:latest +docker push $NAMESPACE/microservice-auth:latest +docker push $NAMESPACE/microservice-group:latest +docker push $NAMESPACE/microservice-notification:latest +docker push $NAMESPACE/microservice-notification-v1-1:latest +docker push $NAMESPACE/microservice-occasion:latest +docker push $NAMESPACE/microservice-user:latest \ No newline at end of file diff --git a/front-end-ui/Dockerfile b/front-end-ui/Dockerfile new file mode 100644 index 0000000..a2cd653 --- /dev/null +++ b/front-end-ui/Dockerfile @@ -0,0 +1,3 @@ +FROM openliberty/open-liberty +COPY target/liberty/wlp/usr/servers/UIServer /config +RUN sed -i -e 's/httpEndpoint/httpEndpoint host="*"/g' /config/server.xml diff --git a/front-end-ui/src/app/auth/services/auth.service.ts b/front-end-ui/src/app/auth/services/auth.service.ts index b57f056..5720e65 100644 --- a/front-end-ui/src/app/auth/services/auth.service.ts +++ b/front-end-ui/src/app/auth/services/auth.service.ts @@ -17,8 +17,8 @@ import { Observable } from 'rxjs/Rx'; */ @Injectable() export class AuthService { - // Maven fills in these variables from the pom.xml - private url = 'https://${auth.hostname}:${auth.https.port}/auth/'; + + private url = '/service/auth/'; constructor(private http: HttpClient) {} diff --git a/front-end-ui/src/app/group/services/group.service.ts b/front-end-ui/src/app/group/services/group.service.ts index 7fdc0ca..e125d43 100644 --- a/front-end-ui/src/app/group/services/group.service.ts +++ b/front-end-ui/src/app/group/services/group.service.ts @@ -22,8 +22,7 @@ import { Observable } from 'rxjs/Rx'; export class GroupService { private groups: Group[]; - // Maven fills in these variables from the pom.xml - private groupsUrl = 'https://${group.hostname}:${group.https.port}/groups/'; + private groupsUrl = '/service/groups/'; constructor(private http: HttpClient) { if (sessionStorage.jwt == null) { diff --git a/front-end-ui/src/app/login/services/login.service.ts b/front-end-ui/src/app/login/services/login.service.ts index 27d1293..8fdfd64 100644 --- a/front-end-ui/src/app/login/services/login.service.ts +++ b/front-end-ui/src/app/login/services/login.service.ts @@ -14,8 +14,8 @@ import { Observable } from 'rxjs/Rx'; @Injectable() export class LoginService { - // Maven fills in these variables from the pom.xml - private url = 'https://${user.hostname}:${user.https.port}/logins/'; + + private url = '/service/logins/'; constructor(private http: HttpClient) { } diff --git a/front-end-ui/src/app/occasion/services/occasion.service.ts b/front-end-ui/src/app/occasion/services/occasion.service.ts index 3819e76..0a17f96 100644 --- a/front-end-ui/src/app/occasion/services/occasion.service.ts +++ b/front-end-ui/src/app/occasion/services/occasion.service.ts @@ -39,10 +39,9 @@ export class OccasionService { private jwt: string = null; - // Maven fills in these variables from the pom.xml - groupUrl = 'https://${group.hostname}:${group.https.port}/groups/'; - occasionUrl = 'https://${occasion.hostname}:${occasion.https.port}/occasions/'; - userUrl = 'https://${user.hostname}:${user.https.port}/users/'; + groupUrl = '/service/groups/'; + occasionUrl = '/service/occasions/'; + userUrl = '/service/users/'; createOccasion(occasion: Occasion): Observable { const payload = JSON.stringify(occasion); diff --git a/front-end-ui/src/app/user/services/user.service.ts b/front-end-ui/src/app/user/services/user.service.ts index 118f6f0..9d3a243 100644 --- a/front-end-ui/src/app/user/services/user.service.ts +++ b/front-end-ui/src/app/user/services/user.service.ts @@ -22,9 +22,8 @@ import { Users } from '../users'; export class UserService { private users: User[]; - // Maven fills in these variables from the pom.xml - private userUrl = 'https://${user.hostname}:${user.https.port}/users/'; - private userUrl2 = 'https://${user.hostname}:${user.https.port}/users'; + private userUrl = '/service/users/'; + private userUrl2 = '/service/users'; constructor(private http: HttpClient) {} diff --git a/kubernetes.yml b/kubernetes.yml new file mode 100644 index 0000000..21a17ce --- /dev/null +++ b/kubernetes.yml @@ -0,0 +1,353 @@ +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: mongo-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: mongo + spec: + containers: + - name: mongo + image: mongo + imagePullPolicy: Always + ports: + - containerPort: 27017 +--- +apiVersion: v1 +kind: Service +metadata: + name: mongo +spec: + selector: + app: mongo + ports: + - protocol: TCP + port: 27017 + targetPort: 27017 +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: front-end-ui-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: front-end-ui + spec: + containers: + - name: front-end-ui + image: acmegifts/front-end-ui:latest + imagePullPolicy: Always + ports: + - containerPort: 9443 +--- +apiVersion: v1 +kind: Service +metadata: + name: front-end-ui +spec: + selector: + app: front-end-ui + ports: + - name: https + protocol: TCP + port: 9443 + targetPort: 9443 +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: microservice-auth-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: microservice-auth + spec: + containers: + - name: microservice-auth + image: acmegifts/microservice-auth:latest + imagePullPolicy: Always + ports: + - containerPort: 9443 +--- +apiVersion: v1 +kind: Service +metadata: + name: auth +spec: + selector: + app: microservice-auth + ports: + - name: https + protocol: TCP + port: 9443 + targetPort: 9443 +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: microservice-user-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: microservice-user + spec: + containers: + - name: microservice-user + image: acmegifts/microservice-user:latest + imagePullPolicy: Always + ports: + - containerPort: 9443 +--- +apiVersion: v1 +kind: Service +metadata: + name: user +spec: + selector: + app: microservice-user + ports: + - name: https + protocol: TCP + port: 9443 + targetPort: 9443 +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: microservice-group-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: microservice-group + spec: + containers: + - name: microservice-group + image: acmegifts/microservice-group:latest + imagePullPolicy: Always + ports: + - containerPort: 9443 +--- +apiVersion: v1 +kind: Service +metadata: + name: group +spec: + selector: + app: microservice-group + ports: + - name: https + protocol: TCP + port: 9443 + targetPort: 9443 +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: microservice-occasion-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: microservice-occasion + spec: + containers: + - name: microservice-occasion + image: acmegifts/microservice-occasion:latest + imagePullPolicy: Always + ports: + - containerPort: 9443 +--- +apiVersion: v1 +kind: Service +metadata: + name: occasion +spec: + selector: + app: microservice-occasion + ports: + - name: https + protocol: TCP + port: 9443 + targetPort: 9443 +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: microservice-notification-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: microservice-notification + spec: + containers: + - name: microservice-notification + image: acmegifts/microservice-notification:latest + imagePullPolicy: Always + ports: + - containerPort: 9443 + - containerPort: 9080 +--- +apiVersion: v1 +kind: Service +metadata: + name: notification +spec: + selector: + app: microservice-notification + ports: + - name: http + protocol: TCP + port: 9080 + targetPort: 9080 + - name: https + protocol: TCP + port: 9443 + targetPort: 9443 +--- +apiVersion: apps/v1beta1 +kind: Deployment +metadata: + name: microservice-notification11-deployment +spec: + replicas: 1 + template: + metadata: + labels: + app: microservice-notification11 + spec: + containers: + - name: microservice-notification11 + image: acmegifts/microservice-notification-v1-1:latest + imagePullPolicy: Always + ports: + - containerPort: 9443 + - containerPort: 9080 +--- +apiVersion: v1 +kind: Service +metadata: + name: notification11 +spec: + selector: + app: microservice-notification11 + ports: + - name: http + protocol: TCP + port: 9080 + targetPort: 9080 + - name: https + protocol: TCP + port: 9443 + targetPort: 9443 +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: front-end-ui-ingress + annotations: + ingress.kubernetes.io/rewrite-target: / + ingress.kubernetes.io/secure-backends: "true" +spec: + rules: + - http: + paths: + - path: / + backend: + serviceName: front-end-ui + servicePort: 9443 +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: auth-ingress + annotations: + ingress.kubernetes.io/rewrite-target: /auth + ingress.kubernetes.io/secure-backends: "true" +spec: + rules: + - http: + paths: + - path: /service/auth + backend: + serviceName: auth + servicePort: 9443 +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: users-ingress + annotations: + ingress.kubernetes.io/rewrite-target: /users + ingress.kubernetes.io/secure-backends: "true" +spec: + rules: + - http: + paths: + - path: /service/users + backend: + serviceName: user + servicePort: 9443 +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: logins-ingress + annotations: + ingress.kubernetes.io/rewrite-target: /logins + ingress.kubernetes.io/secure-backends: "true" +spec: + rules: + - http: + paths: + - path: /service/logins + backend: + serviceName: user + servicePort: 9443 +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: groups-ingress + annotations: + ingress.kubernetes.io/rewrite-target: /groups + ingress.kubernetes.io/secure-backends: "true" +spec: + rules: + - http: + paths: + - path: /service/groups + backend: + serviceName: group + servicePort: 9443 +--- +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: occasions-ingress + annotations: + ingress.kubernetes.io/rewrite-target: /occasions + ingress.kubernetes.io/secure-backends: "true" +spec: + rules: + - http: + paths: + - path: /service/occasions + backend: + serviceName: occasion + servicePort: 9443 \ No newline at end of file diff --git a/microservice-auth/Dockerfile b/microservice-auth/Dockerfile new file mode 100644 index 0000000..0eb1f33 --- /dev/null +++ b/microservice-auth/Dockerfile @@ -0,0 +1,2 @@ +FROM openliberty/open-liberty +COPY target/liberty/wlp/usr/servers/authServer /config diff --git a/microservice-group/Dockerfile b/microservice-group/Dockerfile new file mode 100644 index 0000000..c5e3e68 --- /dev/null +++ b/microservice-group/Dockerfile @@ -0,0 +1,4 @@ +FROM openliberty/open-liberty +COPY target/liberty/wlp/usr/servers/groupServer /config +COPY target/liberty/wlp/usr/shared /opt/ol/wlp/usr/shared +RUN sed -i -e 's/httpEndpoint/httpEndpoint host="*"/g' /config/server.xml diff --git a/microservice-notification/Dockerfile b/microservice-notification/Dockerfile new file mode 100644 index 0000000..394ee1a --- /dev/null +++ b/microservice-notification/Dockerfile @@ -0,0 +1,2 @@ +FROM openliberty/open-liberty +COPY target/liberty/wlp/usr/servers/notificationServer /config diff --git a/microservice-notification/pom.xml b/microservice-notification/pom.xml index 37a2754..66a75f9 100644 --- a/microservice-notification/pom.xml +++ b/microservice-notification/pom.xml @@ -21,7 +21,7 @@ notificationMicroservice notificationServer - ${project.build.directory}/logs/notifications.log + /logs/notifications.log diff --git a/microservice-notification_v1_1/Dockerfile b/microservice-notification_v1_1/Dockerfile new file mode 100644 index 0000000..394ee1a --- /dev/null +++ b/microservice-notification_v1_1/Dockerfile @@ -0,0 +1,2 @@ +FROM openliberty/open-liberty +COPY target/liberty/wlp/usr/servers/notificationServer /config diff --git a/microservice-occasion/Dockerfile b/microservice-occasion/Dockerfile new file mode 100644 index 0000000..a12eecc --- /dev/null +++ b/microservice-occasion/Dockerfile @@ -0,0 +1,4 @@ +FROM openliberty/open-liberty +COPY target/wlp/usr/servers/OccasionsServer /config +COPY target/wlp/usr/shared /opt/op/wlp/usr/shared +RUN sed -i -e 's/httpEndpoint/httpEndpoint host="*"/g' /config/server.xml \ No newline at end of file diff --git a/microservice-user/Dockerfile b/microservice-user/Dockerfile new file mode 100644 index 0000000..9d192b6 --- /dev/null +++ b/microservice-user/Dockerfile @@ -0,0 +1,3 @@ +FROM openliberty/open-liberty +COPY target/liberty/wlp/usr/servers/userServer /config +COPY target/liberty/wlp/usr/shared /opt/op/wlp/usr/shared diff --git a/shared-keystore/pom.xml b/shared-keystore/pom.xml index d18cb9d..4a38b35 100644 --- a/shared-keystore/pom.xml +++ b/shared-keystore/pom.xml @@ -68,7 +68,7 @@ 2048 SHA256withRSA default - cn=localhost, ou=userServer, O=IBM, C=us + cn=*.default.svc.cluster.local, ou=userServer, O=IBM, C=us 999 true