Skip to content

Commit 79d24bc

Browse files
authored
Create new and improved seed and test overlays (canada-ca#1182)
For sidecar injection to happen Istio needs to be running before our app is. To make this happen, this commit splits the config into a seed config that creates namespaces, secrets and installs Istio, and then an normal overlay that installs the app. Also included here is an overlay called test, that is very close to prod, but uses a self signed cert. The process to bring up a cluster (using test as an example) is now the following: ```sh kustomize build overlays/seed/test | kubectl apply -f - watch kubectl get po -A kustomize build overlays/test | kubectl apply -f - watch kubectl get po -A kubectl get svc -n istio-system istio-ingressgateway -o json | jq '.status.loadBalancer.ingress' ```
1 parent 7aad091 commit 79d24bc

32 files changed

Lines changed: 2170 additions & 186 deletions

platform/README.md

Lines changed: 97 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,102 @@ The purpose of this directory is to hold the manifest files for kubernetes deplo
44

55
Before applying these please check out the README.md in each overlay to understand the individual configurations.
66

7-
Assuming you have `kubectl` set to the proper context you can then run:
87

9-
`kustomize build overlays/minikube | kubectl apply -f -`
10-
or
11-
`kustomize build overlays/minikube | kubectl delete -f -`
8+
## Getting started
129

13-
to provision or tear down a cluster.
10+
In accordance with the [12Factor app](https://12factor.net) philosophy, all the services [draws their config from the environment](https://12factor.net/config).
11+
To generate the config needed to run a copy of the app, we need to define some `.env` files, that will be used to create Kubernetes secrets, whose values are available to the various parts of the app.
12+
13+
First, the secret for the result-queue to insert scan results into to the database.
14+
15+
```
16+
cat <<'EOF' > platform/overlays/seed/minikube/scanners.env
17+
DB_HOST=postgres
18+
DB_USER=track_dmarc
19+
DB_PASS=test
20+
DB_NAME=track_dmarc
21+
SA_USER_NAME=superuser@department.gc.ca
22+
SA_PASSWORD=superadminpassword
23+
SA_DISPLAY_NAME=superuser
24+
EOF
25+
```
26+
Next some default credentials so we can log in to the Kiali observability tool.
27+
28+
```
29+
cat <<'EOF' > platform/overlays/seed/minikube/kiali.env
30+
username=admin
31+
passphrase=admin
32+
EOF
33+
```
34+
Then a password for our database.
35+
36+
```
37+
cat <<'EOF' > platform/overlays/seed/minikube/postgres.env
38+
POSTGRES_USER=track_dmarc
39+
POSTGRES_PASSWORD=test
40+
EOF
41+
```
42+
43+
And finally the credentials needed for the API to talk to the database, and collaborative services like Notify.
44+
45+
```bash
46+
cat <<'EOF' > platform/overlays/seed/minikube/api.env
47+
DB_USER=track_dmarc
48+
DB_PASS=test
49+
DB_HOST=postgres
50+
DB_PORT=5432
51+
DB_NAME=track_dmarc
52+
BASE32_SECRET=alongstring
53+
SUPER_SECRET_KEY=alonghash
54+
SUPER_SECRET_SALT=alonghash
55+
NOTIFICATION_API_KEY=test_key-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
56+
NOTIFICATION_API_URL=https://api.notification.alpha.canada.ca
57+
SA_USER_NAME=superuser@department.gc.ca
58+
SA_PASSWORD=superadminpassword
59+
SA_DISPLAY_NAME=superuser
60+
TOKEN_KEY=test_jwt_token
61+
DMARC_REPORT_API_URL=https://dmarc-report-api-brpuw6ogca-nn.a.run.app
62+
DMARC_REPORT_API_TOKEN=a.jwt.token
63+
EOF
64+
```
65+
66+
Next we can start minikube (throwing lots of resources at it).
67+
68+
```
69+
minikube start --cpus 4 --memory 20480
70+
```
71+
72+
Last we use Kustomize to generate our config (creating Kubernetes secrets from the .env files we just created) and feed that config to `kubectl apply`.
73+
74+
There are two steps here, first the config in `platform/overlays/seed/minikube` creates namespaces and secrets appropriate for minikube and installs istio.
75+
76+
```
77+
kustomize build platform/overlays/seed/minikube | kubectl apply -f -
78+
```
79+
80+
Watch the results with `watch kubectl get pods -n istio-system`. Once Istio is running (and ready to inject it's sidecar proxies), the config for our app can be applied.
81+
82+
```
83+
kustomize build platform/overlays/minikube | kubectl apply -f -
84+
```
85+
86+
Depending on the speed of your system you might need to run the kustomize/apply commands more than once.
87+
88+
### Seeing the result:
89+
90+
The app lets you connect to both ports 80 and 443 (which is using a self signed certificate).
91+
92+
```bash
93+
$ minikube service list
94+
|-----------------|---------------------------|--------------|---------------------------|
95+
| NAMESPACE | NAME | TARGET PORT | URL |
96+
|-----------------|---------------------------|--------------|---------------------------|
97+
| api | postgres | No node port |
98+
| api | tracker-api | No node port |
99+
| cert-manager | cert-manager | No node port |
100+
| cert-manager | cert-manager-webhook | No node port |
101+
| default | kubernetes | No node port |
102+
| frontend | tracker-frontend | No node port |
103+
| istio-system | istio-ingressgateway | http2/80 | http://192.168.49.2:32722 |
104+
| | | https/443 | http://192.168.49.2:32114 |
105+
```

platform/bases/kustomization.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ resources:
3535
- tracker-frontend-deployment.yaml
3636
- tracker-frontend-service.yaml
3737
- tracker-frontend-virtual-service.yaml
38-
- istio.yaml
3938
- envoy-filter.yaml
4039
- publicgateway.yaml
4140
- postgres-deployment.yaml
@@ -45,8 +44,3 @@ resources:
4544
- cert-manager.yaml
4645
- cluster-admin-rolebinding.yaml
4746
- http-01-challenge-destination-rule.yaml
48-
- api-namespace.yaml
49-
- frontend-namespace.yaml
50-
- istio-system-namespace.yaml
51-
- knative-serving-namespace.yaml
52-
- scanners-namespace.yaml

platform/overlays/istio/bases/kustomization.yaml

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

platform/overlays/istio/helloworld-deployment.yaml

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

platform/overlays/istio/helloworld-service.yaml

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

platform/overlays/istio/helloworld-virtual-service.yaml

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

platform/overlays/istio/publicgateway.yaml

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

platform/overlays/minikube/kustomization.yaml

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,3 @@ resources:
55
- knative-istio-networking.yaml
66
- knative-serving-core.yaml
77
- selfsigned-issuer.yaml
8-
secretGenerator:
9-
- envs:
10-
- postgres.env
11-
name: postgres
12-
namespace: api
13-
- envs:
14-
- api.env
15-
name: api
16-
namespace: api
17-
- envs:
18-
- kiali.env
19-
name: kiali
20-
namespace: istio-system
21-
- envs:
22-
- scanners.env
23-
name: scanners
24-
namespace: scanners
25-
generatorOptions:
26-
disableNameSuffixHash: true
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)