Skip to content

Commit

Permalink
README.md improvements, minor fix in Helm hook
Browse files Browse the repository at this point in the history
  • Loading branch information
rafzei committed Jan 8, 2022
1 parent 4795c51 commit 0239a25
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
66 changes: 60 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ python3 ./http-api/app.py

### Docker image

You can easly build and run application in docker by typing the following commands:
You can easly build application in docker by typing the following command:

```sh
docker build --tag http-api:latest .
docker run -d --name http-api:latest
```

The image is also available on Dockerhub:
Expand All @@ -59,33 +58,53 @@ The image is also available on Dockerhub:
docker pull rafzei/http-api:latest
```

To run an application in Docker, execute:

```sh
docker run -ti --name http-api http-api:latest
```

## Monitoring

In addition, you could use provided docker-compose file. It contains Prometheus and Grafana image definitions. In `./configs` directory you can find config files for both, as well as Grafana dashboard.

To run monitoring tools along with application, execute:

```sh
docker-compose up --build
```

The Flask application exposes its metrics on `/metrics` endpoint. Example:

```sh
<url>:5000/metrics
http://<url>:5000/metrics
```

To reach provided Grafana dashboard:

```sh
<ulr>:3000/d/app/flask-app
http://<url>:3000/d/app/flask-app
```

To get Prometheus GUI:

```sh
http://<url>:9090/graph
```

As `<url>` you could use localhost or container ip address (check it via docker inspect).

## Helm

### Helm chart

To run a chart execute the following command:

```sh
helm helm upgrade --install http-api --namespace http-api --create-namespace ./http-api/
helm helm upgrade --install http-api --namespace http-api --create-namespace ./charts/http-api/
```

Note: To be able to run ingress on minikube, enable addon:
Note: To be able to run ingress on minikube, make sure your minikube is in the latest released version and enable addon:

```sh
minikube addons enable ingress
Expand All @@ -95,10 +114,45 @@ For details see [the official documentation](https://kubernetes.io/docs/tasks/ac

### Helm hook

I've provided sample Helm hook (job) which can be adjusted and used for migrations between releases.
See [here](charts/http-api/templates/hooks/pre-hook.yaml)

### Helm test

Please, refer to: [docs/tests](docs/tests.md)

## Kubernetes

Because the yaml's are already in the Helm charts, you could use it as `source of true` and generate manifests needed for example by kubectl. Execute the following command:

```sh
helm template http-api ./charts/http-api/ --namespace http-api --create-namespace --output-dir ./kubernetes --no-hooks --skip-tests
```

Because the namespace is created during helm chart execution, you have to provide it mannualy before `kubectl apply -f <file.yml>` execution.

Example:

```sh
kubectl create namespace http-api
```

### Open-policy-agent (OPA)

This part assumes, that you already have OPA user, namespace and rbac created (TODO: Implement in v0.2.0).

Files related to OPA are included in [opa dir](opa/):

- deployment.yaml - deploys OPA in a cluster
- check-container-user.rego - provice policy file to check if user is not privileged
- service.yaml - provide clusterIP service for ingress
- ingress.yaml - provide ingress to reach OPA API

To apply OPA execute the following commands:

```sh
kubectl create configmap check-container-user --from-file ./opa/check-container-user.rego
kubectl apply -f ./opa/deployment.yaml
kubectl apply -f ./opa/service.yaml
kubectl apply -f ./opa/ingress.yaml
```
3 changes: 1 addition & 2 deletions charts/http-api/templates/hooks/pre-hook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ spec:
- name: migration
image: busybox
command: ['echo']
args: ['Doing some fancy migration here...']
restartPolicy: Never
args: ['Doing some migration here...']
Empty file added kubernetes/.gitkeep
Empty file.

0 comments on commit 0239a25

Please sign in to comment.