Skip to content

Commit

Permalink
Deploy webapp on local kubernetes clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
chuyangzh committed Aug 20, 2024
1 parent 8c1971d commit 4c5d962
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
27 changes: 27 additions & 0 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: webapp-photo2monet
spec:
replicas: 1
selector:
matchLabels:
app: webapp-photo2monet
template:
metadata:
labels:
app: webapp-photo2monet
spec:
containers:
- name: webapp
# image: zcycyrus/photo2monet-dockerhub:webapp_latest
image: zcycyrus/photo2monet-dockerhub:local-test
ports:
- containerPort: 5000
volumeMounts:
- name: model-volume
mountPath: /app/models # Directory in the container
volumes:
- name: model-volume
persistentVolumeClaim:
claimName: model-pvc
14 changes: 14 additions & 0 deletions k8s/pv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: model-pv
spec:
storageClassName: manual
capacity:
storage: 2Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "C:/Monet_Local/webapp"
# Ensure this is the correct path where your model file is stored on your machine
# translated from windows style C:\Monet_Local\webapp to linux
11 changes: 11 additions & 0 deletions k8s/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: model-pvc
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Gi
14 changes: 14 additions & 0 deletions scripts/deploy_webapp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

# Print a message
echo "Deploying the web application..."

# Apply the deployment configuration from the deployment.yaml file
kubectl apply -f ./k8s/deployment.yaml

# Restart the deployment to use the latest Docker image, if updated
echo "Restarting the deployment to ensure the latest image is used..."
kubectl rollout restart deployment/webapp-photo2monet

# Provide feedback that the deployment has been triggered
echo "Deployment has been updated. Check the status with 'kubectl get pods' to ensure pods are running."
4 changes: 3 additions & 1 deletion webapp/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ def forward(self, x):

def load_model(model_path=None):
if model_path is None:
model_path = os.path.join(os.path.dirname(__file__), 'models/serving_model_v0.pth')
# model_path = os.path.join(os.path.dirname(__file__), 'models/serving_model_v0.pth')
# Update the default model path to match the mountPath in Kubernetes
model_path = '/app/models/serving_model_v0.pth'
device = 'cuda' if torch.cuda.is_available() else 'cpu'

G_Photo2Monet = Generator(img_channels=3).to(device)
Expand Down

0 comments on commit 4c5d962

Please sign in to comment.