diff --git a/k8s/ReadMe.md b/k8s/ReadMe.md deleted file mode 100644 index f2ded81..0000000 --- a/k8s/ReadMe.md +++ /dev/null @@ -1,63 +0,0 @@ -# Deployment for NodeJs App on Kubernetes - - -## Local Development - -### Allowing Connecting to Redis using - -By default a local Redis only allow to be connected through localhost. - -Edit Redis conf to allow connection through local IP. - -Here is a [link](https://www.digitalocean.com/community/questions/enable-remote-redis-connection) to how to do it. - - -### Configure your Kubernetes - -Use minikube for local kubernetes engine - - $ minikube start - $ eval $(minikube docker-env) - -Configure your local kubernetes secrets - - $ make configure-local - - -This sets up the following Redis configuration, make sure your Redis is set up like this - -db id: **0** - -password: **123456789** - -port: **6379** - -host: **{Your local IP address}** - - -### Building the app - - $ make build - -### Deploying to local Kubernetes - - $ make install - -### Running the application - - $ make run - -This will run the application in the browser. Copy the url into postman for API testing - - -### Resetting the the environement - - $ make clean - -This deletes all the pods and all the secrets - - -## Running on Google Kubernetes Engine - -**TO BE ADDED** - diff --git a/k8s/application.yml b/k8s/application.yml deleted file mode 100644 index c46f07d..0000000 --- a/k8s/application.yml +++ /dev/null @@ -1,65 +0,0 @@ ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: nodejs-kubernetes - labels: - app: nodejs-kubernetes -spec: - replicas: 1 - selector: - matchLabels: - app: nodejs-kubernetes - template: - metadata: - labels: - app: nodejs-kubernetes - spec: - containers: - - name: nodejs-kubernetes - image: nodejs-kubernetes:1.0 - imagePullPolicy: IfNotPresent - ports: - - name: http - containerPort: 3000 - resources: - limits: - cpu: 1 - memory: "200Mi" - env: - - name: REDIS_PASSWORD - valueFrom: - secretKeyRef: - name: redis-pass - key: password - - name: MYSQL_DB_ID - valueFrom: - secretKeyRef: - name: redis-db-id - key: db_id - - name: REDIS_HOST - valueFrom: - secretKeyRef: - name: redis-host - key: host - - name: REDIS_PORT - valueFrom: - secretKeyRef: - name: redis-host - key: port ---- -apiVersion: v1 -kind: Service -metadata: - name: nodejs-service - labels: - app: nodejs-service -spec: - type: LoadBalancer - selector: - app: nodejs-kubernetes - ports: - - name: http - port: 3000 - targetPort: 3000 - protocol: TCP \ No newline at end of file diff --git a/k8s/configmap/development.yml b/k8s/configmap/development.yml new file mode 100644 index 0000000..2d2784b --- /dev/null +++ b/k8s/configmap/development.yml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: road-review-configmap + namespace: road-review-namespace +data: + NODE_ENV: development diff --git a/k8s/deployment.yml b/k8s/deployment.yml new file mode 100644 index 0000000..1f92ed3 --- /dev/null +++ b/k8s/deployment.yml @@ -0,0 +1,93 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: road-review-deployment + namespace: road-review-namespace + labels: + app: road-review-backend +spec: + replicas: 1 + selector: + matchLabels: + app: road-review-backend + template: + metadata: + labels: + app: road-review-backend + spec: + containers: + - name: road-review-backend + image: road-review-backend:$VERSION_NUM + imagePullPolicy: IfNotPresent + ports: + - name: http + containerPort: 3000 + resources: + limits: + cpu: 1 + memory: "1Gi" + requests: + cpu: 0.5 + memory: "500Mi" + envFrom: + - configMapRef: + name: road-review-configmap + env: + - name: REDIS_PASSWORD + valueFrom: + secretKeyRef: + name: redis-pass + key: password + - name: REDIS_HOST + valueFrom: + secretKeyRef: + name: redis-host + key: host + - name: REDIS_PORT + valueFrom: + secretKeyRef: + name: redis-host + key: port + - name: REDIS_DB_ID + valueFrom: + secretKeyRef: + name: redis-host + key: db-id + - name: DB_USER + valueFrom: + secretKeyRef: + name: mysql + key: mysql-user-name + - name: DB_HOST + valueFrom: + secretKeyRef: + name: mysql + key: mysql-host + - name: DB_PASSWORD + valueFrom: + secretKeyRef: + name: mysql + key: mysql-password + - name: DB_NAME + valueFrom: + secretKeyRef: + name: mysql + key: mysql-db-name + restartPolicy: Always +--- +apiVersion: v1 +kind: Service +metadata: + name: road-review-backend + labels: + app: road-review-backend +spec: + type: NodePort + selector: + app: road-review-backend + ports: + - name: http + port: 3000 + targetPort: 3000 + protocol: TCP diff --git a/k8s/ingress/ingress.yml b/k8s/ingress/ingress.yml new file mode 100644 index 0000000..a36b547 --- /dev/null +++ b/k8s/ingress/ingress.yml @@ -0,0 +1,13 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: road-review-ingress + annotations: + kubernetes.io/ingress.global-static-ip-name: "road-review-static-ip" + kubernetes.io/ingress.allow-http: "false +spec: + backend: + serviceName: road-review-backend + servicePort: 3000 +tls: + - secretName: road-review-tls-cert