Skip to content

Commit fb3f891

Browse files
author
AlexRogalskiy
committed
Added info on workflows
Updates on github-actions
1 parent 325214b commit fb3f891

25 files changed

Lines changed: 1007 additions & 29 deletions

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ node_modules
1212
flow-typed
1313
coverage
1414
dist
15+
helm
1516
tilt_modules

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ ARG UID
1414
ARG GID
1515

1616
ARG NAME="java-patterns"
17-
ARG VERSION="0.0.0-dev"
17+
ARG VERSION="$(git describe --abbrev=0 --tag)"
1818
ARG PACKAGE="AlexRogalskiy/java-patterns"
1919
ARG DESCRIPTION="Java Design Patterns"
2020

2121
ARG LC_ALL="en_US.UTF-8"
22-
ARG BUILD_DATE="$(git rev-parse --short HEAD)"
23-
ARG VCS_REF="$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")"
22+
ARG BUILD_DATE="$(date -u +\"%Y-%m-%dT%H:%M:%SZ\")"
23+
ARG VCS_REF="$(git rev-parse --short HEAD)"
2424

2525
## Working directories
2626
ARG APP_DIR="/usr/src/app"
@@ -119,6 +119,7 @@ RUN pip3.8 install mkdocs-material --no-cache-dir --quiet
119119
RUN pip3.8 install pygments --no-cache-dir --quiet
120120
RUN pip3.8 install markdown --no-cache-dir --quiet
121121
RUN pip3.8 install markdown-include --no-cache-dir --quiet
122+
RUN pip3.8 install markdown-checklist --no-cache-dir --quiet
122123
RUN pip3.8 install fontawesome_markdown --no-cache-dir --quiet
123124
RUN pip3.8 install mkdocs-redirects --no-cache-dir --quiet
124125
RUN pip3.8 install mkdocs-material-extensions --no-cache-dir --quiet

build.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
startTimeSecs = 1628508136;
2-
startTimeNanos = 406841278;
1+
startTimeSecs = 1628533547;
2+
startTimeNanos = 510196924;

helm/.helmignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*.orig
18+
*~
19+
# Various IDEs
20+
.project
21+
.idea/
22+
*.tmproj
23+
.vscode/

helm/Chart.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v2
2+
version: 1.0.0
3+
appVersion: 1.0.0
4+
name: java-patterns
5+
description: A demo application for a Kubernetes cluster.
6+
home: https://alexander-rogalsky.gitbook.io/java-patterns
7+
type: application
8+
maintainers:
9+
- email: alexrogalskiy@users.noreply.github.com
10+
name: AlexRogalskiy
11+
sources:
12+
- https://github.com/AlexRogalskiy/java-patterns
13+
kubeVersion: '>=1.19.0-0'

helm/README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Hello Kubernetes!
2+
3+
This container image can be deployed on a Kubernetes cluster. It runs a web app, that displays the following:
4+
5+
- a default **Hello world!** message
6+
- namespace, pod, and node details
7+
- container image details
8+
9+
## Quick start
10+
11+
You can deploy `java-patterns` to your Kubernetes cluster using [Helm 3](https://helm.sh/docs/intro/install/). The Helm chart installation and configuration
12+
options can be found in the [Deploy using Helm](docs/deploy-using-helm.md) guide.
13+
14+
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.
15+
16+
```bash
17+
$ cd helm
18+
```
19+
20+
### Example 1: Default
21+
22+
Deploy the `java-patterns` app into the `webapp` namespace. The app is exposed via a public Load Balancer on port 80 by default - note that a LoadBalancer
23+
service typically only works in cloud provider based Kubernetes offerings.
24+
25+
```bash
26+
$ helm install --create-namespace --namespace webapp java-patterns .
27+
28+
# get the LoadBalancer ip address.
29+
$ kubectl get svc webapp-java-patterns -n webapp -o 'jsonpath={ .status.loadBalancer.ingress[0].ip }'
30+
```
31+
32+
### Example 2: Custom message
33+
34+
Deploy the `java-patterns` app into the `webapp` namespace with an "I just deployed this on Kubernetes!" message. The app is exposed via a public Load Balancer
35+
on port 80 by default - note that a LoadBalancer service typically only works in cloud provider based Kubernetes offerings.
36+
37+
```bash
38+
$ helm install --create-namespace --namespace webapp custom-java-patterns . --set message="I just deployed this on Kubernetes!"
39+
40+
# get the LoadBalancer ip address.
41+
$ kubectl get svc webapp-custom-java-patterns -n webapp -o 'jsonpath={ .status.loadBalancer.ingress[0].ip }'
42+
```
43+
44+
### Example 3: Ingress
45+
46+
Deploy the `java-patterns` app into the `webapp` namespace. This example assumes that an ingress has been deployed and configured in the cluster, and that the
47+
ingress has a path of `/app/java-patterns/` mapped to the `java-patterns` service.
48+
49+
The `java-patterns` app can be reached on the ip address of the ingress via the `/app/java-patterns/` path.
50+
51+
```bash
52+
$ helm install --create-namespace --namespace webapp ingress . \
53+
--set ingress.configured=true \
54+
--set ingress.pathPrefix="/app/java-patterns/" \
55+
--set service.type="ClusterIP"
56+
```
57+
58+
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example,
59+
60+
```bash
61+
$ helm install --create-namespace --namespace webapp java-patterns . -f values.yaml
62+
```
63+
64+
> **Tip**: You can use the default [values.yaml](values.yaml)
65+
66+
## Documentation
67+
68+
### Deploying
69+
70+
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
71+
discover more about the ingress configuration options in the [Deploy with ingress](docs/deploy-with-ingress.md) documentation
72+
73+
### Building your own images
74+
75+
If you'd like to build the `java-patterns` container image yourself and reference from your own registry or DockerHub repository, then you can get more details
76+
on how to do this in the [Build and push container images](docs/build-and-push-container-images.md) documentation.
77+
78+
### Development environment
79+
80+
If you have [VS Code](https://code.visualstudio.com/) and
81+
the [VS Code Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) extension installed, the `.devcontainer`
82+
folder will be used to provide a container based development environment. You can read more about how to use this in
83+
the [Development environments](docs/development-environment.md) documentation.
84+
85+
## Upgrading the chart
86+
87+
### To =< 5.0.0
88+
89+
Version 5.0.0 is a major update.
90+
91+
* The chart now follows the new Kubernetes label recommendations:
92+
<https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/>
93+
94+
The simplest way to update is to do a force upgrade, which recreates the resources by doing a delete and an install.

helm/deploy-using-helm.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Deploy using Helm
2+
3+
The `java-patterns` Helm chart can be used to deploy the `java-patterns` application. The chart will deploy the following resources:
4+
5+
- ServiceAccount
6+
- Service
7+
- Deployment
8+
9+
## Prerequisites
10+
11+
- [Helm 3](https://v3.helm.sh/)
12+
13+
If you are using the [VS Code Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) based development
14+
environment, all of the prerequisites will be available in the terminal.
15+
16+
## Configuration and installation
17+
18+
The following table lists the configuration parameters of the java-patterns chart, and their default values.
19+
20+
| Parameter | Type | Default | Description |
21+
| --------- | ---- | ------- | ----------- |
22+
| `message` | `string` | `""` | A custom message to display instead of the default. |
23+
| `ingress.configured` | `bool` | `false` | Indicates whether an ingress has been configured in the cluster. <br/>Note: this chart will not install or configure an ingress. You will need to install an ingress controller and add ingress record to the app namespace. |
24+
| `ingress.rewritePath` | `bool` | `true` | Indicates whether pathPrefix is rewritten by the ingress. <br/> If this is set to `true` then the java-patterns dynamic content and static assets will be served from `/`, otherwise, they will be served from `/$pathPrefix`. |
25+
| `ingress.pathPrefix` | `string` | `""` | The path prefix configured in the ingress for the java-patterns service.<br/> Must be provided when ingress is used. |
26+
| `service.type` | `string` | `"LoadBalancer"` | The service type. |
27+
| `service.port` | `int` | `80` | The port exposed by the service. |
28+
| `deployment.replicaCount` | `int` | `2` | The number of replicas for the java-patterns deployment. |
29+
| `deployment.container.image.repository` | `string` | `java-patterns` | The container image to run in the java-patterns pods. |
30+
| `deployment.container.image.tag` | `string` | `""` | The container image tag. If not specified, the chart's appVersion is used. |
31+
| `deployment.container.image.pullPolicy` | `string` | `"IfNotPresent"` | The pull policy for the container image. |
32+
| `deployment.container.port` | `int` | `"8080"` | The port that java-patterns app listens on. |
33+
| `deployment.nodeSelector` | `object` | `{"kubernetes.io/os":"linux", "kubernetes.io/arch":"amd64"}` | The node selector for the deployment. |
34+
| `deployment.resources` | `object` | `{}` | The resource limits for the deployment. |
35+
| `deployment.tolerations` | `object` | `[]` | The tolerations for the deployment. |
36+
| `deployment.affinity` | `object` | `{}` | The affinity for the deployment. |
37+
38+
### Installing the chart
39+
40+
Ensure that you are in the chart directory in the repo, since the instructions reference a local helm chart.
41+
42+
To install `java-patterns` via the Helm chart, use the following to:
43+
44+
- create the webapp namespace if it doesn't exist
45+
- deploy the chart located in the current folder into the webapp namespace
46+
- create a Helm release named java-patterns
47+
48+
```bash
49+
$ helm install --create-namespace --namespace webapp java-patterns .
50+
```
51+
52+
You can override the values for the configuration parameter defined in the table above, either directly in the `values.yaml` file, or via the `--set` switches.
53+
54+
```bash
55+
$ helm install --create-namespace --namespace webapp custom-message . --set message="I just deployed this on Kubernetes!"
56+
```
57+
58+
### Upgrading the chart
59+
60+
Ensure that you are in the chart directory in the repo, since the instructions reference a local helm chart.
61+
62+
You can modify the `java-patterns` app by providing new values for the configuration parameter defined in the table above, either directly in the `values.yaml`
63+
file, or via the `--set` switches.
64+
65+
```bash
66+
$ helm upgrade --namespace webapp custom-java-patterns . --set message="This is a different message"
67+
```
68+
69+
### Uninstalling the chart
70+
71+
You can uninstall the `java-patterns` app as follows:
72+
73+
```bash
74+
$ helm uninstall --namespace webapp custom-java-patterns
75+
```

helm/deploy-with-ingress.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Deploy with ingress
2+
3+
The `java-patterns` Helm chart can be used to deploy and configure the `java-patterns` application for use with an ingress controller.
4+
5+
> **Note:**
6+
>
7+
> The `java-patterns` Helm chart does **not** deploy an [Ingress Controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/) and does **not** deploy the [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) definition.
8+
>
9+
> The chart aims to support deployment to as many platforms and providers as possible, so the choice of Ingress Controller and configuration of Ingress resource is left to the person deploying.
10+
11+
## Prerequisites
12+
13+
- [Helm 3](https://v3.helm.sh/)
14+
15+
If you are using the [VS Code Remote Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers) based development
16+
environment, all of the prerequisites will be available in the terminal.
17+
18+
## Install ingress controller
19+
20+
Install an [Ingress Controller](https://kubernetes.io/docs/concepts/services-networking/ingress-controllers/) that is available for your platform or provider.
21+
Here is an example that uses the [Nginx Ingress Controller](https://kubernetes.github.io/ingress-nginx/deploy/) on a cloud provider:
22+
23+
```bash
24+
$ helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
25+
26+
$ helm install nginx-ingress ingress-nginx/ingress-nginx \
27+
--create-namespace --namespace ingress \
28+
--set controller.replicaCount=2
29+
```
30+
31+
## Use webapp with ingress
32+
33+
### Deploy webapp instances
34+
35+
Install two `java-patterns` instances that will be available via 2 different paths on the ingress.
36+
37+
The `java-patterns` instance will display the default "Hello world!" message, and the `custom-java-patterns` instance will display a "This is my custom
38+
message!" message.
39+
40+
```bash
41+
$ helm install --create-namespace --namespace webapp java-patterns . \
42+
--set ingress.configured=true --set ingress.pathPrefix=hello-world \
43+
--set service.type=ClusterIP
44+
45+
$ helm install --create-namespace --namespace webapp custom-java-patterns . \
46+
--set ingress.configured=true --set ingress.pathPrefix=custom-message \
47+
--set service.type=ClusterIP \
48+
--set message="This is my custom message!"
49+
```
50+
51+
### Deploy ingress definition
52+
53+
The `java-patterns` Helm chart has a `ingress.rewritePath` configuration parameter that is `true` by default. When used together with
54+
the `ingress.configured=true` configuration parameter, there is an assumption that the ingress being used supports path rewrites. See
55+
the [Deploy using Helm](deploy-using-helm.md) guidance for more details.
56+
57+
So from our example, a request to `/java-patterns` should be rewritten to `/` before being passed to the `java-patterns` app instance.
58+
59+
Create a file named `webapp-ingress.yaml` with the content below. This ingress definition will be serviced by the nginx ingress controller due to
60+
the `kubernetes.io/ingress.class: nginx` annotation. It will also leverage the path rewrite capabilities of nginx via
61+
the `nginx.ingress.kubernetes.io/rewrite-target: /$2` annotation.
62+
63+
```yaml
64+
# webapp-ingress.yaml
65+
apiVersion: networking.k8s.io/v1beta1
66+
kind: Ingress
67+
metadata:
68+
name: webapp-ingress
69+
annotations:
70+
kubernetes.io/ingress.class: nginx
71+
nginx.ingress.kubernetes.io/rewrite-target: /$2
72+
spec:
73+
rules:
74+
- http:
75+
paths:
76+
- backend:
77+
serviceName: webapp-java-patterns
78+
servicePort: 8000
79+
path: /hello-world(/|$)(.*)
80+
- backend:
81+
serviceName: webapp-custom-java-patterns
82+
servicePort: 8000
83+
path: /custom-message(/|$)(.*)
84+
```
85+
86+
Deploy the contents of the `webapp-ingress.yaml` into the same namespace as the two `java-patterns` apps.
87+
88+
```bash
89+
$ kubectl apply -n webapp -f webapp-ingress.yaml
90+
```
91+
92+
### Browse
93+
94+
You can browse to each of the `java-patterns` apps via the $INGRESS_CONTROLLER_IPADDRESS and each of the configured paths. So for our example at:
95+
96+
- `$INGRESS_CONTROLLER_IPADDRESS/hello-world` - the `java-patterns` instance with the default "Hello world!" message
97+
- `$INGRESS_CONTROLLER_IPADDRESS/custom-java-patterns` - the `custom-java-patterns` instance with the "This is my custom message!" message
98+
99+
## Alternatives
100+
101+
You can deploy the `java-patterns` app via the Helm chart with the `ingress.rewritePath=false` configuration parameter if you are deploying with an ingress
102+
controller that does not support path rewrites.
103+
104+
In this case, the `java-patterns` apps will serve dynamic content and static assets from the path defined by the `ingress.pathPrefix` configuration parameter.

0 commit comments

Comments
 (0)