Skip to content

Commit 04d581d

Browse files
committed
Added more on liveness probe
Signed-off-by: knrt10 <[email protected]>
1 parent e00b3cf commit 04d581d

File tree

7 files changed

+269
-181
lines changed

7 files changed

+269
-181
lines changed

1.docker/readme.md

-173
This file was deleted.

app.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const http = require('http');
22
const os = require('os');
33
console.log("Kubia server starting...");
4-
var handler = function (request, response) {
4+
let handler = function (request, response) {
55
console.log("Received request from " + request.connection.remoteAddress);
66
response.writeHead(200);
77
response.end("You've hit " + os.hostname() + "\n");
88
};
9-
var www = http.createServer(handler);
9+
let www = http.createServer(handler);
1010
www.listen(8080);

kubia-liveness-probe.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: pod
3+
metadata:
4+
name: kubia-liveness
5+
spec:
6+
containers:
7+
- image: knrt10/kubia-unhealthy
8+
name: kubia
9+
livenessProbe:
10+
httpGet:
11+
path: /
12+
port: 8080

kubia-unhealthy/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM node:8
2+
3+
ADD app.js /app.js
4+
5+
ENTRYPOINT [ "node", "app.js" ]

kubia-unhealthy/app.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const http = require('http');
2+
const os = require('os');
3+
4+
console.log("Kubia server starting...");
5+
6+
let requestCount = 0;
7+
8+
let handler = function(request, response) {
9+
console.log("Received request from " + request.connection.remoteAddress);
10+
requestCount++;
11+
if (requestCount > 5) {
12+
response.writeHead(500);
13+
response.end("I'm not well. Please restart me!");
14+
return;
15+
}
16+
response.writeHead(200);
17+
response.end("You've hit " + os.hostname() + "\n");
18+
};
19+
20+
let www = http.createServer(handler);
21+
www.listen(8080);

kubia-unhealthy/package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "kubernetes-basiclearning",
3+
"version": "1.0.0",
4+
"description": "Understand kubernetes step by step.",
5+
"main": "app.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"start": "node app.js"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "git+https://github.com/knrt10/kubernetes-basicLearning.git"
13+
},
14+
"author": "knrt10",
15+
"license": "MIT",
16+
"bugs": {
17+
"url": "https://github.com/knrt10/kubernetes-basicLearning/issues"
18+
},
19+
"homepage": "https://github.com/knrt10/kubernetes-basicLearning#readme"
20+
}

0 commit comments

Comments
 (0)