-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kubernetes and Docker files for Server and Client (#231)
* Added Docker and Kubernetes support for running Portals Server and Client.
- Loading branch information
Showing
5 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: test-deployment | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: portals | ||
template: | ||
metadata: | ||
labels: | ||
app: portals | ||
spec: | ||
containers: | ||
- name: portals-server | ||
image: "test-server" | ||
imagePullPolicy: Never | ||
ports: | ||
- containerPort: 8080 | ||
|
||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: test-service | ||
spec: | ||
type: NodePort | ||
selector: | ||
app: portals | ||
ports: | ||
- protocol: TCP | ||
port: 8080 | ||
targetPort: 8080 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Portals | ||
|
||
## Build the Docker Container | ||
The Dockerfile | ||
To build the Docker container for the server, use the following command (replace `test-server` with a more meaningful container tag): | ||
|
||
`docker build -f scripts/deployment/docker/Dockerfile-Server . -t test-server` | ||
|
||
To run the container: | ||
|
||
`docker run -dp 127.0.0.1:8080:8080 test-server` | ||
|
||
## Kubernetes | ||
|
||
If you want to run the server on a kubernetes cluster (e.g. a local minikube setup) | ||
|
||
0. Make sure your cluster/minikube setup is running | ||
|
||
`minikube start` | ||
|
||
1. Deploy the container into the Kubernetes environment (Replace <image-name> with the actual image name you have chosen): | ||
|
||
`kubectl apply -f scripts/deployment/Kubernetes/Deployment.yaml` | ||
|
||
2. Wait for a bit and check if the pods have started | ||
|
||
`kubectl get pods` | ||
|
||
|
||
## Known Issues : | ||
- If the status of the pod is `ImagePullBackOff`, and you are using Minikube, ensure that Minikube can use the built container. Some Minikube setups require you to push the built Docker image to Minikube with the following command: | ||
`minikube image load <image name>` | ||
|
||
|
||
- For WSL/Minikube users, connecting to the pod can be a little tricky. The easiest workaround is to use port forwarding: | ||
`kubectl port-forward <pod-name> 8080:8080` To force k8s to forward the port from the pod to localhost | ||
|
||
|
||
# Full Example | ||
|
||
Before deploying the Server and the Client into the Kubernetes environment, make sure you have started Minikube and built the Docker images for the Client and Server: | ||
|
||
``` | ||
minikube start | ||
docker build -f scripts/deployment/docker/Dockerfile-ShoppingCartClient . -t test-client | ||
docker build -f scripts/deployment/docker/Dockerfile-Server . -t test-server | ||
``` | ||
|
||
1. Deploy the Server into the Kubernetes environment (Adjust the image name in the `deployment.yaml` file): | ||
|
||
`kubectl apply -f scripts/deployment/Kubernetes/Deployment.yaml` | ||
|
||
2. Once the Server has started, you can run the ShoppingCartClient: | ||
|
||
`docker run --network host test-client` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
FROM sbtscala/scala-sbt:openjdk-oraclelinux8-11.0.16_1.8.1_3.2.1 | ||
|
||
# Copy Necessary Files | ||
COPY ./portals-distributed/ /app/portals-distributed | ||
COPY ./portals-core/ /app/portals-core | ||
COPY ./project/ /app/project | ||
COPY ./build.sbt /app/build.sbt | ||
# Necessary because of imports in portals-distributed/examples | ||
COPY ./portals-examples/ /app/portals-examples | ||
|
||
|
||
WORKDIR /app | ||
RUN sbt compile | ||
|
||
ENTRYPOINT sbt "distributed/runMain portals.distributed.ClientCLI submitDir \ | ||
--directory portals-distributed/target/scala-3.3.0/classes" && \ | ||
sbt "distributed/runMain portals.distributed.ClientCLI launch \ | ||
--application portals.distributed.examples.HelloWorld$" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM sbtscala/scala-sbt:openjdk-oraclelinux8-11.0.16_1.8.1_3.2.1 | ||
|
||
# Copy Necessary Files | ||
COPY ./portals-distributed/ /app/portals-distributed | ||
COPY ./portals-core/ /app/portals-core | ||
COPY ./project/ /app/project | ||
COPY ./build.sbt /app/build.sbt | ||
# Necessary because of imports in portals-distributed/examples | ||
COPY ./portals-examples/ /app/portals-examples | ||
|
||
|
||
WORKDIR /app | ||
RUN sbt compile | ||
EXPOSE 8080 | ||
ENTRYPOINT sbt "distributed/runMain portals.distributed.SBTRunServer" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM sbtscala/scala-sbt:openjdk-oraclelinux8-11.0.16_1.8.1_3.2.1 | ||
|
||
# Copy Necessary Files | ||
COPY ./portals-distributed/ /app/portals-distributed | ||
COPY ./portals-core/ /app/portals-core | ||
COPY ./project/ /app/project | ||
COPY ./build.sbt /app/build.sbt | ||
# Necessary because of imports in portals-distributed/examples | ||
COPY ./portals-examples/ /app/portals-examples | ||
|
||
|
||
WORKDIR /app | ||
RUN sbt compile | ||
|
||
ENTRYPOINT sbt "distributed/runMain portals.distributed.ClientCLI submitDir \ | ||
--directory portals-distributed/target/scala-3.3.0/classes" && \ | ||
sbt "distributed/runMain portals.distributed.ClientCLI launch \ | ||
--application portals.distributed.examples.shoppingcart.Inventory$ " && \ | ||
sbt "distributed/runMain portals.distributed.ClientCLI launch \ | ||
--application portals.distributed.examples.shoppingcart.Cart$ " && \ | ||
sbt "distributed/runMain portals.distributed.ClientCLI launch \ | ||
--application portals.distributed.examples.shoppingcart.Orders$ " && \ | ||
sbt "distributed/runMain portals.distributed.ClientCLI launch \ | ||
--application portals.distributed.examples.shoppingcart.Analytics$ " | ||
|