Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
This container image can be deployed on a Kubernetes cluster. It runs a web app, that displays the following:

- a default **Hello world!** message
- the pod name
- node os information
- namespace, pod, and node details
- container image details

![Hello world! from the hello-kubernetes image](hello-kubernetes.png)

Expand Down
14 changes: 14 additions & 0 deletions deploy/helm/hello-kubernetes/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,20 @@ spec:
- name: RENDER_PATH_PREFIX
value: "{{ .Values.ingress.pathPrefix }}"
{{- end }}
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: KUBERNETES_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: KUBERNETES_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: CONTAINER_IMAGE
value: "{{ .Values.deployment.container.image.repository }}:{{ .Values.deployment.container.image.tag | default .Chart.AppVersion }}"
{{- with .Values.deployment.resources }}
resources:
{{- toYaml . | nindent 12 }}
Expand Down
Binary file modified hello-kubernetes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions src/app/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Hello Kubernetes demo app

A demo app that can be deployd to a Kubernetes cluster. It displays a message, the name of the pod and details of the node it's deployed to.
A demo app that can be deployd to a Kubernetes cluster. It displays a message, and also namespace, pod, node and image details.

## Paths

Expand All @@ -17,5 +17,15 @@ The application can be configured via the following environment variables.
| PORT | No | 8080 | The port that the app listens on. |
| MESSAGE | No | "Hello world!" | The message displayed by the app. |
| RENDER_PATH_PREFIX | No | "" | The path prefix to use when rendering the urls for the static assets in the handlebar templates. <br/> Must be used when app is deployed with an ingress using a backend path for traffic to app. |
| HANDLER_PATH_PREFIX | No | "" | The path prefix to use by handlers when serving the static asset and services. <br/> Note: Must be used when app is deployed with an ingress that has a backend path for traffic to the app, but which does not rewrite the backend paths to '/'. |
| HANDLER_PATH_PREFIX | No | "" | The path prefix to use by handlers when serving the dynamic and static assets. <br/> Note: Must be used when app is deployed with an ingress that has a backend path for traffic to the app, but which does not rewrite the backend paths to '/'. |
| KUBERNETES_NAMESPACE | Yes | "-" | The Kubernetes namespace that the app has been deployed to. |
| KUBERNETES_POD_NAME | Yes | hostname | The name of the Kubernetes pod that the app is deployed into. |
| KUBERNETES_NODE_NAME | Yes | "-" | The name of the Kubernetes node that the app is deployed on. |
| CONTAINER_IMAGE | Yes | "paulbouwer/hello-kubernetes:$(cat package.json \| jq -r .version)" | The name and tag of the container image running the app. |

The application relies on the following files for configuration and operational information.

| File | Required | Information | Description |
| ---- | -------- | ----------- | ----------- |
| package.json | Yes | `.version` | The release version is used when the CONTAINER_IMAGE env is not provided. |
| info.json | Yes | `.containerImageArch` | The container image architecture is used for display. This file will be overwritten in future versions as part of the container image build process when multi-arch images are supported. |
3 changes: 3 additions & 0 deletions src/app/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"containerImageArch": "linux/amd64"
}
22 changes: 18 additions & 4 deletions src/app/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require('express');
const exphbs = require('express-handlebars');
const os = require("os");
const fs = require('fs');

const pino = require('pino');
const expressPino = require('express-pino-logger');
Expand All @@ -27,13 +28,25 @@ var handlerPathPrefix = (
''
);

var namespace = process.env.KUBERNETES_NAMESPACE || '-';
var podName = process.env.KUBERNETES_POD_NAME || os.hostname();
var nodeName = process.env.KUBERNETES_NODE_NAME || '-';
var nodeOS = os.type() + ' ' + os.release();
var applicationVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version;
var containerImage = process.env.CONTAINER_IMAGE || 'paulbouwer/hello-kubernetes:' + applicationVersion
var containerImageArch = JSON.parse(fs.readFileSync('info.json', 'utf8')).containerImageArch;

logger.debug();
logger.debug('Configuration');
logger.debug('-----------------------------------------------------');
logger.debug('PORT=' + process.env.PORT);
logger.debug('MESSAGE=' + process.env.MESSAGE);
logger.debug('RENDER_PATH_PREFIX=' + process.env.RENDER_PATH_PREFIX);
logger.debug('HANDLER_PATH_PREFIX=' + process.env.HANDLER_PATH_PREFIX);
logger.debug('KUBERNETES_NAMESPACE=' + process.env.KUBERNETES_NAMESPACE);
logger.debug('KUBERNETES_POD_NAME=' + process.env.KUBERNETES_POD_NAME);
logger.debug('KUBERNETES_NODE_NAME=' + process.env.KUBERNETES_NODE_NAME);
logger.debug('CONTAINER_IMAGE=' + process.env.CONTAINER_IMAGE);

// Handlers

Expand All @@ -50,9 +63,10 @@ logger.debug('Serving from base path "' + handlerPathPrefix + '"');
app.get(handlerPathPrefix + '/', function (req, res) {
res.render('home', {
message: message,
platform: os.type(),
release: os.release(),
hostName: os.hostname(),
namespace: namespace,
pod: podName,
node: nodeName + ' (' + nodeOS + ')',
container: containerImage + ' (' + containerImageArch + ')',
renderPathPrefix: renderPathPrefix
});
});
Expand All @@ -64,5 +78,5 @@ logger.debug('Server');
logger.debug('-----------------------------------------------------');

app.listen(port, function () {
logger.info("Listening on: http://%s:%s", os.hostname(), port);
logger.info("Listening on: http://%s:%s", podName, port);
});
11 changes: 11 additions & 0 deletions src/app/static/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ div.main img {
div.content {
color:#f2f2f2;
}

.content #message {
margin: 10px 0 50px 0;
padding: 30px 0;
Expand All @@ -26,6 +27,16 @@ div.content {
border-bottom: 2px solid #909090;
}

.content #footer {
margin: 50px 0;
padding: 30px 0;
font-family: 'Ubuntu', sans-serif;
font-weight: 300;
font-size: 12pt;
color: #909090;
border-top: 2px solid #909090;
}

.content #info {
margin: 0 auto;
font-family: 'Ubuntu', sans-serif;
Expand Down
12 changes: 9 additions & 3 deletions src/app/views/home.handlebars
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
</div>
<div id="info">
<table>
<tr>
<th>namespace:</th>
<td>{{ namespace }}</td>
</tr>
<tr>
<th>pod:</th>
<td>{{ hostName }}</td>
<td>{{ pod }}</td>
</tr>
<tr>
<th>node:</th>
<td>{{ platform }} ({{ release }})</td>
<td>{{ node }}</td>
</tr>
</table>

</div>
<div id="footer">
{{ container }}
</div>