Skip to content

Commit 09c77a9

Browse files
committed
updated docs
1 parent da293d8 commit 09c77a9

File tree

8 files changed

+119
-106
lines changed

8 files changed

+119
-106
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Content
2020
:maxdepth: 4
2121

2222
installation
23+
runinkubernetes
2324
quickstart
2425
structure
2526
configuration

docs/installation.rst

Lines changed: 1 addition & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,67 +8,4 @@ Clone the project
88
99
Configure your project and the path of your MS. See :doc:`configuration </configuration>` section.
1010

11-
Configure your setup.py with your project information
12-
13-
14-
15-
Use MS with Docker
16-
------------------
17-
`Install docker <https://docs.docker.com/install/>`_
18-
19-
20-
Use MS with Kubernetes localy
21-
-----------------------------
22-
Configure your service.yaml (TODO: create docs to configure kubernetes service.yaml)
23-
24-
* Installing Kubernetes...
25-
26-
.. code-block:: bash
27-
28-
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
29-
30-
* Installing Minikube...
31-
32-
.. code-block:: bash
33-
34-
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
35-
36-
37-
Start minikube and set the environment of docker
38-
39-
.. code-block:: bash
40-
41-
minikube start
42-
eval $(minikube docker-env)
43-
kubectl config use-context minikube
44-
45-
If a shell isn't your friend. You could use kubernetes web panel to see your pods:
46-
47-
.. code-block:: bash
48-
49-
minikube dashboard
50-
51-
Create your image
52-
53-
.. code-block:: bash
54-
55-
docker build -t your-app:v1 .
56-
57-
Deploy your images localy:
58-
59-
.. code-block:: bash
60-
61-
kubectl create -f service.yaml
62-
minikube service your-app
63-
64-
65-
Clean your environment
66-
67-
.. code-block:: bash
68-
69-
kubectl delete service your-app
70-
kubectl delete deployment your-app
71-
docker rmi your-app:v1 -f
72-
minikube stop
73-
eval $(minikube docker-env -u)
74-
minikube delete
11+
Configure your setup.py with your project information

docs/runinkubernetes.rst

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Run in kubernetes
2+
=================
3+
4+
Use MS with Docker
5+
------------------
6+
`Install docker <https://docs.docker.com/install/>`_
7+
8+
9+
Use MS with Kubernetes localy
10+
-----------------------------
11+
Configure your service.yaml (TODO: create docs to configure kubernetes service.yaml)
12+
13+
* Installing Kubernetes...
14+
15+
.. code-block:: bash
16+
17+
curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
18+
19+
* Installing Minikube...
20+
21+
.. code-block:: bash
22+
23+
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
24+
25+
26+
Start minikube and set the environment of docker
27+
28+
.. code-block:: bash
29+
30+
minikube start
31+
eval $(minikube docker-env)
32+
kubectl config use-context minikube
33+
34+
If a shell isn't your friend. You could use kubernetes web panel to see your pods:
35+
36+
.. code-block:: bash
37+
38+
minikube dashboard
39+
40+
Create your image
41+
42+
.. code-block:: bash
43+
44+
docker build -t template:v1 .
45+
46+
Deploy your images localy:
47+
48+
.. code-block:: bash
49+
50+
kubectl apply -f service.yaml
51+
minikube service template
52+
53+
54+
Clean your environment
55+
56+
.. code-block:: bash
57+
58+
kubectl delete template
59+
kubectl delete template
60+
docker rmi template:v1 -f
61+
minikube stop
62+
eval $(minikube docker-env -u)
63+
minikube delete

docs/structure.rst

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@ You have a project with this structure:
66
.. code-block:: bash
77
88
manager.py
9+
requirements.txt
10+
requirements-tests.txt
11+
requirements-docker.txt
12+
setup.py
13+
tox.ini
14+
myms
15+
├ healthcheck
16+
│ └ healthcheck.py
17+
├ models
18+
│ └ __init__.py
19+
└ tracer
20+
└ main.py
921
project
1022
├ __init__.py
1123
├ config.py
1224
├ views
1325
│ ├ __init__.py
14-
│ ├ views.py
15-
│ └ healthcheck.py
26+
│ └ views.py
1627
├ models
1728
│ ├ __init__.py
1829
│ └ models.py
@@ -25,26 +36,44 @@ manager.py
2536
A Django style command line. Use this to start the application like:
2637

