Formation Linux Devops

https://acloudguru.com/

Travail demandé:

Serveur à utiliser:

Vous pouvez utiliser l’outil Vmware ou VirtualBox ou une technologie similaire 

Travail demandé

Créer ce site web

https://medium.com/geekculture/build-and-deploy-a-web-application-with-react-and-node-js-express-bce2c3cfec32

Code du site web:

https://gitlab.com/Form5tt/devops-linux-v2

Aide (étapes)

  • Créer votre compte Gitlab
  • Gitlab (installer gitlab runner sur le serveur A cloud guru)
  • Copier le contenu du projet Gitlab https://gitlab.com/Form5tt/devops-linux-v2 dans votre compte Gitlab
  • Sur Gitlab: Modifier le fichier .gitlab-ci.yml pour pouvroir créer ce site web avec les technologies Devops (CI/CD)

Technologies à utiliser:

  • Gitlab
  • Ubuntu 20
  • Nginx
  • On n’utilise pas Docker

Résultat attendu

Quand on lance cette url ( http://server_ip/8080 )  sur un navigateur, on obtient cette interface:
Contenu du fichier .gitlab-ci.yml:
stages:          # List of stages for jobs, and their order of execution
  – build
  – deploy
 
build-job:       # This job runs in the build stage, which runs first.
  stage: build
  script:
    – echo «  »start build » »
    – pwd
    – npm –version
    – node –version
    – npm install
    – echo «  »end build » »
  artifacts:
    expire_in: 1 hour
    paths:
      – client/build
      – node_modules
deploy-job:      # This job runs in the deploy stage.
  stage: deploy  # It only runs when *both* jobs in the test stage complete successfully.
  script:
    – echo «  »Deploying application… » »
    – pwd
    – ls -lrt
    #- apt-get update -qq
    #- apt-get install -y -qq sshpass
    #- EXPORT SSHPASS=$USER_PASSWORD
    – npm run start &
    – echo «  »Application successfully deployed. » »
  #environment:
    #name: production
    #url: 217.160.37.142
 
Contenu du fichier de condig Nginx:
app.js: require(‘dotenv’).config(); const Server = require(‘./models/server’); const server = new Server(); server.listen(process.env.PORT || 8080);
Serveur à utiliser:
Vous pouvez utiliser l’outil Vmware ou VirtualBox ou une technologie similaire 

Travail demandé
Créer le site web
 

Créer 2 conteneurs au niveau du serveur:
  • 1 conteneur contenant le Nginx
  • 1 conteneur contenant le code
 

Technologies à utiliser:
  • Créer un compte Gitlab
  • 2 conteneurs Docker
  • Nginx
  • Gitlab (installer gitlab runner sur le serveur ubuntu 20)
  • Ubuntu 20
  • Créer un pipeline sur Gitlab
Travail à rendre:
  • dockerfile pour le projet nodejs
  • dockerfile pour nginx
Le bon contenu des fichiers:
 
dockerfile
« FROM ubuntu:20.04
 
RUN apt-get update -yq \
&& apt-get install curl gnupg -yq \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash \
&& apt-get install nodejs -yq \
&& apt-get clean -y
 
ADD . /app/
WORKDIR /app
RUN npm install
 
EXPOSE 3000
VOLUME /app/logs
 
CMD npm run start »
docker-compose
« version: «  »3.8″ »
services:
    nodeserver:
        build:
            context: .
        ports:
            – «  »3000:3000″ »
    nginx:
        restart: always
        build:
            context: ./nginx
        ports:
            – «  »8080:80″ » »
Contenu du fichier .gitlab-ci.yml
« stages:          # List of stages for jobs, and their order of execution
  – deploy
deploy-job:      # This job runs in the deploy stage.
  stage: deploy
  before_script:
  – docker info
  # It only runs when *both* jobs in the test stage complete successfully.
  #environment: production
  script:
    – echo «  »Deploying application… » »
    #- cd /home/cloud_user/nodereactdocker/
    – docker-compose up –build -d
    – echo «  »Application successfully deployed. » » »
Nginx
« FROM nginx
COPY nginx.conf /etc/nginx/conf.d/default.conf »
gitlab_ci.yml
« # This file is a template, and might need editing before it works on your project.
# This is a sample GitLab CI/CD configuration file that should run without any modifications.
# It demonstrates a basic 3 stage CI/CD pipeline. Instead of real tests or scripts,
# it uses echo commands to simulate the pipeline execution.
#
# A pipeline is composed of independent jobs that run scripts, grouped into stages.
# Stages run in sequential order, but jobs within stages run in parallel.
#
# For more information, see: https://docs.gitlab.com/ee/ci/yaml/index.html#stages
#
# You can copy and paste this template into a new `.gitlab-ci.yml` file.
# You should not add this template to an existing `.gitlab-ci.yml` file by using the `include:` keyword.
#
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml
 
stages:          # List of stages for jobs, and their order of execution
  – deploy
deploy-job:      # This job runs in the deploy stage.
  stage: deploy
  before_script:
  – docker info
  # It only runs when *both* jobs in the test stage complete successfully.
  #environment: production
  script:
    – echo «  »Deploying application… » »
    #- cd /home/cloud_user/nodereactdocker/
    – docker-compose up –build -d
    – echo «  »Application successfully deployed. » » »
 
Environnement:
  • Serveur 1: Controlleur Kubernetes (Master – Control server)
  • Serveur 2 (serveur Kuberntes de type Worker Node)
 
 
Travail demandé:
Créer le site web
https://medium.com/geekculture/build-and-deploy-a-web-application-with-react-and-node-js-express-bce2c3cfec32
 
Code du site web: 
https://gitlab.com/Form5tt/devops-linux-v2
 
Résultat attendu:
 
Technologies utilisées:
Kubernetes
Gitlab (Il faut créer un compte Gitlab)
Docker
Nginx
Gitlab (installer gitlab runner sur le serveur ubuntu 20)
Ubuntu 20
Créer un pipeline sur Gitlab
Pour la partie réseau de Kubernetes, on utilise le plugin Flannel
 
Travail à effectuer:
Il faut mettre le contenu de ces fichiers
dockerfile-compose
dockerfile_nginx
dockerfile_nodejs
manifest_kubernetes
nginx.conf
run.sh
nginx_kubernetes.conf
 
Le bon contenu des fichiers:
dockerfile_nginx
« FROM nginx
COPY nginx.conf /etc/nginx/conf.d/default.conf »
dockerfile-compose
« version: «  »3.8″ »
services:
    nodeserver:
        build:
            context: .
        ports:
            – «  »3000:3000″ »
    nginx:
        restart: always
        build:
            context: ./nginx
        ports:
            – «  »8080:80″ » »
dockerfile_nodejs
« FROM ubuntu:20.04
 
RUN apt-get update -yq \
&& apt-get install curl gnupg -yq \
&& curl -sL https://deb.nodesource.com/setup_10.x | bash \
&& apt-get install nodejs -yq \
&& apt-get clean -y
 
ADD . /app/
WORKDIR /app
RUN npm install
 
EXPOSE 3000
VOLUME /app/logs
 
CMD npm run start »
manifest_kubernetes
« apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginxnode
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginxnodejs
  template:
    metadata:
      labels:
        app: nginxnodejs
    spec:
      containers:
      – name: nginxnodejs
        image: nginx
        command: [«  »sh » », «  »run.sh » »]
        ports:
        – containerPort: 80
        volumeMounts:
        – mountPath: /usr/share/nginx/html
          name: monvolume
      volumes:
      – name: monvolume
        hostPath:
          path: /home/cloud_user/testdocker/nodereactdocker/test
          type: Directory
apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: nginxnodejs
  type: NodePort
  ports:
  – name: http
     port: 80
    targetPort: 80
    nodePort: 30003
    protocol: TCP »
nginx.conf
« server {
    listen [::]:80;
    listen 80;
    server_name nodeserver;
    charset utf-8;
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
 
        proxy_pass http://nodeserver:3000;
    }
} »
run.sh
« #!/bin/bash
 
