Skip to content
Snippets Groups Projects
Commit d90181f4 authored by Thomas  MENARD's avatar Thomas MENARD
Browse files

Update README

parent 87c393ff
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,24 @@ In order to deploy this app on Kubernetes we will need to complete the following
* Define a URL in order to access to your application
* Setup Gitlab CI in order to define the Continuous Delivery (CD)
## Pre-requisits
### On your computer
* Git ust be installed
* Nice to have : a code editor (Atom, Visual Studio code ....)
* Connected to Pasteur VPN (or you won't be able to use all the tools)
### Gitlab
If you have never used Gitlab before, you will need to add an `ssh key` in your profile or define `HTTP` password in order to fetch the git repository.
Use basic git command :
```
git add .
git commit -m 'My comment'
git push
```
## Step by step guide
### Create Docker Registry Access Token
......@@ -79,8 +97,15 @@ CMD python manage.py runserver 0.0.0.0:$PORT
At the root of your git repository create a `.gitlab-ci.yml` file.
We will use a special docker image which contain the docker binary.
We will attach to the running docker daemon in order to build the image.
> Name it correctly `.gitlab-ci.yml` and not `.gitlab-ci.yaml` !
We will use a special docker image which contain the docker binary, we build a docker in a docker :-)
What do we do here ?
* We login on the docker registry enbended in Gitlab (a docker registry is the place where we store docker images to redistribute them)
* We build the docker image and we add a `tag`to it (actually the id of the git commit)
* We tag the previously builded docker image with a special tag `latest` (this can be sometime usefull)
* We push the image to the docker registry
```yaml
stages:
......@@ -102,25 +127,44 @@ build:
Save, commit and push; you should be abble to see your first running pipeline
> For those not familiar with `git` you can just do the following in a terminal
```
git add .
git commit -m 'My comment'
git push
```
![alt text](img/ci_pipeline.png)
Once succesfully completed, you can see the docker image in the `Registry`section on the left pane.
### Create manifests yaml files
We are going to create manifest files at the root directory of your git repository and fill it with the following definition.
In order to deploy your application on Kubernetes we need to define how to deploy :
* What is the source of the image ?
* Do I need parameters in order to configure my application ?
* Do I need some storage ?
* What will be it's name ?
* Do I have some "secure" information ? (login, password...)
* What would be it's dns name ?
....
So we are going to create manifest files at the root directory of your git repository and fill it with the following definition.
> Keep in mind that yaml formating require that you seperate each declaration with `---` line.
#### PostgreSQL Server
> Create `postgresql.yaml` file
> Create the `postgresql.yaml` file at the root directory of your project
In order to deploy a Postgresql server we need :
- [ ] Storage
- [ ] Configuration
- [ ] Secrets (passwords....)
- [ ] Deployment
- [ ] Service
- [ ] Service (Load balancing even if it's for one Pod)
##### Persistent Volume Claim
......@@ -129,6 +173,7 @@ As a Docker image is immutable, you may need to define some persistent storage.
We do this using a `Persistent Volume Claim`.
> You can see that we define an `accessModes`to `ReadWriteOnce`, this mean that the Persistent Volume will only be accessed by one container.
> Insert this in the `postgresql.yaml` file :
```yaml
apiVersion: v1
kind: PersistentVolumeClaim
......@@ -152,6 +197,7 @@ We are here defining the PostgreSQL basic parameters : username, password and da
![alt text](img/base64.png)
> Insert this in the `postgresql.yaml` file with `---` line before
```yaml
apiVersion: v1
kind: Secret
......@@ -166,6 +212,7 @@ data:
##### PostgreSQL Deployment
> Insert this in the `postgresql.yaml` file with `---` line before
```yaml
apiVersion: apps/v1
kind: Deployment
......@@ -230,6 +277,7 @@ spec:
##### PostgreSQL Service
> Insert this in the `postgresql.yaml` file with `---` line before
```yaml
apiVersion: v1
kind: Service
......@@ -250,7 +298,7 @@ spec:
> Create `polls.yaml` file
##### Deployment
> Insert this in the `polls.yaml` file
```yaml
apiVersion: apps/v1
kind: Deployment
......@@ -311,6 +359,7 @@ spec:
##### Service
> Insert this in the `polls.yaml` file with `---` line before
```yaml
apiVersion: v1
kind: Service
......@@ -328,6 +377,7 @@ spec:
##### Ingress Resource
> Insert this in the `polls.yaml` file with `---` line before
```yaml
apiVersion: extensions/v1beta1
kind: Ingress
......@@ -355,6 +405,7 @@ Create a file `job.yaml` at the root directory of your git repository and fill i
We will use a `Job` in order to manage django migrations.
> Note: Kubernetes jobs are run only once opposed to `Deployments` that run continiously. We put it in a seperate file because a Job is immutable and cannot be updated.
> Insert this in the `job.yaml` file
```yaml
---
apiVersion: batch/v1
......@@ -399,6 +450,7 @@ spec:
### Setup Continuous Delivery in Gitlab CI
> Insert this in the `.gitlab-ci.yml` file after the previous part (docker build)
```yaml
deploy:
stage: deploy
......@@ -456,6 +508,10 @@ You may have a `404 page not found` error, that's can be unfortunately normal fo
If you want to increase the number of replicas of your web application, you can go in the Deployement section and select the 3 dots on the `polls` line; select `Scale`. You can increase or decrease the number of replicas. Kubernetes will automaticaly add or remove Pods.
> You can also update the file `polls.yaml` to change the replicas value (by default 1)
> Kubernetes will automatically load balance the traffic to the n PODS.
#### What happen if I kill a Pod ?
You can try to `Delete` the polls `Pod` using the 3 dots icon and see that Kubernetes will automaticaly restart a new one.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment