Skip to content
This repository has been archived by the owner on Apr 22, 2022. It is now read-only.

WIP: Run on kubernetes #36

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d480ec0
Initial setup for kubernetes using `kompose convert` and some manual …
Sep 24, 2019
58502df
Fix the key in `labels` to get the network between pods going
Sep 24, 2019
b3b4e4a
Change web app service type to be LoadBalancer
JCZuurmond Sep 24, 2019
38dd8d3
Make shop-api also of type loadbalancer to expose it on localhost
Sep 24, 2019
3ff4214
Start
Sep 24, 2019
ee26a59
Merge branch 'run-on-kubernetes' of github.com:divolte/shop into run-…
Sep 24, 2019
faa2216
First attempt to load shop content using Job pod, not working
Sep 24, 2019
9c1e9f0
Loading the shop content using job pod
Sep 24, 2019
8b405c7
Back the bare minimum config
Sep 25, 2019
7b41316
Change shop API service to ClusterIP
JCZuurmond Sep 25, 2019
8b89bb3
Change shop webapp service to ClusterIP
JCZuurmond Sep 25, 2019
1be73e4
Add ingress yaml
JCZuurmond Sep 25, 2019
601b808
Change path to webshop to be index
JCZuurmond Sep 25, 2019
966daac
Add set-up for Ingress nginx to README
JCZuurmond Sep 25, 2019
cc058ec
Add initContainers to delay the start of the put-categories pods.
Sep 25, 2019
505d7e8
Merge branch 'run-on-kubernetes' of github.com:divolte/shop into run-…
Sep 25, 2019
49d91b9
Bug fix: change index path was not committed correctly
JCZuurmond Sep 25, 2019
32dc2cc
add Liveness probe for API with own route
anibaldk Sep 25, 2019
0a9c94e
Merge branch 'live-probes' into run-on-kubernetes
anibaldk Sep 25, 2019
8cdee5d
Change init container to check if shop-api service is alive
JCZuurmond Sep 26, 2019
dc83947
Add init containers which checks if API is alive
JCZuurmond Sep 26, 2019
9f0c106
Solve flake8 issues
JCZuurmond Sep 26, 2019
76fed7b
Change input order according to PEP8
JCZuurmond Sep 26, 2019
4393bf4
Put json requests in separate function
JCZuurmond Sep 26, 2019
292fe7d
Retry json put if 10 times ConnectionError
JCZuurmond Sep 26, 2019
2a5d2f0
Bug fix: json.dump --> json.dumps
JCZuurmond Sep 26, 2019
3438536
Add retrying to be pip installed
JCZuurmond Sep 26, 2019
3e01af4
Add utility script to build the jars, without the need of sbt/gradle.
Sep 26, 2019
ffa2b94
Add comment explaining ttlSecondsAfterFinished
JCZuurmond Sep 26, 2019
be74dc2
Make catalog-builder an image to load data into the shop
anibaldk Sep 26, 2019
2fcd672
merge work with Cor
anibaldk Sep 26, 2019
b8ff7a1
Clean up deployment file
anibaldk Sep 26, 2019
d326724
Merge branch 'run-on-kubernetes' of github.com:divolte/shop into run-…
JCZuurmond Sep 26, 2019
b4831d5
Make sure the docker-compose also works.
Sep 26, 2019
3081478
Fix typo
Sep 26, 2019
8927773
Uniform the docker context of catalog builder.
Sep 26, 2019
9722410
Small readme update
Jan 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ This application comprises a number of different processes:
## Prerequisite(s)

The following package(s) are required;
- `sbt`.

Install them with your package manager:
- `sbt`;
- and `ingress-nginx`.

Install with your package manager:

```
brew update
Expand All @@ -58,6 +60,32 @@ apt update
apt install sbt
```

### Ingress Nginx

