02 Deploying the Demo Application

Deploying an Application with GitLab Pipeline #

In this lesson, we will clone the project over to our space, so that we can make edits. We will deploy our application to our Kubernetes cluster, along with an Ingress controller. This will allow us to access the application from the outside world.

Step 1: Create a new Workshop Group #

  1. From the GitLab UI, Click on the Menu tab

  2. Go to the Groups tab

  3. Click on the Create Group tab

  4. Press the Create group button

  5. Give the group a name, and press the Create group button

  6. Now you have a group in which we can start adding projects to

Step 2: Cloning the Sample Project #

Here we will clone the sample project which we will use through this workshop. It’s a simple python Flask application which add/removes notes from a MariaDB DataBase.

  1. Press the New Project button

Note This action must be done within the group created in Step 1.
  1. Select Import project

  1. Press the Repo By URL button

  1. Under Git repository URL add the following URL:
https://gitlab.com/tech-marketing/devsecops/devsecops-workshop/workshop-notes.git
  1. Select Public under visibility level

  2. Press the Create project button

  3. Wait for the project to be imported. It will take a few seconds

Note You should be redirected to the newely imported project along with the message “The project was successfully imported”

Step 3. Cloning the Compliance and Deployment Manifests #

Here we will clone the sample project which house the files used to deploy the ingress controller, and echo application. It’s a collection of compliance pipeline and deployment yamls.

  1. Go back to the group created in step 1

  2. Press the New Project button

  3. Select Import project

  4. Press the Repo By URL button

  5. Under Git repository URL add the following URL:

https://gitlab.com/tech-marketing/devsecops/devsecops-workshop/workshop-manifests.git
  1. Select Public under visibility level

  2. Press the Create project button

  3. Wait for the project to be imported. It will take a few seconds

Note You should be redirected to the newely imported project along with the message “The project was successfully imported”

Step 4. Setting up the Project to use the Cluster #

In this section we will be installing the GitLab Kubernetes Agent to interact with the cluster and deploy our Kubernetes manifests.

  1. Open the WebIDE

Note This will be done within the workshop-notes project.
  1. Open the file .gitlab/agents/kube-agent/config.yaml which contains the following:
gitops:
  manifest_projects:
  - id: path/to/workshop-manifests/project
    paths:
    - glob: '/deploy/*.yaml'

and make sure to configure the path appropriately to your project.

Note The id for my workshop-notes is fjdiaz/workshop-manifests
  1. Commit this change by clicking on the Commit button

  1. Click on Commit to main branch and then press the Commit button. You can now deploy the Kubernetes agent to your cluster

  1. Click on the Infrastructure > Kubernetes clusters in the left navigation menu

  1. Click on the Install new Agent button

  1. Select your agent (kube-agent) from the drop down and press the Register button

  1. Open a terminal and connect to your cluster
$ gcloud container clusters get-credentials fern-initech --zone us-central1-c --project fdiaz-02874dfa

Fetching cluster endpoint and auth data.
kubeconfig entry generated for fern-initech.
  1. Run the following command to deploy the agent onto your cluster
$ 
Note This will deploy the kubernetes-agent which will then start deploying items found in the deploy folder in the agents configuration
  1. Verify the Kubernetes Agent is running
$ kubectl get pods -n gitlab-kubernetes-agent

Step 5: Running the Pipelines #

Now let’s run a pipeline to deploy the application to our Kubernetes cluster.

  1. Click on the CI/CD left navigation menu and click on Pipelines

  2. Click on Run Pipeline

  3. Ensure that the main branch is selected

  4. Press the Run Pipeline button

Note You should now see the pipeline running on your project

Step 6: Accessing our application #

Now let’s use the ingress to access our application. With the default settings your application should be avaliable at your Load-Balancers IP under the /notes path. These items can be configured via the values.yaml within the helm path.

  1. Get the Load-Balancer External IP-Address
$ kubectl get svc -n ingress-nginx
  1. Point your browser to http://[Load-Balancer External IP-Address]/notes

Congratulations! You have now successfully deployed an application using GitLab CICD.

Previous Lesson Next Lesson