Lesson 2 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: 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

  2. Select Import project

  3. Press the Repo By URL button

  4. Under Git repository URL add the following URL:

https://gitlab.com/tech-marketing/devsecops/initech/simple-notes.git
  1. Select Public under visibility level
Note: Public is set so that we don’t need to take extra steps to be able to pull from a private container-registry
  1. Press the Create project button

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

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

Step 2. 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. Click on the Infrastructure > Kubernetes clusters in the left navigation menu

  2. Click on the Connect a cluster (agent) button

  3. Select the simplenotes agent from the drop down and press the Register button

Note: Save the commands presented to you in the next screen
  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:
$ helm repo add gitlab https://charts.gitlab.io
$ helm repo update
$ helm upgrade --install simplenotes gitlab/gitlab-agent \
    --namespace gitlab-agent \
    --create-namespace \
    --set image.tag=v15.5.1 \
    --set config.token=1gqUgdbmxNsY3pyWLz_HzsqF_8zMgheniaxoCfFx1zPnyWacUQ \
    --set config.kasAddress=wss://kas.gitlab.com

"gitlab" already exists with the same configuration, skipping
Hang tight while we grab the latest from your chart repositories...
...Successfully got an update from the "gitlab" chart repository
Update Complete. ⎈Happy Helming!⎈

Release "simplenotes" does not exist. Installing it now.
NAME: simplenotes
LAST DEPLOYED: Mon Nov 14 14:27:43 2022
NAMESPACE: gitlab-agent
STATUS: deployed
REVISION: 1
TEST SUITE: None
Note: Make sure you use the token provided to you
  1. Verify the Kubernetes Agent is running
$ kubectl get pods -n gitlab-agent

NAME                                        READY   STATUS    RESTARTS   AGE
simplenotes-gitlab-agent-6795665c54-ccbbk   1/1     Running   0          54s

Step 3: 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 4: Reviewing the Pipeline #

Now let’s wait for the pipeline to complete, this should take a few mins - so grab a coffee ☕️ or tea 🍵, or whatever you like! If the pipeline happens to fail, please checkout the troubleshooting documentation.

  1. Verify that all the stages before deploy have passed successfully within the pipeline
Note: A completed pre-deploy pipeline should look like the below:
  1. Press the play button on the deploy job, the push to production. The play button like like the below:
Note: The reason why this is manual is because a deployment from the default branch has been set to manual. All other branches will deploy automatically. We are treating the default branch like production.
  1. Verify all jobs have completed successfully. It should look like the below:

Step 5: Accessing our Application #

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

  1. Click on the deploy job and scroll to the bottom. You should see the URL which the application was deployed to
Note: You can also go to the Deployment > Environments tab and click the Open button under the production environment.
  1. Point your browser to the provided link
Note: It should look something like http://xxx.xxx.xxx.xxx/notes
  1. You should now see the Simple Notes Application running. Go ahead and play around by adding and deleting notes
Note: It should look something like the below:

Congratulations! You have now successfully deployed an application using GitLab CI/CD.

Previous Lesson Next Lesson