# Set variables
$source_directory=/home/cloud_user/testdocker/nodereactkubernetes
$destination_directory=/home/cloud_user/testdocker/nodereactkubernetes
 
# Synchronize files using rsync
rsync -avz –delete –exclude=.git –exclude=node_modules –rsh= » »ssh » » $source_directory/ clouduser@172.31.30.86:$destination_directory/ »
nginx_kubernetes.conf
« server {
    listen 80;
    server_name example.com;
 
    location / {
        proxy_pass http://localhost:3000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
} »
 
 
 

DevOps:
https://www.interviewgig.com/top-devops-tools-interview-questions/

AWS:
https://www.interviewgig.com/amazon-web-services-interview-questions-and-answers/
https://intellipaat.com/mediaFiles/2019/02/AWS-Basic-Cheat-Sheet.png

Linux:
https://appletree.or.kr/quick_reference_cards/Unix-Linux/Linux%20Command%20Line%20Cheat%20Sheet.pdf
https://www.guru99.com/linux-interview-questions-answers.html
https://cheatography.com/davechild/cheat-sheets/linux-command-line/

Docker:
https://www.docker.com/sites/default/files/d8/2019-09/docker-cheat-sheet.pdf
http://dockerlabs.collabnix.com/docker/cheatsheet/

Ansible:
https://drive.google.com/file/d/11Yv3ikHg7driYVrv-IcNvQmi6xhX9_i5/view

Kubernetes:
https://linuxacademy.com/blog/containers/kubernetes-cheat-sheet/?utm_source=intercom&utm_medium=email&utm_campaign=2019_learnbydoing
https://intellipaat.com/blog/tutorial/devops-tutorial/kubernetes-cheat-sheet/