Skip to content

Commit 9eaac1b

Browse files
author
Nik Mohamad Aizuddin b. Nik Azmi
committed
feat(example): Add kong-podman example
1 parent c6e743b commit 9eaac1b

10 files changed

Lines changed: 1573 additions & 0 deletions

File tree

kong-podman/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM docker.io/node:14.16.1
2+
MAINTAINER extra2000 <https://github.com/extra2000>
3+
4+
COPY ./project /srv/project
5+
WORKDIR /srv/project
6+
RUN npm install
7+
ENTRYPOINT npm run webservice

kong-podman/README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Sample apps: Kong Podman
2+
3+
4+
## Deploy Postgres
5+
6+
```
7+
$ podman play kube --network=sampleapps postgres-pod.yaml
8+
```
9+
10+
Bootstrap Kong database for the first time:
11+
```
12+
$ podman run --rm --pod postgres-pod --volume="./kong.conf:/etc/kong/kong.conf:ro,z" -e "KONG_PG_HOST=localhost" docker.io/library/kong:2.3.0 kong migrations bootstrap
13+
```
14+
15+
Test to make sure postgres works (use password `abcde12345`):
16+
```
17+
$ podman run -it --rm --network=sampleapps docker.io/postgres:13.1-alpine psql --host=postgres-pod.sampleapps --username=kong --dbname=kongdb
18+
```
19+
20+
21+
## Deploy Kong
22+
23+
Start Kong:
24+
```
25+
$ podman play kube --network=sampleapps kong-pod.yaml
26+
```
27+
28+
Test Kong and make sure no error, for example:
29+
```
30+
$ podman run -it --rm --network=sampleapps docker.io/curlimages/curl curl http://kong-pod.sampleapps:8001
31+
```
32+
33+
34+
## Running NodeJS webservice
35+
36+
```
37+
$ podman build -t extra2000/webservice:latest .
38+
$ podman play kube --network=sampleapps webservice-pod.yaml
39+
```
40+
41+
Test make sure the NodeJS webservice is working and accessible by `kong`:
42+
```
43+
$ podman run -it --rm --pod=webservice-pod docker.io/curlimages/curl curl http://localhost:8000/api/v1/customers
44+
$ podman run -it --rm --pod=kong-pod docker.io/curlimages/curl curl http://webservice-pod.sampleapps:8000/api/v1/customers
45+
```
46+
47+
Register NodeJS webservice into Kong and setup routing:
48+
```
49+
$ podman run -it --rm --pod=kong-pod docker.io/curlimages/curl curl -i -X POST --url http://localhost:8001/services/ --data 'name=webservice' --data 'url=http://webservice-pod.sampleapps:8000'
50+
$ podman run -it --rm --pod=kong-pod docker.io/curlimages/curl curl -i -X POST --url http://localhost:8001/services/webservice/routes --data 'name=webservice-route' --data 'paths[]=/myweb'
51+
```
52+
53+
To test:
54+
```
55+
$ podman run -it --rm --network=sampleapps docker.io/curlimages/curl curl -i -X GET http://kong-pod.sampleapps:8000/myweb/api/v1/customers
56+
$ curl -i -X GET http://localhost:8000/myweb/api/v1/customers
57+
```
58+
59+
To list services and routes:
60+
```
61+
$ podman run -it --rm --pod=kong-pod docker.io/curlimages/curl curl -i http://localhost:8001/services
62+
$ podman run -it --rm --pod=kong-pod docker.io/curlimages/curl curl -i http://localhost:8001/routes
63+
```
64+
65+
To delete a service, delete their routes first:
66+
```
67+
$ podman run -it --rm --pod=kong-pod docker.io/curlimages/curl curl -i -X DELETE --url http://localhost:8001/routes/webservice-route
68+
$ podman run -it --rm --pod=kong-pod docker.io/curlimages/curl curl -i -X DELETE --url http://localhost:8001/services/webservice
69+
```
70+
71+
72+
## Cleaning up
73+
74+
To remove all pods including containers:
75+
```
76+
$ podman pod rm --force webservice-pod kong-pod postgres-pod
77+
```