2738
.. code-block:: bash
39+
2840
python manage.py runserver
2941
3042
You can set the host and the port with:
3143

3244
.. code-block:: bash
45+
3346
python manage.py runserver -h 0.0.0.0 -p 8080
3447
48+
Common Structure
49+
----------------
50+
51+
myms/healthcheck/healthcheck.py
52+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
This views is usually used by Kubernetes, Eureka and other systems to check if our application is up and running
54+
55+
myms/models/__init__.py
56+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
Initizalize `flask_sqlalchemy.SQLAlchemy object`
58+
59+
myms/tracer/main.py
60+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61+
Create an injector `flask_opentracing.FlaskTracer` to use in our projects
62+
63+
Structure of a project
64+
----------------------
65+
3566
project/__init__.py
36-
-------------------
67+
~~~~~~~~~~~~~~~~~~~
3768
This file init the project with the funcion `create_app`. Initialize the Flask app, register `blueprints <http://flask.pocoo.org/docs/0.12/blueprints/>`_
3869
and intialize all libraries like Swagger, database, the trace system...
3970

4071
project/config.py
41-
-----------------
72+
~~~~~~~~~~~~~~~~~
4273
See :doc:`configuration </configuration>` section
4374

4475
project/views
45-
-------------
76+
~~~~~~~~~~~~~
4677
use views.py or create your file. You must add after register the view blueprint in `project/views/__init__.py`.
4778

48-
project/views/healthcheck.py
49-
----------------------------
50-
This views is usually used by Kubernetes, Eureka and other systems to check if our application is up and running
79+

project/tests/test_views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def _format_response(response: Text = "") -> Union[List, Dict]:
1010
return json.loads(response)
1111

1212

13-
class FlaskrTestCase(unittest.TestCase):
13+
class ProjectTestCase(unittest.TestCase):
1414

1515
def setUp(self):
1616
os.environ["ENVIRONMENT"] = "test"

pyms/healthcheck/healthcheck.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,6 @@
1-
import opentracing
2-
import requests
3-
from flask_opentracing import FlaskTracer
4-
51
from pyms.healthcheck import healthcheck_blueprint
62

73

84
@healthcheck_blueprint.route('/healthcheck', methods=['GET'])
9-
def healthcheck(tracer: FlaskTracer):
10-
span = tracer.get_span()
11-
headers = {}
12-
tracer._tracer.inject(span, opentracing.Format.HTTP_HEADERS, headers)
13-
result = requests.post(url="http://localhost:8081/oauth/login", data={
14-
"username": "test",
15-
"password": "1234"
16-
}, headers=headers)
17-
return result.content
5+
def healthcheck():
6+
return "OK"

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,5 @@ Flask-Injector==0.10.1
55
Flask-OpenTracing==0.1.8
66
Flask-Script==2.0.6
77
Flask-SQLAlchemy==2.3.2
8-
Flask-Testing==0.7.1
98
SQLAlchemy==1.2.5
109
requests==2.18.4

service.yaml

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
# interno
2-
kind: Service
31
apiVersion: v1
2+
kind: Service
43
metadata:
54
name: template
65
spec:
76
selector:
87
app: template
98
ports:
109
- protocol: TCP
11-
port: 80
10+
port: 5000
1211
targetPort: 5000
13-
---
14-
# externo
15-
apiVersion: v1
16-
kind: Service
17-
metadata:
18-
name: template-external
19-
spec:
20-
ports:
21-
- port: 80
22-
targetPort: 5000
23-
selector:
24-
app: template
2512
type: LoadBalancer
26-
loadBalancerSourceRanges:
27-
- 62.82.24.134/32
13+
externalTrafficPolicy: "Local"
2814
---
2915
apiVersion: extensions/v1beta1
3016
kind: Deployment
@@ -39,7 +25,16 @@ spec:
3925
spec:
4026
containers:
4127
- name: template
42-
image: template:latest
28+
image: template:v1
4329
ports:
4430
- name: http
45-
containerPort: 5000
31+
containerPort: 5000
32+
---
33+
apiVersion: extensions/v1beta1
34+
kind: Ingress
35+
metadata:
36+
name: ingress
37+
spec:
38+
backend:
39+
serviceName: template
40+
servicePort: 5000

0 commit comments

Comments
 (0)