-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aishwarydhare
committed
Nov 11, 2018
0 parents
commit 45f883c
Showing
15 changed files
with
223 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,13 @@ | ||
node_modules | ||
npm-debug.log | ||
Dockerfile* | ||
docker-compose* | ||
.dockerignore | ||
.git | ||
.gitignore | ||
.env | ||
*/bin | ||
*/obj | ||
README.md | ||
LICENSE | ||
.vscode |
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,5 @@ | ||
node_modules | ||
temp | ||
k8s-archive | ||
dump.rdb | ||
package-lock.json |
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,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 |
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,7 @@ | ||
FROM node:6.14.2 | ||
COPY package.json . | ||
RUN npm install | ||
COPY keys.js . | ||
COPY server.js . | ||
CMD node server.js | ||
EXPOSE 8086 |
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,3 @@ | ||
FROM redis:alpine | ||
EXPOSE 6379 | ||
CMD ["redis-server"] |
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,15 @@ | ||
version: '3' | ||
services: | ||
nodeapp: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
ports: | ||
- "8082:8082" | ||
redisdb: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile.redis | ||
restart: always | ||
ports: | ||
- 6379:6379 |
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,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 | ||
|
||
--- |
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,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 |
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,12 @@ | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: node-server-clusterip-service | ||
spec: | ||
type: ClusterIP | ||
selector: | ||
component: node-server | ||
ports: | ||
- port: 8086 | ||
targetPort: 8086 | ||
|
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,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' |
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,10 @@ | ||
kind: Service | ||
apiVersion: v1 | ||
metadata: | ||
name: redis-clusterip-service | ||
spec: | ||
selector: | ||
component: redis-server | ||
ports: | ||
- port: 6379 | ||
targetPort: 6379 |
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 @@ | ||
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 |
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,4 @@ | ||
module.exports = { | ||
redisHost: process.env.REDIS_HOST, | ||
redisPort: process.env.REDIS_PORT | ||
} |
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,11 @@ | ||
{ | ||
"name": "hellonode", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"redis": "~2.8.0" | ||
}, | ||
"scripts": { | ||
"start": "node server.js" | ||
} | ||
} |
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,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); | ||
}); |