2020-10-30 17:08:52 -04:00
---
2020-11-16 13:09:15 -05:00
stage: Configure
group: Configure
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-30 17:08:52 -04:00
---
2021-02-08 13:09:49 -05:00
# Getting started with Auto DevOps **(FREE)**
2017-09-07 16:39:09 -04:00
2020-11-18 19:09:41 -05:00
This step-by-step guide helps you use [Auto DevOps ](index.md ) to
2018-06-21 17:54:47 -04:00
deploy a project hosted on GitLab.com to Google Kubernetes Engine.
2017-09-07 16:39:09 -04:00
2020-12-10 16:10:15 -05:00
You are using the GitLab native Kubernetes integration, so you don't need
2018-06-21 17:54:47 -04:00
to create a Kubernetes cluster manually using the Google Cloud Platform console.
2020-11-18 19:09:41 -05:00
You are creating and deploying a simple application that you create from a GitLab template.
2017-09-07 16:39:09 -04:00
2020-11-18 19:09:41 -05:00
These instructions also work for a self-managed GitLab instance;
ensure your own [runners are configured ](../../ci/runners/README.md ) and
2018-06-22 02:12:20 -04:00
[Google OAuth is enabled ](../../integration/google.md ).
2020-04-14 23:09:11 -04:00
## Configure 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,
2020-04-14 23:09:11 -04:00
you need a [Google Cloud Platform account ](https://console.cloud.google.com ).
Sign in with an existing Google account, such as the one you use to access Gmail
or Google Drive, or create a new one.
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
1. Follow the steps described in the ["Before you begin" section ](https://cloud.google.com/kubernetes-engine/docs/quickstart#before-you-begin )
2020-12-22 13:10:05 -05:00
of the Kubernetes Engine documentation to enable the required APIs and related services.
2020-04-14 23:09:11 -04:00
1. Ensure you've created a [billing account ](https://cloud.google.com/billing/docs/how-to/manage-billing-account )
with Google Cloud Platform.
2017-09-07 16:39:09 -04:00
2020-12-07 22:09:37 -05:00
NOTE:
2018-06-12 06:38:10 -04:00
Every new Google Cloud Platform (GCP) account receives [$300 in credit ](https://console.cloud.google.com/freetrial ),
2020-04-14 23:09:11 -04:00
and in partnership with Google, GitLab is able to offer an additional $200 for new
2020-12-10 16:10:15 -05:00
GCP accounts to get started with the GitLab integration with Google Kubernetes Engine.
2020-04-14 23:09:11 -04:00
[Follow this link ](https://cloud.google.com/partners/partnercredit/?pcn_code=0014M00001h35gDQAQ#contact-form )
and apply for credit.
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
## Create a new project from a template
2018-05-17 08:57:49 -04:00
2020-12-10 16:10:15 -05:00
We are using a GitLab project template to get started. As the name suggests,
2020-01-08 22:07:56 -05:00
those projects provide a bare-bones application built on some well-known frameworks.
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
1. In GitLab, click the plus icon (**{plus-square}**) at the top of the navigation bar, and select
2018-06-12 06:38:10 -04:00
**New project** .
2020-04-14 23:09:11 -04:00
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.
2020-04-14 23:09:11 -04:00
For this tutorial, 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
2021-01-28 19:09:17 -05:00
[GitLab Ultimate plan ](https://about.gitlab.com/pricing/ ).
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
2020-11-18 19:09:41 -05:00
Now that you've created a project, create the Kubernetes cluster
2020-04-14 23:09:11 -04:00
to deploy this project to.
2017-09-12 14:22:56 -04:00
2020-04-14 23:09:11 -04:00
## Create a Kubernetes cluster from within GitLab
2017-09-12 14:22:56 -04:00
2020-04-14 23:09:11 -04:00
1. On your project's landing page, click **Add Kubernetes cluster**
2020-08-04 14:09:49 -04:00
(note that this option is also available when you navigate to **Operations > Kubernetes** ).
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
![Project landing page ](img/guide_project_landing_page_v12_10.png )
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
1. On the **Add a Kubernetes cluster integration** page, click the **Create new cluster** tab,
then click **Google GKE** .
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
1. Connect with your Google account, and click **Allow** to allow access to your
Google account. (This authorization request is only displayed the first time
you connect GitLab with your Google account.)
After authorizing access, the **Add a Kubernetes cluster integration** page
is displayed.
1. In the **Enter the details for your Kubernetes cluster** section, provide
details about your cluster:
- **Kubernetes cluster name**
- **Environment scope** - Leave this field unchanged.
- **Google Cloud Platform project** - Select a project. When you
[configured your Google account ](#configure-your-google-account ), a project
should have already been created for you.
- **Zone** - The [region/zone ](https://cloud.google.com/compute/docs/regions-zones/ ) to
create the cluster in.
- **Number of nodes**
- **Machine type** - For more information about
[machine types ](https://cloud.google.com/compute/docs/machine-types ), see Google's documentation.
2020-04-21 11:21:10 -04:00
- **Enable Cloud Run for Anthos** - Select this checkbox to use the
[Cloud Run ](../../user/project/clusters/add_gke_clusters.md#cloud-run-for-anthos ),
2020-04-14 23:09:11 -04:00
Istio, and HTTP Load Balancing add-ons for this cluster.
- **GitLab-managed cluster** - Select this checkbox to
2020-04-21 11:21:10 -04:00
[allow GitLab to manage namespace and service accounts ](../../user/project/clusters/index.md#gitlab-managed-clusters ) for this cluster.
2020-04-14 23:09:11 -04:00
1. Click **Create Kubernetes cluster** .
2019-01-30 05:20:50 -05:00
2020-11-18 19:09:41 -05:00
After a couple of minutes, the cluster is created. You can also see its
2018-06-12 06:38:10 -04:00
status on your [GCP dashboard ](https://console.cloud.google.com/kubernetes ).
2017-09-07 16:39:09 -04:00
2020-12-22 13:10:05 -05:00
## Install Ingress
2017-09-07 16:39:09 -04:00
2020-12-22 13:10:05 -05:00
After your cluster is running, you must install NGINX Ingress Controller as a
load balancer, to route traffic from the internet to your application. Because
you've created a Google GKE cluster in this guide, you can install NGINX Ingress Controller
with Google Cloud Shell:
2018-06-12 06:38:10 -04:00
2020-12-22 13:10:05 -05:00
1. Go to your cluster's details page, and click the **Advanced Settings** tab.
1. Click the link to Google Kubernetes Engine to visit the cluster on Google Cloud Console.
1. On the GKE cluster page, select **Connect** , then click **Run in Cloud Shell** .
1. After the Cloud Shell starts, run these commands to install NGINX Ingress Controller:
2018-06-12 06:38:10 -04:00
2020-12-22 13:10:05 -05:00
```shell
helm repo add nginx-stable https://helm.nginx.com/stable
helm repo update
helm install nginx-ingress nginx-stable/nginx-ingress
2018-06-12 06:38:10 -04:00
2020-12-22 13:10:05 -05:00
# Check that the ingress controller is installed successfully
kubectl get service nginx-ingress-nginx-ingress
```
1. A few minutes after you install NGINX, the load balancer obtains an IP address, and you can
get the external IP address with this command:
```shell
kubectl get service nginx-ingress-nginx-ingress -ojson | jq -r '.status.loadBalancer.ingress[].ip'
```
2018-06-12 06:38:10 -04:00
2020-12-22 13:10:05 -05:00
Copy this IP address, as you need it in the next step.
2018-06-12 06:38:10 -04:00
2020-12-22 13:10:05 -05:00
1. Go back to the cluster page on GitLab, and go to the **Details** tab.
- Add your **Base domain** . For this guide, use the domain `<IP address>.nip.io` .
- Click **Save changes** .
2018-06-12 06:38:10 -04:00
2020-12-22 13:10:05 -05:00
![Cluster Base Domain ](img/guide_base_domain_v12_3.png )
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
## Enable Auto DevOps (optional)
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
While Auto DevOps is enabled by default, Auto DevOps can be disabled at both
the instance level (for self-managed instances) and the group level. Complete
these steps to enable Auto DevOps if it's disabled:
2018-06-12 06:38:10 -04:00
2020-07-28 23:09:51 -04:00
1. Navigate to **Settings > CI/CD > Auto DevOps** , and click **Expand** .
2020-04-14 23:09:11 -04:00
1. Select **Default to Auto DevOps pipeline** to display more options.
1. In **Deployment strategy** , select your desired [continuous deployment strategy ](index.md#deployment-strategy )
to deploy the application to production after the pipeline successfully runs on the `master` branch.
1. Click **Save changes** .
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
![Auto DevOps settings ](img/guide_enable_autodevops_v12_3.png )
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
After you save your changes, GitLab creates a new pipeline. To view it, go to
**{rocket}** **CI/CD > Pipelines** .
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
In the next section, we explain what each job does in the pipeline.
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
## Deploy the application
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
When your pipeline runs, what is it doing?
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
To view the jobs in the pipeline, click the pipeline's status badge. The
**{status_running}** icon displays when pipeline jobs are running, and updates
without refreshing the page to ** {status_success}** (for success) or
**{status_failed}** (for failure) when the jobs complete.
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
The jobs are separated into stages:
2018-06-12 06:38:10 -04:00
2020-05-27 14:08:14 -04:00
![Pipeline stages ](img/guide_pipeline_stages_v13_0.png )
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
- **Build** - The application builds a Docker image and uploads it to your project's
[Container Registry ](../../user/packages/container_registry/index.md ) ([Auto Build](stages.md#auto-build)).
2020-11-04 10:08:41 -05:00
- **Test** - GitLab runs various checks on the application, but all jobs except `test`
are allowed to fail in the test stage:
2020-04-14 23:09:11 -04:00
- The `test` job runs unit and integration tests by detecting the language and
framework ([Auto Test](stages.md#auto-test))
- The `code_quality` job checks the code quality and is allowed to fail
2021-01-26 22:08:58 -05:00
([Auto Code Quality](stages.md#auto-code-quality))
2020-04-14 23:09:11 -04:00
- The `container_scanning` job checks the Docker container if it has any
2020-09-07 11:09:04 -04:00
vulnerabilities and is allowed to fail ([Auto Container Scanning](stages.md#auto-container-scanning))
2020-04-14 23:09:11 -04:00
- The `dependency_scanning` job checks if the application has any dependencies
susceptible to vulnerabilities and is allowed to fail
2020-09-07 11:09:04 -04:00
([Auto Dependency Scanning](stages.md#auto-dependency-scanning)) ** (ULTIMATE)**
2020-05-27 14:08:14 -04:00
- Jobs suffixed with `-sast` run static analysis on the current code to check for potential
2020-09-07 11:09:04 -04:00
security issues, and are allowed to fail ([Auto SAST](stages.md#auto-sast)) ** (ULTIMATE)**
- The `secret-detection` job checks for leaked secrets and is allowed to fail ([Auto Secret Detection](stages.md#auto-secret-detection)) ** (ULTIMATE)**
2020-04-14 23:09:11 -04:00
- The `license_management` job searches the application's dependencies to determine each of their
licenses and is allowed to fail
2020-09-07 11:09:04 -04:00
([Auto License Compliance](stages.md#auto-license-compliance)) ** (ULTIMATE)**
2020-04-14 23:09:11 -04:00
2020-05-27 14:08:14 -04:00
- **Review** - Pipelines on `master` include this stage with a `dast_environment_deploy` job.
To learn more, see [Dynamic Application Security Testing (DAST) ](../../user/application_security/dast/index.md ).
2020-04-14 23:09:11 -04:00
- **Production** - After the tests and checks finish, the application deploys in
Kubernetes ([Auto Deploy](stages.md#auto-deploy)).
- **Performance** - Performance tests are run on the deployed application
2020-09-07 11:09:04 -04:00
([Auto Browser Performance Testing](stages.md#auto-browser-performance-testing)). ** (PREMIUM)**
2020-04-14 23:09:11 -04:00
2020-05-27 14:08:14 -04:00
- **Cleanup** - Pipelines on `master` include this stage with a `stop_dast_environment` job.
2020-04-14 23:09:11 -04:00
After running a pipeline, you should view your deployed website and learn how
to monitor it.
### Monitor your project
After successfully deploying your application, you can view its website and check
on its health on the **Environments** page by navigating to
2020-08-04 14:09:49 -04:00
**Operations > Environments**. This page displays details about
2020-04-14 23:09:11 -04:00
the deployed applications, and the right-hand column displays icons that link
you to common environment tasks:
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
2020-04-21 11:21:10 -04:00
- **Open live environment** (**{external-link}**) - Opens the URL of the application deployed in production
- **Monitoring** (**{chart}**) - Opens the metrics page where Prometheus collects data
2020-04-14 23:09:11 -04:00
about the Kubernetes cluster and how the application
affects it in terms of memory usage, CPU usage, and latency
2020-04-21 11:21:10 -04:00
- **Deploy to** (**{play}** ** {angle-down}**) - Displays a list of environments you can deploy to
2020-05-15 14:07:52 -04:00
- **Terminal** (**{terminal}**) - Opens a [web terminal ](../../ci/environments/index.md#web-terminals )
2020-04-14 23:09:11 -04:00
session inside the container where the application is running
2020-04-21 11:21:10 -04:00
- **Re-deploy to environment** (**{repeat}**) - For more information, see
2021-02-23 16:10:44 -05:00
[Retrying and rolling back ](../../ci/environments/index.md#retry-or-roll-back-a-deployment )
2020-04-21 11:21:10 -04:00
- **Stop environment** (**{stop}**) - For more information, see
2020-05-15 14:07:52 -04:00
[Stopping an environment ](../../ci/environments/index.md#stopping-an-environment )
2020-04-14 23:09:11 -04:00
GitLab displays the [Deploy Board ](../../user/project/deploy_boards.md ) below the
environment's information, with squares representing pods in your
Kubernetes cluster, color-coded to show their status. Hovering over a square on
the deploy board displays the state of the deployment, and clicking the square
takes you to the pod's logs page.
2017-09-07 16:39:09 -04:00
2020-12-07 22:09:37 -05:00
NOTE:
2020-04-14 23:09:11 -04:00
The example shows only one pod hosting the application at the moment, but you can add
2021-02-18 19:11:06 -05:00
more pods by defining the [`REPLICAS` CI/CD variable ](customize.md#cicd-variables )
in **Settings > CI / CD > Variables** .
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
### Work 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 ),
2020-04-14 23:09:11 -04:00
you should next create a feature branch to add content to your application:
2017-09-12 14:22:56 -04:00
2020-04-14 23:09:11 -04:00
1. In your project's repository, navigate to the following file: `app/views/welcome/index.html.erb` .
This file should only contain a paragraph: `<p>You're on Rails!</p>` .
1. Open the GitLab [Web IDE ](../../user/project/web_ide/index.md ) to make the change.
1. Edit the file so it contains:
2017-09-07 16:39:09 -04:00
2020-04-14 23:09:11 -04:00
```html
< p > You're on Rails! Powered by GitLab Auto DevOps.< / p >
```
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
1. Stage the file. Add a commit message, then create a new branch and a merge request
by clicking **Commit** .
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
![Web IDE commit ](img/guide_ide_commit_v12_3.png )
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
After submitting the merge request, GitLab runs your pipeline, and all the jobs
in it, as [described previously ](#deploy-the-application ), in addition to
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
2020-11-18 19:09:41 -05:00
After a few minutes a test fails, which means a test was
2020-04-14 23:09:11 -04:00
'broken' by your change. Click on the failed `test` job to see more information
about it:
2018-06-12 06:38:10 -04:00
2020-03-25 02:07:58 -04:00
```plaintext
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
2020-04-14 23:09:11 -04:00
To fix the broken test:
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
1. Return to the **Overview** page for your merge request, and click **Open in Web IDE** .
1. In the left-hand directory of files, find the `test/controllers/welcome_controller_test.rb`
file, and click it to open it.
2018-06-12 06:38:10 -04:00
1. Change line 7 to say `You're on Rails! Powered by GitLab Auto DevOps.`
1. Click **Commit** .
2020-04-14 23:09:11 -04:00
1. In the left-hand column, under **Unstaged changes** , click the checkmark icon
2020-04-21 11:21:10 -04:00
(**{stage-all}**) to stage the changes.
2020-04-14 23:09:11 -04:00
1. Write a commit message, and click **Commit** .
2018-06-12 06:38:10 -04:00
2020-04-14 23:09:11 -04:00
Return to the **Overview** page of your merge request, and you should not only
see the test passing, but also the application deployed as a
[review application ](stages.md#auto-review-apps ). You can visit it by clicking
2020-04-21 11:21:10 -04:00
the **View app** ** {external-link}** button to see your changes deployed.
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
2020-04-14 23:09:11 -04:00
After merging the merge request, GitLab runs the pipeline on the `master` branch,
and then deploys the application to production.
2018-06-12 06:38:10 -04:00
## Conclusion
2020-04-14 23:09:11 -04:00
After implementing this project, you should have a solid understanding of the basics of Auto DevOps.
You started from building and testing, to deploying and monitoring an application
2020-12-22 13:10:05 -05:00
all in 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 )
2020-07-08 08:09:33 -04:00
1. [Multiple Kubernetes clusters ](index.md#using-multiple-kubernetes-clusters )
2020-09-07 11:09:04 -04:00
1. [Incremental rollout to production ](customize.md#incremental-rollout-to-production ) ** (PREMIUM)**
2021-02-18 19:11:06 -05:00
1. [Disable jobs you don't need with CI/CD variables ](customize.md#cicd-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 )
2020-04-07 23:09:31 -04:00
1. [Use your own buildpacks to build your application ](customize.md#custom-buildpacks )
2018-06-12 06:38:10 -04:00
1. [Prometheus monitoring ](../../user/project/integrations/prometheus.md )