2018-06-12 06:38:10 -04:00
# Getting started with Auto DevOps
2017-09-07 16:39:09 -04:00
2018-06-21 17:54:47 -04:00
This is a step-by-step guide that will help you use [Auto DevOps ](index.md ) to
deploy a project hosted on GitLab.com to Google Kubernetes Engine.
2017-09-07 16:39:09 -04:00
2018-06-21 17:54:47 -04:00
We will use GitLab's native Kubernetes integration, so you will not need
to create a Kubernetes cluster manually using the Google Cloud Platform console.
We will create and deploy a simple application that we create from a GitLab template.
2017-09-07 16:39:09 -04:00
2018-06-22 02:12:20 -04:00
These instructions will also work for a self-hosted GitLab instance; you'll just
need to ensure your own [Runners are configured ](../../ci/runners/README.md ) and
[Google OAuth is enabled ](../../integration/google.md ).
2018-06-12 06:38:10 -04:00
## Configuring your Google account
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
Before creating and connecting your Kubernetes cluster to your GitLab project,
2018-06-21 17:54:47 -04:00
you need a Google Cloud Platform account. If you don't already have one,
2018-10-07 19:54:09 -04:00
sign up at < https: / / console . cloud . google . com > . You'll need to either sign in with an existing
2018-06-21 17:54:47 -04:00
Google account (for example, one that you use to access Gmail, Drive, etc.) or create a new one.
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
1. Follow the steps as outlined in the ["Before you begin" section of the Kubernetes Engine docs ](https://cloud.google.com/kubernetes-engine/docs/quickstart#before-you-begin )
in order for the required APIs and related services to be enabled.
1. Make sure you have created a [billing account ](https://cloud.google.com/billing/docs/how-to/manage-billing-account ).
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
TIP: **Tip:**
Every new Google Cloud Platform (GCP) account receives [$300 in credit ](https://console.cloud.google.com/freetrial ),
and in partnership with Google, GitLab is able to offer an additional $200 for new GCP accounts to get started with GitLab's
2019-10-09 20:06:44 -04:00
Google Kubernetes Engine Integration. All you have to do is [follow this link ](https://cloud.google.com/partners/partnercredit/?PCN=a0n60000006Vpz4AAC ) and apply for credit.
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
## Creating a new project from a template
2018-05-17 08:57:49 -04:00
2018-06-21 17:54:47 -04:00
We will use one of GitLab's project templates to get started. As the name suggests,
those projects provide a barebones application built on some well-known frameworks.
2017-09-07 16:39:09 -04:00
2018-06-21 17:54:47 -04:00
1. In GitLab, click the plus icon (**+**) at the top of the navigation bar and select
2018-06-12 06:38:10 -04:00
**New project** .
1. Go to the **Create from template** tab where you can choose among a Ruby on
2019-10-14 23:06:19 -04:00
Rails, Spring, or NodeJS Express project.
We'll use the Ruby on Rails template.
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
![Select project template ](img/guide_project_template_v12_3.png )
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
1. Give your project a name, optionally a description, and make it public so that
you can take advantage of the features available in the
[GitLab Gold plan ](https://about.gitlab.com/pricing/#gitlab-com ).
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
![Create project ](img/guide_create_project_v12_3.png )
2017-09-07 16:39:09 -04:00
2018-06-21 17:54:47 -04:00
1. Click **Create project** .
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
Now that the project is created, the next step is to create the Kubernetes cluster
under which this application will be deployed.
2017-09-12 14:22:56 -04:00
2018-06-21 17:54:47 -04:00
## Creating a Kubernetes cluster from within GitLab
2017-09-12 14:22:56 -04:00
2018-06-22 02:12:20 -04:00
1. On the project's landing page, click the button labeled **Add Kubernetes cluster**
(note that this option is also available when you navigate to **Operations > Kubernetes** ).
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
![Project landing page ](img/guide_project_landing_page_v12_3.png )
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
1. One the **Create new cluster on GKE** tab, click "Sign in with Google".
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
![Google sign in ](img/guide_google_signin_v12_3.png )
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
1. Connect with your Google account and press **Allow** when asked (this will
be shown only the first time you connect GitLab with your Google account).
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
![Google auth ](img/guide_google_auth_v12_3.png )
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
1. The last step is to provide the cluster details. Give it a name, leave the
2018-06-12 06:38:10 -04:00
environment scope as is, and choose the GCP project under which the cluster
2018-06-21 17:54:47 -04:00
will be created. (Per the instructions when you
2018-06-12 06:38:10 -04:00
[configured your Google account ](#configuring-your-google-account ), a project
2018-06-21 17:54:47 -04:00
should have already been created for you.) Next, choose the
2018-06-12 06:38:10 -04:00
[region/zone ](https://cloud.google.com/compute/docs/regions-zones/ ) under which the
cluster will be created, enter the number of nodes you want it to have, and
2019-10-14 23:06:19 -04:00
finally choose the [machine type ](https://cloud.google.com/compute/docs/machine-types ).
2017-09-07 16:39:09 -04:00
2019-10-14 23:06:19 -04:00
![GitLab GKE cluster details ](img/guide_gitlab_gke_details_v12_3.png )
2017-09-07 16:39:09 -04:00
2018-06-21 17:54:47 -04:00
1. Once ready, click **Create Kubernetes cluster** .
2019-01-30 05:20:50 -05:00
2018-06-12 06:38:10 -04:00
After a couple of minutes, the cluster will be created. You can also see its
status on your [GCP dashboard ](https://console.cloud.google.com/kubernetes ).
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
The next step is to install some applications on your cluster that are needed
to take full advantage of Auto DevOps.
2017-09-07 16:39:09 -04:00
2018-06-21 17:54:47 -04:00
## Installing Helm, Ingress, and Prometheus
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
GitLab's Kubernetes integration comes with some
[pre-defined applications ](../../user/project/clusters/index.md#installing-applications )
for you to install.
2019-10-14 23:06:19 -04:00
![Cluster applications ](img/guide_cluster_apps_v12_3.png )
2018-06-12 06:38:10 -04:00
The first one to install is Helm Tiller, a package manager for Kubernetes, which
is needed in order to install the rest of the applications. Go ahead and click
its **Install** button.
2018-06-21 17:54:47 -04:00
Once it's installed, the other applications that rely on it will each have their **Install**
2018-06-12 06:38:10 -04:00
button enabled. For this guide, we need Ingress and Prometheus. Ingress provides
load balancing, SSL termination, and name-based virtual hosting, using NGINX behind
the scenes. Prometheus is an open-source monitoring and alerting system that we'll
use to supervise the deployed application. We will not install GitLab Runner as
we'll use the shared Runners that GitLab.com provides.
After the Ingress is installed, wait a few seconds and copy the IP address that
2019-10-14 23:06:19 -04:00
is displayed in order to add in your base **Domain** at the top of the page. For
the purpose of this guide, we will use the one suggested by GitLab. Once you have
filled in the domain, click **Save changes** .
![Cluster Base Domain ](img/guide_base_domain_v12_3.png )
2018-06-12 06:38:10 -04:00
2019-10-14 23:06:19 -04:00
## Enabling Auto DevOps (optional)
2018-06-12 06:38:10 -04:00
2019-10-14 23:06:19 -04:00
Starting with GitLab 11.3, Auto DevOps is enabled by default. However, it is possible to disable
Auto DevOps at both the instance-level (for self-managed instances) and also at the group-level.
Follow these steps if Auto DevOps has been manually disabled.
2018-06-12 06:38:10 -04:00
1. First, navigate to **Settings > CI/CD > Auto DevOps** .
2019-10-14 23:06:19 -04:00
1. Select **Default to Auto DevOps pipeline** .
2018-06-12 06:38:10 -04:00
1. Lastly, let's select the [continuous deployment strategy ](index.md#deployment-strategy )
which will automatically deploy the application to production once the pipeline
2018-06-21 17:54:47 -04:00
successfully runs on the `master` branch.
1. Click **Save changes** .
2018-06-12 06:38:10 -04:00
2019-10-14 23:06:19 -04:00
![Auto DevOps settings ](img/guide_enable_autodevops_v12_3.png )
2018-06-12 06:38:10 -04:00
2018-06-21 17:54:47 -04:00
Once you complete all the above and save your changes, a new pipeline is
automatically created. To view the pipeline, go to **CI/CD > Pipelines** .
2018-06-12 06:38:10 -04:00
2019-10-14 23:06:19 -04:00
![First pipeline ](img/guide_first_pipeline_v12_3.png )
2018-06-12 06:38:10 -04:00
In the next section we'll break down the pipeline and explain what each job does.
## Deploying the application
2018-06-21 17:54:47 -04:00
By now you should see the pipeline running, but what is it running exactly?
2018-06-12 06:38:10 -04:00
2018-07-07 18:30:47 -04:00
To navigate inside the pipeline, click its status badge. (Its status should be "running").
2018-06-12 06:38:10 -04:00
The pipeline is split into 4 stages, each running a couple of jobs.
2019-10-14 23:06:19 -04:00
![Pipeline stages ](img/guide_pipeline_stages_v12_3.png )
2018-06-12 06:38:10 -04:00
In the **build** stage, the application is built into a Docker image and then
2019-09-17 08:06:48 -04:00
uploaded to your project's [Container Registry ](../../user/packages/container_registry/index.md ) ([Auto Build](index.md#auto-build)).
2018-06-12 06:38:10 -04:00
In the **test** stage, GitLab runs various checks on the application:
- The `test` job runs unit and integration tests by detecting the language and
framework ([Auto Test](index.md#auto-test))
- The `code_quality` job checks the code quality and is allowed to fail
2019-07-08 04:50:38 -04:00
([Auto Code Quality](index.md#auto-code-quality-starter)) ** (STARTER)**
2018-06-12 06:38:10 -04:00
- The `container_scanning` job checks the Docker container if it has any
2019-06-11 13:20:41 -04:00
vulnerabilities and is allowed to fail ([Auto Container Scanning](index.md#auto-container-scanning-ultimate))
2018-06-12 06:38:10 -04:00
- The `dependency_scanning` job checks if the application has any dependencies
2019-07-08 04:50:38 -04:00
susceptible to vulnerabilities and is allowed to fail ([Auto Dependency Scanning](index.md#auto-dependency-scanning-ultimate)) ** (ULTIMATE)**
2018-06-21 17:54:47 -04:00
- The `sast` job runs static analysis on the current code to check for potential
2019-07-08 04:50:38 -04:00
security issues and is allowed to fail([Auto SAST](index.md#auto-sast-ultimate)) ** (ULTIMATE)**
2018-06-21 17:54:47 -04:00
- The `license_management` job searches the application's dependencies to determine each of their
2019-08-22 03:44:58 -04:00
licenses and is allowed to fail ([Auto License Compliance](index.md#auto-license-compliance-ultimate)) ** (ULTIMATE)**
2017-09-07 16:39:09 -04:00
2018-02-07 09:35:54 -05:00
NOTE: **Note:**
2018-06-12 06:38:10 -04:00
As you might have noticed, all jobs except `test` are allowed to fail in the
test stage.
The **production** stage is run after the tests and checks finish, and it automatically
deploys the application in Kubernetes ([Auto Deploy](index.md#auto-deploy)).
Lastly, in the **performance** stage, some performance tests will run
on the deployed application
2019-07-08 04:50:38 -04:00
([Auto Browser Performance Testing](index.md#auto-browser-performance-testing-premium)). ** (PREMIUM)**
2018-06-12 06:38:10 -04:00
---
The URL for the deployed application can be found under the **Environments**
page where you can also monitor your application. Let's explore that.
### Monitoring
Now that the application is successfully deployed, let's navigate to its
2018-06-21 17:54:47 -04:00
website. First, go to **Operations > Environments** .
2018-06-12 06:38:10 -04:00
2019-10-14 23:06:19 -04:00
![Environments ](img/guide_environments_v12_3.png )
2018-06-12 06:38:10 -04:00
2018-06-21 17:54:47 -04:00
In **Environments** you can see some details about the deployed
applications. In the rightmost column for the production environment, you can make use of the three icons:
2018-06-12 06:38:10 -04:00
2018-06-21 17:54:47 -04:00
- The first icon will open the URL of the application that is deployed in
production. It's a very simple page, but the important part is that it works!
2018-07-07 18:30:47 -04:00
- The next icon, with the small graph, will take you to the metrics page where
2018-06-21 17:54:47 -04:00
Prometheus collects data about the Kubernetes cluster and how the application
affects it (in terms of memory/CPU usage, latency, etc.).
2018-02-07 09:35:54 -05:00
2019-10-14 23:06:19 -04:00
![Environments metrics ](img/guide_environments_metrics_v12_3.png )
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
- The third icon is the [web terminal ](../../ci/environments.md#web-terminals )
and it will open a terminal session right inside the container where the
application is running.
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
Right below, there is the
2019-05-30 02:21:35 -04:00
[Deploy Board ](../../user/project/deploy_boards.md ).
2018-06-12 06:38:10 -04:00
The squares represent pods in your Kubernetes cluster that are associated with
the given environment. Hovering above each square you can see the state of a
2018-06-21 17:54:47 -04:00
deployment and clicking a square will take you to the pod's logs page.
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
TIP: **Tip:**
There is only one pod hosting the application at the moment, but you can add
more pods by defining the [`REPLICAS` variable ](index.md#environment-variables )
2019-01-30 05:20:50 -05:00
under **Settings > CI/CD > Environment variables** .
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
### Working with branches
2017-09-12 14:22:56 -04:00
2019-10-27 02:06:30 -04:00
Following the [GitLab flow ](../gitlab_flow.md#working-with-feature-branches ),
2018-06-12 06:38:10 -04:00
let's create a feature branch that will add some content to the application.
2017-09-12 14:22:56 -04:00
2018-06-12 06:38:10 -04:00
Under your repository, navigate to the following file: `app/views/welcome/index.html.erb` .
By now, it should only contain a paragraph: `<p>You're on Rails!</p>` , so let's
2018-06-21 17:54:47 -04:00
start adding content. Let's use GitLab's [Web IDE ](../../user/project/web_ide/index.md ) to make the change. Once
2018-06-12 06:38:10 -04:00
you're on the Web IDE, make the following change:
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
```html
< p > You're on Rails! Powered by GitLab Auto DevOps.< / p >
```
Stage the file, add a commit message, and create a new branch and a merge request
by clicking **Commit** .
2019-10-14 23:06:19 -04:00
![Web IDE commit ](img/guide_ide_commit_v12_3.png )
2018-06-12 06:38:10 -04:00
Once you submit the merge request, you'll see the pipeline running. This will
2018-07-07 18:30:47 -04:00
run all the jobs as [described previously ](#deploying-the-application ), as well as
2018-06-12 06:38:10 -04:00
a few more that run only on branches other than `master` .
2019-10-14 23:06:19 -04:00
![Merge request ](img/guide_merge_request_v12_3.png )
2018-06-12 06:38:10 -04:00
2018-06-21 17:54:47 -04:00
After a few minutes you'll notice that there was a failure in a test.
This means there's a test that was 'broken' by our change.
Navigating into the `test` job that failed, you can see what the broken test is:
2018-06-12 06:38:10 -04:00
```
Failure:
WelcomeControllerTest#test_should_get_index [/app/test/controllers/welcome_controller_test.rb:7]:
< You ' re on Rails ! > expected but was
< You ' re on Rails ! Powered by GitLab Auto DevOps . > ..
Expected 0 to be >= 1.
bin/rails test test/controllers/welcome_controller_test.rb:4
```
2017-09-07 16:39:09 -04:00
2018-06-12 06:38:10 -04:00
Let's fix that:
2019-10-14 23:06:19 -04:00
1. Back to the merge request, click the **Open in Web IDE** button.
2018-06-12 06:38:10 -04:00
1. Find the `test/controllers/welcome_controller_test.rb` file and open it.
1. Change line 7 to say `You're on Rails! Powered by GitLab Auto DevOps.`
1. Click **Commit** .
1. On your left, under "Unstaged changes", click the little checkmark icon
to stage the changes.
2018-06-21 17:54:47 -04:00
1. Write a commit message and click **Commit** .
2018-06-12 06:38:10 -04:00
2018-10-07 19:54:09 -04:00
Now, if you go back to the merge request you should not only see the test passing, but
also the application deployed as a [review app ](index.md#auto-review-apps ). You
2019-10-14 23:06:19 -04:00
can visit it by following clicking the **View app** button. You will see
the changes that we previously made.
2018-06-12 06:38:10 -04:00
2019-10-14 23:06:19 -04:00
![Review app ](img/guide_merge_request_review_app_v12_3.png )
2018-06-12 06:38:10 -04:00
Once you merge the merge request, the pipeline will run on the `master` branch,
and the application will be eventually deployed straight to production.
## Conclusion
2018-06-21 17:54:47 -04:00
After implementing this project, you should now have a solid understanding of the basics of Auto DevOps.
2018-06-12 06:38:10 -04:00
We started from building and testing to deploying and monitoring an application
2018-07-07 18:30:47 -04:00
all within GitLab. Despite its automatic nature, Auto DevOps can also be configured
2018-06-21 17:54:47 -04:00
and customized to fit your workflow. Here are some helpful resources for further reading:
2018-06-12 06:38:10 -04:00
1. [Auto DevOps ](index.md )
2019-07-08 04:50:38 -04:00
1. [Multiple Kubernetes clusters ](index.md#using-multiple-kubernetes-clusters-premium ) ** (PREMIUM)**
1. [Incremental rollout to production ](index.md#incremental-rollout-to-production-premium ) ** (PREMIUM)**
2018-06-12 06:38:10 -04:00
1. [Disable jobs you don't need with environment variables ](index.md#environment-variables )
2019-10-31 11:06:41 -04:00
1. [Use a static IP for your cluster ](../../user/clusters/applications.md#using-a-static-ip )
2018-06-12 06:38:10 -04:00
1. [Use your own buildpacks to build your application ](index.md#custom-buildpacks )
1. [Prometheus monitoring ](../../user/project/integrations/prometheus.md )