Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
89 changes: 87 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,92 @@ NOTE: The following tasks should take no more than 1 hour total.
2. create docker-compose.yaml to replicate a full running environment
so that a developer can run the entire application locally without having
to run any dependencies (i.e. redis) in a separate process.
3. explain how you would monitor this application in production. Please
write code to do the monitoring.
3. Explain how you would monitor this application in production. Please write code/scripts to do the monitoring.


### Kubernetes(MiniKube) Tasks
1. Prepare local Kubernetes environment (using MiniKube) to run our application in pod/container. Store all relevant scripts (kubectl commands etc) in your forked repository.
2. Suggest & create minimal local infrastructure to perform functional testing/monitoring of our application pod. Demonstrate monitoring of relevant results & metrics for normal app behavior and failure(s).



Please fork this repository and make a pull request with your changes.

Please provide test monitoring results in any convenient form (files, images, additional notes) as a separate archive.



## Solution

1. Dockerfile: ./src/Dockerfile
2. For developer:
```sh
# To see the docker compose manifest
cat docker-compose.yaml
# Start
docker compose up
# Stop
docker compose down
```

3. Application monitoring.
Mostly depends on metrics what we want.
I suggest:
- add functionality to write logs to the file
- mount disk
- run sidecar container with filebeat/metricbeat or fluentd and push logs to the some storage(e.g. InfluxDB)
- Grafana as UI. Grafana might be used from kube-prometheus-stack(see below)


4. Kubernetes.
I implemented configuration using Helm. Of course it might be only kubectl.
Helm chart: ./k8s

4.1 Create namespace for application

```sh
kubectl create namespace test-app
```

4.2 Deploy ingress-nginx(or similar) if you don't have any ingress controllers
```sh
cd ingress-nginx/
helm install -n test-app ingress-nginx .
```

4.3 Deploy application
```sh
cd ./k8s/deploy/
helm install -n test-app test-app .
# if you have some changes:
helm upgrade -n test-app test-app .
```

You can specify the images in values file: ./k8s/deploy/values.yaml

5. k8s cluster monitoring

5.1 Create monitoring namespace:
```sh
kubectl create namespace monitoring
```

5.2 Deploy kube-prometheus-stack
By default it will deploy prometheus, alert manager, grafana.
You could flexible customize the configuration and add some additional alerts in values file: ./k8s/kube-prometheus-stack/values.yaml

```sh
cd ./k8s/kube-prometheus-stack
helm install -n monitoring monitoring .
```

6. Grafana
There are a lot of pre-defined dashboards.

For instance: http://localhost/grafana/d/6581e46e4e5c7ba40a07646395ef7b23/kubernetes-compute-resources-pod?orgId=1&refresh=10s&var-datasource=Prometheus&var-cluster=&var-namespace=test-app&var-pod=test-app-app-deployment-7ddd5f94fb-2b4j7&from=now-5m&to=now

7. Routing
"/" - application
"/prometheous"
"/grafana"

13 changes: 13 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
services:
app:
build: src
ports:
- 8080:8080
depends_on:
- redis
environment:
- REDIS_ADDR=0.0.0.0:6379
redis:
image: redis
ports:
- 6379:6379
3 changes: 3 additions & 0 deletions k8s/deploy/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: "DevOps Test"
owner: Petr Iglaev
version: 1.0
22 changes: 22 additions & 0 deletions k8s/deploy/templates/app-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-app-deployment
labels:
app: {{ .Release.Name }}-app-deployment
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Release.Name }}-app-deployment
template:
metadata:
labels:
app: {{ .Release.Name }}-app-deployment
spec:
containers:
- name: app
image: {{ .Values.app_container }}
imagePullPolicy: {{ .Values.app_pull_policy }}
ports:
- containerPort: 8080
11 changes: 11 additions & 0 deletions k8s/deploy/templates/app-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: service-app
spec:
selector:
app: {{ .Release.Name }}-app-deployment
ports:
- protocol: TCP
port: 8080
targetPort: 8080
18 changes: 18 additions & 0 deletions k8s/deploy/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ingress-app
annotations:
# nginx.ingress.kubernetes.io/rewrite-target: /$2
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-app
port:
number: 8080
22 changes: 22 additions & 0 deletions k8s/deploy/templates/redis-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-redis-deployment
labels:
app: {{ .Release.Name }}-redis-deployment
spec:
replicas: 1
selector:
matchLabels:
app: {{ .Release.Name }}-redis-deployment
template:
metadata:
labels:
app: {{ .Release.Name }}-redis-deployment
spec:
containers:
- name: redis
image: {{ .Values.redis_container }}
imagePullPolicy: IfNotPresent
ports:
- containerPort: 6379
11 changes: 11 additions & 0 deletions k8s/deploy/templates/redis-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: service-redis
spec:
selector:
app: {{ .Release.Name }}-redis-deployment
ports:
- protocol: TCP
port: 6379
targetPort: 6379
8 changes: 8 additions & 0 deletions k8s/deploy/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Application
app_container: devopstest:2.0
# Set IfNotPresent if you image is remote
app_pull_policy: Never


# Redis
redis_container: redis:latest
22 changes: 22 additions & 0 deletions k8s/ingress-nginx/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
Loading