kong-podman/initdb.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CREATE DATABASE kongdb;
2+
CREATE USER kong WITH PASSWORD 'abcde12345';

kong-podman/kong-pod.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: kong-pod
5+
spec:
6+
restartPolicy: Never
7+
containers:
8+
- name: kong
9+
image: docker.io/library/kong:2.3.0
10+
ports:
11+
- containerPort: 8000
12+
hostPort: 8000
13+
protocol: tcp
14+
- containerPort: 8443
15+
protocol: tcp
16+
- containerPort: 8001
17+
protocol: tcp
18+
- containerPort: 8444
19+
protocol: tcp
20+
volumeMounts:
21+
- mountPath: /etc/kong/kong.conf
22+
name: kongconf
23+
readOnly: true
24+
volumes:
25+
- name: kongconf
26+
hostPath:
27+
path: ./kong.conf

kong-podman/kong.conf

Lines changed: 1249 additions & 0 deletions
Large diffs are not rendered by default.

kong-podman/postgres-pod.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: postgres-pod
5+
spec:
6+
restartPolicy: Never
7+
containers:
8+
- name: postgres
9+
image: docker.io/postgres:13.1-alpine
10+
ports:
11+
- containerPort: 5432
12+
protocol: tcp
13+
env:
14+
- name: POSTGRES_PASSWORD
15+
value: abcde12345
16+
volumeMounts:
17+
- mountPath: /docker-entrypoint-initdb.d/initdb.sql
18+
name: initdb
19+
readOnly: true
20+
volumes:
21+
- name: initdb
22+
hostPath:
23+
path: ./initdb.sql

kong-podman/project/.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port

kong-podman/project/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "webservice",
3+
"version": "1.0.0",
4+
"description": "Dummy webservice",
5+
"author": "extra2000",
6+
"license": "MIT",
7+
"main": "src/webservice.ts",
8+
"scripts": {
9+
"tsc": "tsc",
10+
"webservice": "ts-node src/webservice.ts"
11+
},
12+
"dependencies": {
13+
"express": "^4.16.1",
14+
"body-parser": "1.18.3"
15+
},
16+
"devDependencies": {
17+
"typescript": "^4.0.2",
18+
"ts-node": "^9.0.0",
19+
"@types/node": "^14.11.2"
20+
}
21+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
const express = require('express');
2+
const bodyParser = require('body-parser');
3+
const app = express();
4+
5+
const customers = [
6+
{
7+
id: 5,
8+
first_name: 'Gordon',
9+
last_name: 'Freeman'
10+
},
11+
{
12+
id: 6,
13+
first_name: 'Nick',
14+
last_name: 'Mendoza'
15+
}
16+
];
17+
18+
const clients = [
19+
{
20+
id: 1,
21+
first_name: 'Heather',
22+
last_name: 'Mason'
23+
},
24+
{
25+
id: 2,
26+
first_name: 'James',
27+
last_name: 'Sunderland'
28+
}
29+
];
30+
31+
app.use(bodyParser.json());
32+
33+
app.get('/api/v1/customers', (req, res) => {
34+
res.json(customers);
35+
});
36+
37+
app.get('/api/v1/customers/:id', (req, res) => {
38+
res.json(customers[req.params.id]);
39+
});
40+
41+
app.get('/api/v1/clients', (req, res) => {
42+
res.json(clients);
43+
});
44+
45+
app.get('/api/v1/clients/:id', (req, res) => {
46+
res.json(clients[req.params.id]);
47+
});
48+
49+
app.listen(8000, () => {
50+
console.log(`Server started!`);
51+
});

kong-podman/webservice-pod.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: webservice-pod
5+
spec:
6+
restartPolicy: Never
7+
containers:
8+
- name: webservice
9+
image: localhost/extra2000/webservice
10+
ports:
11+
- containerPort: 8000
12+
protocol: tcp

0 commit comments

Comments
 (0)