Our setup uses an [Ingress](https://kubernetes.io/docs/concepts/services-networking/ingress/) with Nginx to define reroutes to the webshop and the
API (aka service) used by the webshop. The following steps
are required:

For all deployments:

```
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
```

Provider specific:

**For Docker for mac**
```
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/cloud-generic.yaml
```

**For minikube**
```
minikube addons enable ingress
```

For more info, see [here](https://github.com/kubernetes/ingress-nginx/blob/master/docs/deploy/index.md#installation-guide).

## Running with Docker

The easiest way to get started is with Docker Compose.
Expand Down
33 changes: 33 additions & 0 deletions k8s/clickstream-analyzer-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: clickstream-analyzer
labels:
app: clickstream-analyzer
spec:
replicas: 1
selector:
matchLabels:
app: clickstream-analyzer
template:
metadata:
labels:
app: clickstream-analyzer
spec:
containers:
- env:
- name: KAFKA_BROKERS
value: kafka:9092
- name: KAFKA_TOPIC
value: divolte
- name: SPARK_JOB_CLASS
value: sparkjob.SparkEventsPerMinute
image: shop_clickstream-analyzer
name: clickstream-analyzer
imagePullPolicy: Never # always local
ports:
- containerPort: 7077
- containerPort: 4040
- containerPort: 18080
hostname: clickstream-analyzer
restartPolicy: Always
19 changes: 19 additions & 0 deletions k8s/clickstream-analyzer-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: clickstream-analyzer
labels:
app: clickstream-analyzer
spec:
ports:
- name: "7077"
port: 7077
targetPort: 7077
- name: "4040"
port: 4040
targetPort: 4040
- name: "18080"
port: 18080
targetPort: 18080
selector:
app: clickstream-analyzer
30 changes: 30 additions & 0 deletions k8s/clickstream-collector-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: clickstream-collector
labels:
app: clickstream-collector
spec:
replicas: 1
selector:
matchLabels:
app: clickstream-collector
template:
metadata:
labels:
app: clickstream-collector
spec:
containers:
- env:
- name: DIVOLTE_CONF_DIR
value: /etc/shop/divolte
- name: DIVOLTE_KAFKA_BROKER_LIST
value: kafka:9092
image: shop_clickstream-collector
name: clickstream-collector
imagePullPolicy: Never
ports:
- containerPort: 8290
hostname: clickstream-collector
restartPolicy: Always
subdomain: divolte-divolte
13 changes: 13 additions & 0 deletions k8s/clickstream-collector-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: clickstream-collector
labels:
app: clickstream-collector
spec:
ports:
- name: "8290"
port: 8290
targetPort: 8290
selector:
app: clickstream-collector
38 changes: 38 additions & 0 deletions k8s/elastic-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: elastic
labels:
app: elastic
spec:
replicas: 1
selector:
matchLabels:
app: elastic
template:
metadata:
labels:
app: elastic
spec:
containers:
- env:
- name: ES_JAVA_OPTS
value: -Xms512m -Xmx512m
- name: cluster.name
value: elasticsearch
- name: discovery.type
value: single-node
- name: network.bind_host
value: 0.0.0.0
- name: network.publish_host
value: elastic
- name: xpack.security.enabled
value: "false"
image: docker.elastic.co/elasticsearch/elasticsearch:6.4.0
name: elastic
ports:
- containerPort: 9200
- containerPort: 9300
hostname: elastic
restartPolicy: Always
subdomain: divolte-divolte
16 changes: 16 additions & 0 deletions k8s/elastic-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: elastic
labels:
app: elastic
spec:
ports:
- name: "9200"
port: 9200
targetPort: 9200
- name: "9300"
port: 9300
targetPort: 9300
selector:
app: elastic
18 changes: 18 additions & 0 deletions k8s/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: nginx-ingress
annotations:
ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- http:
paths:
- path: /
backend:
serviceName: shop-webapp
servicePort: 9011
- path: /api
backend:
serviceName: shop-api
servicePort: 8080
42 changes: 42 additions & 0 deletions k8s/kafka-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kafka
labels:
app: kafka
spec:
replicas: 1
selector:
matchLabels:
app: kafka
template:
metadata:
labels:
app: kafka
spec:
containers:
- env:
- name: ADVERTISED_HOST
value: kafka
- name: ADVERTISED_LISTENERS
value: PLAINTEXT://kafka:9092,INTERNAL://localhost:9093
- name: AUTO_CREATE_TOPICS
value: "false"
- name: INTER_BROKER
value: INTERNAL
- name: KAFKA_CREATE_TOPICS
value: divolte:4:1
- name: LISTENERS
value: PLAINTEXT://0.0.0.0:9092,INTERNAL://0.0.0.0:9093
- name: LOG_RETENTION_HOURS
value: "1"
- name: SECURITY_PROTOCOL_MAP
value: PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT
image: krisgeus/docker-kafka
name: kafka
ports:
- containerPort: 9092
- containerPort: 2181
hostname: kafka
restartPolicy: Always
subdomain: divolte-divolte
16 changes: 16 additions & 0 deletions k8s/kafka-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: Service
metadata:
name: kafka
labels:
app: kafka
spec:
ports:
- name: "9092"
port: 9092
targetPort: 9092
- name: "2182"
port: 2181
targetPort: 2181
selector:
app: kafka
31 changes: 31 additions & 0 deletions k8s/kibana-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: kibana
labels:
app: kibana
spec:
replicas: 1
selector:
matchLabels:
app: kibana
template:
metadata:
labels:
app: kibana
spec:
containers:
- env:
- name: ELASTICSEARCH_URL
value: http://elastic:9200
- name: LOGGING_QUIET
value: "true"
- name: SERVER_NAME
value: kibana.divolte-divolte
image: docker.elastic.co/kibana/kibana:6.4.0
name: kibana
ports:
- containerPort: 5601
hostname: kibana
restartPolicy: Always
subdomain: divolte-divolte
13 changes: 13 additions & 0 deletions k8s/kibana-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: kibana
labels:
app: kibana
spec:
ports:
- name: "5601"
port: 5601
targetPort: 5601
selector:
app: kibana
27 changes: 27 additions & 0 deletions k8s/put-categories-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: batch/v1
kind: Job
metadata:
name: put-categories
spec:
template:
spec:
containers:
- name: put-categories
image: python:3.6
workingDir: /shop
volumeMounts:
- mountPath: /shop
name: divolte-shop
command: ["bash"]
args: ["-c", "pip install requests && python catalog-builder/put-categories.py --api-base-url http://shop-api:8080/api data/categories/animals.json data/categories/architecture.json data/categories/cars.json data/categories/cities.json data/categories/flowers.json data/categories/landscape.json data/categories/nautical.json"]
restartPolicy: Never
volumes:
- name: divolte-shop
hostPath:
path: /Users/bas/code/gdd/shop
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User specific path

type: Directory
initContainers:
- name: wait-for-shop-api
image: busybox:1.28
command: ['sh', '-c', 'sleep 30']
backoffLimit: 4
39 changes: 39 additions & 0 deletions k8s/shop-api-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: shop-api
labels:
app: shop-api
spec:
replicas: 1
selector:
matchLabels:
app: shop-api
template:
metadata:
labels:
app: shop-api
spec:
containers:
- env:
- name: ELASTICSEARCH_CLUSTER_NAME
value: elasticsearch
- name: ELASTICSEARCH_HOSTS
value: '["elastic"]'
- name: JAVA_OPTS
value: -Xms512m -Xmx512m
image: shop_shop-api
name: shop-api
imagePullPolicy: Never
ports:
- containerPort: 8080
- containerPort: 8081
livenessProbe:
httpGet:
path: /api/status/ping
port: 8080
initialDelaySeconds: 3
periodSeconds: 3
hostname: shop-api
restartPolicy: Always
subdomain: divolte-divolte
Loading