Skip to content

Commit 6e9ac0e

Browse files
authored
Merge pull request #21 from paulbouwer/release-1.10
Release 1.10
2 parents ec7bf64 + 2db42b1 commit 6e9ac0e

35 files changed

+741
-903
lines changed

.devcontainer/Dockerfile

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
44
#-------------------------------------------------------------------------------------------------------------
55

6-
FROM node:13
6+
FROM node:15
77

88
# Avoid warnings by switching to noninteractive
99
ENV DEBIAN_FRONTEND=noninteractive
@@ -17,39 +17,60 @@ ARG USER_UID=1000
1717
ARG USER_GID=$USER_UID
1818

1919
# Configure apt and install packages
20-
RUN apt-get update \
21-
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
20+
RUN apt-get update && apt-get install -y --no-install-recommends \
21+
apt-utils \
22+
bash-completion \
23+
ca-certificates \
24+
curl \
25+
dialog \
26+
git \
27+
iproute2 \
28+
jq \
29+
procps \
30+
less \
31+
vim \
2232
#
23-
# Verify git and needed tools are installed
24-
&& apt-get -y install git iproute2 procps \
33+
# Install bash completion
34+
&& echo ". /etc/bash_completion" >> ~/.bashrc \
35+
&& mkdir -p ~/completions \
2536
#
26-
# Remove outdated yarn from /opt and install via package
27-
# so it can be easily updated via apt-get upgrade yarn
28-
&& rm -rf /opt/yarn-* \
29-
&& rm -f /usr/local/bin/yarn \
30-
&& rm -f /usr/local/bin/yarnpkg \
31-
&& apt-get install -y curl apt-transport-https lsb-release \
32-
&& curl -sS https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/pubkey.gpg | apt-key add - 2>/dev/null \
33-
&& echo "deb https://dl.yarnpkg.com/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
34-
&& apt-get update \
35-
&& apt-get -y install --no-install-recommends yarn \
36-
#
37-
# Install eslint globally
38-
&& npm install -g eslint \
37+
# Install node packages globally
38+
&& npm install -g eslint pino-pretty \
3939
#
40-
# [Optional] Update a non-root user to UID/GID if needed.
41-
&& if [ "$USER_GID" != "1000" ] || [ "$USER_UID" != "1000" ]; then \
42-
groupmod --gid $USER_GID $USERNAME \
43-
&& usermod --uid $USER_UID --gid $USER_GID $USERNAME \
44-
&& chown -R $USER_UID:$USER_GID /home/$USERNAME; \
45-
fi \
46-
# [Optional] Add add sudo support for non-root user
40+
# Add add sudo support for non-root user
4741
&& apt-get install -y sudo \
4842
&& echo node ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
49-
&& chmod 0440 /etc/sudoers.d/$USERNAME \
50-
#
51-
# Clean up
52-
&& apt-get autoremove -y \
43+
&& chmod 0440 /etc/sudoers.d/$USERNAME
44+
45+
# Install Docker CE CLI
46+
RUN apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common lsb-release \
47+
&& curl -fsSL https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]')/gpg | (OUT=$(apt-key add - 2>&1) || echo $OUT) \
48+
&& add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/$(lsb_release -is | tr '[:upper:]' '[:lower:]') $(lsb_release -cs) stable" \
49+
&& apt-get update \
50+
&& apt-get install -y docker-ce-cli \
51+
&& curl -L https://raw.githubusercontent.com/docker/docker-ce/master/components/cli/contrib/completion/bash/docker -o ~/completions/docker.bash \
52+
&& echo "source ~/completions/docker.bash" >> ~/.bashrc
53+
54+
# Install Helm
55+
RUN mkdir /tmp/helm \
56+
&& curl -L https://get.helm.sh/helm-$(curl -s https://api.github.com/repos/helm/helm/releases/latest | jq -r .tag_name)-linux-amd64.tar.gz | tar xz -C /tmp/helm --strip-components 1 \
57+
&& mv /tmp/helm/helm /usr/local/bin/ \
58+
&& chmod +x /usr/local/bin/helm \
59+
&& rm -fr /tmp/helm \
60+
&& helm completion bash > ~/completions/helm.bash \
61+
&& echo "source ~/completions/helm.bash" >> ~/.bashrc
62+
63+
# Install kubectl
64+
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" \
65+
&& chmod +x ./kubectl \
66+
&& mv ./kubectl /usr/local/bin/kubectl \
67+
&& kubectl completion bash > ~/completions/kubectl.bash \
68+
&& echo "source ~/completions/kubectl.bash" >> ~/.bashrc \
69+
&& echo "alias k=kubectl" >> ~/.bashrc \
70+
&& echo "complete -o default -F __start_kubectl k" >> ~/.bashrc
71+
72+
# Clean up
73+
RUN apt-get autoremove -y \
5374
&& apt-get clean -y \
5475
&& rm -rf /var/lib/apt/lists/*
5576

.devcontainer/devcontainer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or the definition README at
22
// https://github.com/microsoft/vscode-dev-containers/tree/master/containers/javascript-node-12
33
{
4-
"name": "Node.js 13",
4+
"name": "Development environment - hello-kubernetes",
55
"dockerFile": "Dockerfile",
6+
"mounts": [
7+
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind",
8+
"source=${env:HOME}${env:USERPROFILE}/.kube,target=/root/.kube,type=bind"
9+
],
610

711
// Use 'settings' to set *default* container specific settings.json values on container create.
812
// You can edit these settings after create using File > Preferences > Settings > Remote.

.dockerignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# Dependency directories
2-
node_modules/
1+
# Dependency directories and files
2+
node_modules/
3+
package-lock.json

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
REGISTRY ?= docker.io
2+
REPOSITORY ?= paulbouwer
3+
IMAGE_VERSION ?= $(shell cat src/app/package.json | jq -r .version)
4+
IMAGE_MAJOR_VERSION = $(shell echo "$(IMAGE_VERSION)" | cut -d '.' -f1 )
5+
IMAGE_MINOR_VERSION = $(shell echo "$(IMAGE_VERSION)" | cut -d '.' -f2 )
6+
IMAGE = $(REGISTRY)/$(REPOSITORY)/hello-kubernetes
7+
8+
.PHONY: build-image-linux
9+
build-image-linux:
10+
docker build --no-cache \
11+
--build-arg IMAGE_VERSION="$(IMAGE_VERSION)" \
12+
--build-arg IMAGE_CREATE_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" \
13+
--build-arg IMAGE_SOURCE_REVISION="`git rev-parse HEAD`" \
14+
-f src/app/Dockerfile -t "$(IMAGE):$(IMAGE_VERSION)" src/app;
15+
16+
.PHONY: push-image
17+
push-image:
18+
docker tag $(IMAGE):$(IMAGE_VERSION) $(IMAGE):$(IMAGE_MAJOR_VERSION); \
19+
docker tag $(IMAGE):$(IMAGE_VERSION) $(IMAGE):$(IMAGE_MAJOR_VERSION).$(IMAGE_MINOR_VERSION); \
20+
docker push $(IMAGE):$(IMAGE_VERSION); \
21+
docker push $(IMAGE):$(IMAGE_MAJOR_VERSION); \
22+
docker push $(IMAGE):$(IMAGE_MAJOR_VERSION).$(IMAGE_MINOR_VERSION)

README.md

Lines changed: 39 additions & 164 deletions
Original file line numberDiff line numberDiff line change
@@ -2,195 +2,70 @@
22

33
[![Docker Image Version (latest by date)](https://img.shields.io/docker/v/paulbouwer/hello-kubernetes)](https://hub.docker.com/repository/docker/paulbouwer/hello-kubernetes) [![Docker Image Size (latest by date)](https://img.shields.io/docker/image-size/paulbouwer/hello-kubernetes)](https://hub.docker.com/repository/docker/paulbouwer/hello-kubernetes) [![Docker Pulls](https://img.shields.io/docker/pulls/paulbouwer/hello-kubernetes)](https://hub.docker.com/repository/docker/paulbouwer/hello-kubernetes)
44

5-
This container image can be deployed on a Kubernetes cluster. When accessed via a web browser on port `8080`, it will display:
5+
This container image can be deployed on a Kubernetes cluster. It runs a web app, that displays the following:
66

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

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

13-
The default "Hello world!" message displayed can be overridden using the `MESSAGE` environment variable. The default port of 8080 can be overriden using the `PORT` environment variable.
14-
15-
## Deploy
16-
17-
### Standard Configuration
18-
19-
Deploy to your Kubernetes cluster using the hello-kubernetes.yaml, which contains definitions for the service and deployment objects:
20-
21-
```yaml
22-
# hello-kubernetes.yaml
23-
apiVersion: v1
24-
kind: Service
25-
metadata:
26-
name: hello-kubernetes
27-
spec:
28-
type: LoadBalancer
29-
ports:
30-
- port: 80
31-
targetPort: 8080
32-
selector:
33-
app: hello-kubernetes
34-
---
35-
apiVersion: apps/v1
36-
kind: Deployment
37-
metadata:
38-
name: hello-kubernetes
39-
spec:
40-
replicas: 3
41-
selector:
42-
matchLabels:
43-
app: hello-kubernetes
44-
template:
45-
metadata:
46-
labels:
47-
app: hello-kubernetes
48-
spec:
49-
containers:
50-
- name: hello-kubernetes
51-
image: paulbouwer/hello-kubernetes:1.9
52-
ports:
53-
- containerPort: 8080
54-
```
13+
## Quick start
14+
15+
You can deploy `hello-kubernetes` to your Kubernetes cluster using [Helm 3](https://helm.sh/docs/intro/install/). The Helm chart installation and configuration options can be found in the [Deploy using Helm](docs/deploy-using-helm.md) guide.
16+
17+
When running through the following examples, ensure that you are in the chart directory in the repo, since you are referencing a local helm chart.
5518

5619
```bash
57-
$ kubectl apply -f yaml/hello-kubernetes.yaml
20+
cd deploy/helm
5821
```
5922

60-
This will display a **Hello world!** message when you hit the service endpoint in a browser. You can get the service endpoint ip address by executing the following command and grabbing the returned external ip address value:
23+
### Example 1: Default
24+
25+
Deploy the `hello-kubernetes` app into the `hello-kubernetes` namespace with the default "Hello world!" message. The app is exposed via a public Load Balancer on port 80 by default - note that a LoadBalancer service typically only works in cloud provider based Kubernetes offerings.
6126

6227
```bash
63-
$ kubectl get service hello-kubernetes
64-
```
28+
helm install --create-namespace --namespace hello-kubernetes hello-world ./hello-kubernetes
6529

66-
### Customise Message
67-
68-
You can customise the message displayed by the `hello-kubernetes` container. Deploy using the hello-kubernetes.custom-message.yaml, which contains definitions for the service and deployment objects.
69-
70-
In the definition for the deployment, add an `env` variable with the name of `MESSAGE`. The value you provide will be displayed as the custom message.
71-
72-
```yaml
73-
# hello-kubernetes.custom-message.yaml
74-
apiVersion: v1
75-
kind: Service
76-
metadata:
77-
name: hello-kubernetes-custom
78-
spec:
79-
type: LoadBalancer
80-
ports:
81-
- port: 80
82-
targetPort: 8080
83-
selector:
84-
app: hello-kubernetes-custom
85-
---
86-
apiVersion: apps/v1
87-
kind: Deployment
88-
metadata:
89-
name: hello-kubernetes-custom
90-
spec:
91-
replicas: 3
92-
selector:
93-
matchLabels:
94-
app: hello-kubernetes-custom
95-
template:
96-
metadata:
97-
labels:
98-
app: hello-kubernetes-custom
99-
spec:
100-
containers:
101-
- name: hello-kubernetes
102-
image: paulbouwer/hello-kubernetes:1.9
103-
ports:
104-
- containerPort: 8080
105-
env:
106-
- name: MESSAGE
107-
value: I just deployed this on Kubernetes!
30+
# get the LoadBalancer ip address.
31+
kubectl get svc hello-kubernetes-hello-world -n hello-kubernetes -o 'jsonpath={ .status.loadBalancer.ingress[0].ip }'
10832
```
10933

34+
### Example 2: Custom message
35+
36+
Deploy the `hello-kubernetes` app into the `hello-kubernetes` namespace with an "I just deployed this on Kubernetes!" message. The app is exposed via a public Load Balancer on port 80 by default - note that a LoadBalancer service typically only works in cloud provider based Kubernetes offerings.
37+
11038
```bash
111-
$ kubectl apply -f yaml/hello-kubernetes.custom-message.yaml
112-
```
39+
helm install --create-namespace --namespace hello-kubernetes custom-message ./hello-kubernetes \
40+
--set message="I just deployed this on Kubernetes!"
11341

114-
### Specify Custom Port
115-
116-
By default, the `hello-kubernetes` app listens on port `8080`. If you have a requirement for the app to listen on another port, you can specify the port via an env variable with the name of PORT. Remember to also update the `containers.ports.containerPort` value to match.
117-
118-
Here is an example:
119-
120-
```yaml
121-
apiVersion: apps/v1
122-
kind: Deployment
123-
metadata:
124-
name: hello-kubernetes-custom
125-
spec:
126-
replicas: 3
127-
selector:
128-
matchLabels:
129-
app: hello-kubernetes-custom
130-
template:
131-
metadata:
132-
labels:
133-
app: hello-kubernetes-custom
134-
spec:
135-
containers:
136-
- name: hello-kubernetes
137-
image: paulbouwer/hello-kubernetes:1.9
138-
ports:
139-
- containerPort: 80
140-
env:
141-
- name: PORT
142-
value: "80"
42+
# get the LoadBalancer ip address.
43+
kubectl get svc hello-kubernetes-custom-message -n hello-kubernetes -o 'jsonpath={ .status.loadBalancer.ingress[0].ip }'
14344
```
14445

145-
## Cutomize URL context path
146-
147-
If you have an ingress that routes to a custom context path then you can customize the URL context path. The css files and the images will be loaded properly in that case.
148-
149-
```yaml
150-
apiVersion: apps/v1
151-
kind: Deployment
152-
metadata:
153-
name: hello-kubernetes-custom
154-
spec:
155-
replicas: 3
156-
selector:
157-
matchLabels:
158-
app: hello-kubernetes-custom
159-
template:
160-
metadata:
161-
labels:
162-
app: hello-kubernetes-custom
163-
spec:
164-
containers:
165-
- name: hello-kubernetes
166-
image: paulbouwer/hello-kubernetes:1.9
167-
ports:
168-
- containerPort: 8080
169-
env:
170-
- name: MESSAGE
171-
value: I just deployed this on Kubernetes!
172-
- name: CONTEXT_PATH
173-
value: "/api/v1/hello-kubernetes/"
174-
```
46+
### Example 3: Ingress
17547

176-
## Build Container Image
48+
Deploy the `hello-kubernetes` app into the `hello-kubernetes` namespace. This example assumes that an ingress has been deployed and configured in the cluster, and that the ingress has a path of `/app/hello-kubernetes/` mapped to the `hello-kubernetes` service.
17749

178-
If you'd like to build the image yourself, then you can do so as follows. The `build-arg` parameters provides metadata as defined in [OCI image spec annotations](https://github.com/opencontainers/image-spec/blob/master/annotations.md).
50+
The `hello-kubernetes` app can be reached on the ip address of the ingress via the `/app/hello-kubernetes/` path.
17951

180-
Bash
18152
```bash
182-
$ docker build --no-cache --build-arg IMAGE_VERSION="1.9" --build-arg IMAGE_CREATE_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" --build-arg IMAGE_SOURCE_REVISION="`git rev-parse HEAD`" -f Dockerfile -t "hello-kubernetes:1.9" app
53+
helm install --create-namespace --namespace hello-kubernetes ingress ./hello-kubernetes \
54+
--set ingress.configured=true \
55+
--set ingress.pathPrefix="/app/hello-kubernetes/" \
56+
--set service.type="ClusterIP"
18357
```
18458

185-
Powershell
186-
```powershell
187-
PS> docker build --no-cache --build-arg IMAGE_VERSION="1.9" --build-arg IMAGE_CREATE_DATE="$(Get-Date((Get-Date).ToUniversalTime()) -UFormat '%Y-%m-%dT%H:%M:%SZ')" --build-arg IMAGE_SOURCE_REVISION="$(git rev-parse HEAD)" -f Dockerfile -t "hello-kubernetes:1.9" app
188-
```
59+
## Documentation
60+
61+
### Deploying
62+
63+
If you'd like to explore the various Helm chart configuration options, then read the [Deploy with Helm](docs/deploy-using-helm.md) documentation. You can also discover more about the ingress configuration options in the [Deploy with ingress](docs/deploy-with-ingress.md) documentation
18964

190-
## Develop Application
65+
### Building your own images
19166

192-
If you have [VS Code](https://code.visualstudio.com/) and the [Visual Studio Code Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed, the `.devcontainer` folder will be used to build a container based node.js 13 development environment.
67+
If you'd like to build the `hello-kubernetes` container image yourself and reference from your own registry or DockerHub repository, then you can get more details on how to do this in the [Build and push container images](docs/build-and-push-container-images.md) documentation.
19368

194-
Port `8080` has been configured to be forwarded to your host. If you run `npm start` in the `app` folder in the VS Code Remote Containers terminal, you will be able to access the website on `http://localhost:8080`. You can change the port in the `.devcontainer\devcontainer.json` file under the `appPort` key.
69+
### Development environment
19570

196-
See [here](https://code.visualstudio.com/docs/remote/containers) for more details on working with this setup.
71+
If you have [VS Code](https://code.visualstudio.com/) and the [VS Code Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed, the `.devcontainer` folder will be used to provide a container based development environment. You can read more about how to use this in the [Development environments](docs/development-environment.md) documentation.

0 commit comments

Comments
 (0)