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.
Press the New Project button
Select Import project
Press the Repo By URL button
Under Git repository URL add the following URL:
https://gitlab.com/tech-marketing/devsecops/initech/simple-notes.git
- 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
Press the Create project button
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.
Click on the Infrastructure > Kubernetes clusters in the left navigation menu
Click on the Connect a cluster (agent) button
Select the
simplenotes
agent from the drop down and press the Register button
Note: Save the commands presented to you in the next screen
- 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.
- 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
- 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.
Click on the CI/CD left navigation menu and click on Pipelines
Click on Run Pipeline
Ensure that the main branch is selected
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.
- Verify that all the stages before deploy have passed successfully within the pipeline
Note: A completed pre-deploy pipeline should look like the below:
- 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 thedefault
branch has been set to manual. All other branches will deploy automatically. We are treating thedefault
branch like production.
- 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.
- 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 theDeployment > Environments
tab and click theOpen
button under the production environment.
- Point your browser to the provided link
Note: It should look something like http://xxx.xxx.xxx.xxx/notes
- 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.