Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
aishwarydhare committed Nov 11, 2018
0 parents commit 45f883c
Show file tree
Hide file tree
Showing 15 changed files with 223 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
node_modules
npm-debug.log
Dockerfile*
docker-compose*
.dockerignore
.git
.gitignore
.env
*/bin
*/obj
README.md
LICENSE
.vscode
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
temp
k8s-archive
dump.rdb
package-lock.json
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
sudo: required
services:
- docker
before_install:
- openssl aes-256-cbc -K $encrypted_0c35eebf403c_key -iv $encrypted_0c35eebf403c_key
- curl https://sdk.cloud.google.com | bash > /dev/null;
- source $HOME/google-cloud-sdk/path.bash.inc
- gcloud components update kubectl
- gcloud auth activate-service-account --key-file service-accounts.json
- gcloud config set project skilful-berm-214882
- gcloud container clusters get-credentials multi-cluster
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM node:6.14.2
COPY package.json .
RUN npm install
COPY keys.js .
COPY server.js .
CMD node server.js
EXPOSE 8086
3 changes: 3 additions & 0 deletions Dockerfile.redis
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM redis:alpine
EXPOSE 6379
CMD ["redis-server"]
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'
services:
nodeapp:
build:
context: .
dockerfile: Dockerfile
ports:
- "8082:8082"
redisdb:
build:
context: .
dockerfile: Dockerfile.redis
restart: always
ports:
- 6379:6379
33 changes: 33 additions & 0 deletions k8s/aws-nginx-ingress-layer7.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
kind: Service
apiVersion: v1
metadata:
name: ingress-nginx
namespace: ingress-nginx
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
annotations:
# replace with the correct value of the generated certificate in the AWS console
service.beta.kubernetes.io/aws-load-balancer-ssl-cert: "arn:aws:acm:us-west-2:XXXXXXXX:certificate/XXXXXX-XXXXXXX-XXXXXXX-XXXXXXXX"
# the backend instances are HTTP
service.beta.kubernetes.io/aws-load-balancer-backend-protocol: "http"
# Map port 443
service.beta.kubernetes.io/aws-load-balancer-ssl-ports: "https"
# Ensure the ELB idle timeout is less than nginx keep-alive timeout. By default,
# NGINX keep-alive is set to 75s. If using WebSockets, the value will need to be
# increased to '3600' to avoid any potential issues.
service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout: "60"
spec:
type: LoadBalancer
selector:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
ports:
- name: http
port: 80
targetPort: http
- name: https
port: 443
targetPort: http

---
15 changes: 15 additions & 0 deletions k8s/local-ingress-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ingress-service
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: node-server-clusterip-service
servicePort: 8086
12 changes: 12 additions & 0 deletions k8s/node-server-cluseterip-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
kind: Service
apiVersion: v1
metadata:
name: node-server-clusterip-service
spec:
type: ClusterIP
selector:
component: node-server
ports:
- port: 8086
targetPort: 8086

23 changes: 23 additions & 0 deletions k8s/node-server-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: node-server-deployment
spec:
selector:
matchLabels:
component: node-server
template:
metadata:
labels:
component: node-server
spec:
containers:
- name: node-server-deployment
image: aishwarydhare/hellonode:4
ports:
- containerPort: 8086
env:
- name: REDIS_HOST
value: redis-clusterip-service
- name: REDIS_PORT
value: '6379'
10 changes: 10 additions & 0 deletions k8s/redis-server-clusterip-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
kind: Service
apiVersion: v1
metadata:
name: redis-clusterip-service
spec:
selector:
component: redis-server
ports:
- port: 6379
targetPort: 6379
18 changes: 18 additions & 0 deletions k8s/redis-server-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-server-deployment
spec:
selector:
matchLabels:
component: redis-server
template:
metadata:
labels:
component: redis-server
spec:
containers:
- name: redis-server-deployment
image: aishwarydhare/helloredis
ports:
- containerPort: 6379
4 changes: 4 additions & 0 deletions keys.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
redisHost: process.env.REDIS_HOST,
redisPort: process.env.REDIS_PORT
}
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "hellonode",
"version": "0.1.0",
"private": true,
"dependencies": {
"redis": "~2.8.0"
},
"scripts": {
"start": "node server.js"
}
}
42 changes: 42 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const http = require('http');
const keys = require('./keys');
const redis = require('redis');
// const client = redis.createClient(); // this creates a new client
const client = redis.createClient(
keys.redisPort,
keys.redisHost
);

isRedisConnected = false;

var handleRequest = function(request, response) {
console.log('Received request for URL: ' + request.url);
response.writeHead(200);

client.get('mkey', function (error, result) {
if (error) {
console.log(error);
throw error;
isRedisConnected = false;
}
console.log('REDIS GET result ->' + result);
});

var str = "REDIS IS ALSO CONNECTED."
if(!isRedisConnected){
str = "REDIS NOT CONNECTED.";
}
response.end('Hello World! This is Node running on Kubernetes.\n\n' + str);
};
var www = http.createServer(handleRequest);
www.listen(8086);

client.on('connect', function() {
console.log('Redis client connected');
isRedisConnected = true;
client.set('mkey', 'my_test_value', redis.print);
});

client.on('error', function (err) {
console.log('Something went wrong ' + err);
});

0 comments on commit 45f883c

Please sign in to comment.