Skip to content
This repository was archived by the owner on Jul 9, 2022. It is now read-only.

Kubernetes

Omri Bornstein edited this page Dec 13, 2020 · 17 revisions

scr-web Deployment & Service

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: scr-web
  name: scr-web-deployment
spec:
  selector:
    matchLabels:
      app: scr-web-pod
  replicas: 1
  template:
    metadata:
      labels:
        app: scr-web-pod
    spec:
      containers:
        - name: scr-web
          volumeMounts:
            - mountPath: /scr/users
              name: scr-web-data
            - mountPath: /scr/storage
              name: scr-web-storage
          image: applegamer22/scr-web:<version>
          env:
            - name: JWT_SECRET
              value: <some_private_key>
            - name: DATABASE_URL
              value: mongodb://<database_service_name>:27017/<some_database>
          ports:
            - containerPort: 4100
      volumes:
        - name: scr-web-data
          hostPath:
            path: <some_local_directory>
        - name: scr-web-storage
          hostPath:
            path: <some_local_directory>
---
apiVersion: v1
kind: Service
metadata:
  name: scr-web-service
spec:
  type: NodePort
  selector:
    app: scr-web-pod
  ports:
  - port: 4100
    targetPort: 4100
    nodePort: 31000
    name: scr-web
  • For applegamer22/scr-web:
    • A JWT_SECRET environment variable
    • A DATABASE_URL for the MongoDB URL of the docker-compose environment (mongodb://database-service:27017/scr for example mentioned above)
    • A host port routed to container port 4100
    • A host directory for users' Chrome data volumed to container directory /scr/users
    • A host directory for users' file storage volumed to container directory /scr/storage

Database Deployment & Service

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: database-pod
  name: database-deployment
spec:
  selector:
    matchLabels:
      app: database-pod
  replicas: 1
  template:
    metadata:
      labels:
        app: database-pod
    spec:
      containers:
        - name: database
          volumeMounts:
            - mountPath: /data/db
              name: database-data
          image: mongo:<version>
          ports:
            - containerPort: 27017
      volumes:
        - name: database-data
          hostPath:
            path: <database_directory>
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: database-service
spec:
  selector:
    app: database-pod
  ports:
  - port: 27017
    targetPort: 27017
    name: database
  • For MongoDB:
    • A host port routed to container port 27017
    • A host directory volumed to container directory /data/db

minikube set-up

  1. Run sudo chown -R 999:999 <database_directory> to make sure MongoDB (user 999) has the permissions to access your <database_directory>.
  2. Run minikube start --mount --mount-string="/home:/hosthome" in order to mount the host's /home to Docker's /hosthome.
    • As a result, if the host's <database_directory> and <some_local_directory> reside at /home/user/Documents, Docker's <database_directory> and <some_local_directory> will reside at /hosthome/user/Documents.