-
-
Notifications
You must be signed in to change notification settings - Fork 675
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Kubernetes resources for demo-app namespace, api-node servi…
…ce, api-golang service, client-react-nginx service, and strip-api-prefixes middleware - Added Namespace.yaml for demo-app namespace - Added Service.yaml for api-node service - Added Service.yaml for api-golang service - Added Service.yaml for client-react-nginx service - Added Middleware.yaml for strip-api-prefixes middleware
- Loading branch information
1 parent
526ff75
commit 24fdbf1
Showing
21 changed files
with
527 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
docs/kubernetes/demo-apps/go-node-react-postgres/Namespace.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
apiVersion: v1 | ||
kind: Namespace | ||
metadata: | ||
name: demo-app |
165 changes: 165 additions & 0 deletions
165
docs/kubernetes/demo-apps/go-node-react-postgres/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
## Multi Service App | ||
|
||
This is a simple multi-service app that consists of a React Client, a Node API, and a Golang API. The app uses a Postgresql database for data storage. | ||
|
||
### Prerequisites | ||
|
||
- Kubernetes Cluster | ||
- Helm v3 | ||
- kubectl | ||
|
||
## Layout | ||
|
||
The following shows the layout of this directory: | ||
|
||
```markdown | ||
├── api-golang | ||
│ ├── Deployment.yaml | ||
│ ├── IngressRoute.yaml | ||
│ ├── Secret.yml | ||
│ └── Service.yaml | ||
├── api-node | ||
│ ├── Deployment.yaml | ||
│ ├── IngressRoute.yaml | ||
│ ├── Secret.yaml | ||
│ └── Service.yaml | ||
├── client-react | ||
│ ├── ConfigMap.yaml | ||
│ ├── Deployment.yaml | ||
│ ├── IngressRoute.yaml | ||
│ └── Service.yaml | ||
├── common | ||
│ ├── Middleware.yaml | ||
│ ├── Namespace.yaml | ||
└── postgresql | ||
├── Job.db-migrator.yaml | ||
└── Secret.db-password.yaml | ||
``` | ||
|
||
### Setting up the APP | ||
|
||
Make sure you are in `go-node-react-postgres` directory. | ||
|
||
1. Create a Namespace | ||
|
||
```bash | ||
kubectl apply -f Namespace.yaml | ||
``` | ||
|
||
switch to the namespace: | ||
|
||
```bash | ||
kubectl config set-context --current --namespace=demo-app | ||
``` | ||
|
||
2. Install Postgresql Database using Helm | ||
|
||
Add the bitnami repo: | ||
|
||
```bash | ||
helm repo add bitnami https://charts.bitnami.com/bitnami | ||
``` | ||
|
||
Install the chart: | ||
|
||
```bash | ||
helm upgrade --install \ | ||
-n postgres \ | ||
postgres bitnami/postgresql \ | ||
--set auth.postgresPassword=foobarbaz \ | ||
--version 15.3.2 \ | ||
--values ./postgresql/values.yaml \ | ||
--create-namespace | ||
``` | ||
|
||
3. Database Migration | ||
|
||
First we need to create a secret for the database password: | ||
|
||
```bash | ||
kubectl apply -f postgresql/Secret.db-password.yaml | ||
``` | ||
|
||
Then we can run the migration job: | ||
|
||
```bash | ||
kubectl apply -f postgresql/Job.db-migrator.yaml | ||
``` | ||
|
||
5. Install traffic Ingress Controller | ||
|
||
Add the traefik repo: | ||
|
||
```bash | ||
helm repo add traefik https://traefik.github.io/charts | ||
``` | ||
|
||
Install the chart: | ||
|
||
```bash | ||
helm upgrade --install \ | ||
-n traefik \ | ||
traefik traefik/traefik \ | ||
--version 20.8.0 \ | ||
--create-namespace | ||
``` | ||
|
||
6. Deploy a Middleware to Strop of the prefix from incoming requests | ||
|
||
```bash | ||
kubectl apply -f common/Middleware.yaml | ||
``` | ||
|
||
7. Deploy the Golang API. | ||
|
||
Before deploying, update the `IngressRoute.yaml` file to match the correct host. | ||
|
||
```yaml | ||
routes: | ||
- kind: Rule | ||
match: Host(`host/domain`) && PathPrefix(`/api/golang`) | ||
``` | ||
Then deploy the API: | ||
```bash | ||
kubectl apply -f api-golang | ||
``` | ||
|
||
8. Deploy the Node API. | ||
|
||
Before deploying, update the `IngressRoute.yaml` file to match the correct host. | ||
|
||
```yaml | ||
routes: | ||
- kind: Rule | ||
match: Host(`host/domain`) && PathPrefix(`/api/node`) | ||
``` | ||
Then deploy the API: | ||
```bash | ||
kubectl apply -f api-node | ||
``` | ||
|
||
9. Deploy the React Client. | ||
|
||
Before deploying, update the `IngressRoute.yaml` file to match the correct host. | ||
|
||
```yaml | ||
routes: | ||
- kind: Rule | ||
match: Host(`host/domain`) # This will root with no prefix | ||
``` | ||
Then deploy the client: | ||
```bash | ||
kubectl apply -f client-react | ||
``` | ||
|
||
Now you should be able to access the app using the host/domain you have set in the IngressRoute files. | ||
|
||
- For Node API, you can access it using `<host>/api/node`. | ||
- For Golang API, you can access it using `<host>/api/golang`. | ||
- For React Client, you can access it using `<host>`. |
45 changes: 45 additions & 0 deletions
45
docs/kubernetes/demo-apps/go-node-react-postgres/api-golang/Deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: api-golang | ||
namespace: demo-app | ||
labels: | ||
app: api-golang | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: api-golang | ||
template: | ||
metadata: | ||
labels: | ||
app: api-golang | ||
spec: | ||
containers: | ||
- name: api-golang | ||
image: sidpalas/devops-directive-docker-course-api-golang:foobarbaz | ||
env: | ||
- name: PORT | ||
value: "8000" | ||
envFrom: | ||
- secretRef: | ||
name: api-golang-database-url | ||
ports: | ||
- containerPort: 8000 | ||
protocol: TCP | ||
readinessProbe: | ||
httpGet: | ||
path: /ping | ||
port: 8000 | ||
resources: | ||
limits: | ||
memory: "100Mi" | ||
requests: | ||
memory: "100Mi" | ||
cpu: "50m" | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
privileged: false | ||
securityContext: | ||
seccompProfile: | ||
type: RuntimeDefault |
18 changes: 18 additions & 0 deletions
18
docs/kubernetes/demo-apps/go-node-react-postgres/api-golang/IngressRoute.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: traefik.containo.us/v1alpha1 | ||
kind: IngressRoute | ||
metadata: | ||
name: api-golang | ||
namespace: demo-app | ||
spec: | ||
entryPoints: | ||
- web | ||
routes: | ||
- kind: Rule | ||
match: Host(`d11ae95f-7695-4635-9637-13829bf55c83.lb.civo.com`) && PathPrefix(`/api/golang`) | ||
middlewares: | ||
- name: strip-api-prefixes | ||
services: | ||
- kind: Service | ||
name: api-golang | ||
port: 8000 | ||
scheme: http |
9 changes: 9 additions & 0 deletions
9
docs/kubernetes/demo-apps/go-node-react-postgres/api-golang/Secret.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ⛔️ DONT PUT SECRET FILES IN VCS | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: api-golang-database-url | ||
namespace: demo-app | ||
stringData: | ||
DATABASE_URL: postgres://postgres:[email protected]:5432/postgres |
12 changes: 12 additions & 0 deletions
12
docs/kubernetes/demo-apps/go-node-react-postgres/api-golang/Service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: api-golang | ||
namespace: demo-app | ||
spec: | ||
selector: | ||
app: api-golang | ||
ports: | ||
- protocol: TCP | ||
port: 8000 | ||
targetPort: 8000 |
45 changes: 45 additions & 0 deletions
45
docs/kubernetes/demo-apps/go-node-react-postgres/api-node/Deployment.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: api-node | ||
namespace: demo-app | ||
labels: | ||
app: api-node | ||
spec: | ||
replicas: 1 | ||
selector: | ||
matchLabels: | ||
app: api-node | ||
template: | ||
metadata: | ||
labels: | ||
app: api-node | ||
spec: | ||
containers: | ||
- name: api-node | ||
image: sidpalas/devops-directive-docker-course-api-node:foobarbaz | ||
env: | ||
- name: PORT | ||
value: "3000" | ||
envFrom: | ||
- secretRef: | ||
name: api-node-database-url | ||
ports: | ||
- containerPort: 3000 | ||
protocol: TCP | ||
readinessProbe: | ||
httpGet: | ||
path: /ping | ||
port: 3000 | ||
resources: | ||
limits: | ||
memory: "100Mi" | ||
requests: | ||
memory: "100Mi" | ||
cpu: "50m" | ||
securityContext: | ||
allowPrivilegeEscalation: false | ||
privileged: false | ||
securityContext: | ||
seccompProfile: | ||
type: RuntimeDefault |
18 changes: 18 additions & 0 deletions
18
docs/kubernetes/demo-apps/go-node-react-postgres/api-node/IngressRoute.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
apiVersion: traefik.containo.us/v1alpha1 | ||
kind: IngressRoute | ||
metadata: | ||
name: api-node | ||
namespace: demo-app | ||
spec: | ||
entryPoints: | ||
- web | ||
routes: | ||
- kind: Rule | ||
match: Host(`d11ae95f-7695-4635-9637-13829bf55c83.lb.civo.com`) && PathPrefix(`/api/node`) | ||
middlewares: | ||
- name: strip-api-prefixes | ||
services: | ||
- kind: Service | ||
name: api-node | ||
port: 3000 | ||
scheme: http |
9 changes: 9 additions & 0 deletions
9
docs/kubernetes/demo-apps/go-node-react-postgres/api-node/Secret.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# ⛔️ DONT PUT SECRET FILES IN VCS | ||
apiVersion: v1 | ||
kind: Secret | ||
type: Opaque | ||
metadata: | ||
name: api-node-database-url | ||
namespace: demo-app | ||
stringData: | ||
DATABASE_URL: postgres://postgres:[email protected]:5432/postgres |
12 changes: 12 additions & 0 deletions
12
docs/kubernetes/demo-apps/go-node-react-postgres/api-node/Service.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: api-node | ||
namespace: demo-app | ||
spec: | ||
selector: | ||
app: api-node | ||
ports: | ||
- protocol: TCP | ||
port: 3000 | ||
targetPort: 3000 |
Oops, something went wrong.