A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.gitlab.com/topics/autodevops/cloud_deployments/auto_devops_with_gke/ below:

Use Auto DevOps to deploy an application to Google Kubernetes Engine

In this tutorial, we’ll help you to get started with Auto DevOps through an example of how to deploy an application to Google Kubernetes Engine (GKE).

You are using the GitLab native Kubernetes integration, so you don’t need to create a Kubernetes cluster manually using the Google Cloud Platform console. You are creating and deploying an application that you create from a GitLab template.

These instructions also work for GitLab Self-Managed. Ensure your own runners are configured and Google OAuth is enabled.

To deploy a project to Google Kubernetes Engine, follow the steps below:

  1. Configure your Google account
  2. Create a Kubernetes cluster and deploy the agent
  3. Create a new project from a template
  4. Configure the agent
  5. Install Ingress
  6. Configure Auto DevOps
  7. Enable Auto DevOps and run the pipeline
  8. Deploy the application
Configure your Google account

Before creating and connecting your Kubernetes cluster to your GitLab project, you need a Google Cloud Platform account. Sign in with an existing Google account, such as the one you use to access Gmail or Google Drive, or create a new one.

  1. Follow the steps described in the “Before you begin” section of the Kubernetes Engine documentation to enable the required APIs and related services.
  2. Ensure you’ve created a billing account with Google Cloud Platform.

Every new Google Cloud Platform (GCP) account receives $300 in credit, and in partnership with Google, GitLab is able to offer an additional $200 for new GCP accounts to get started with the GitLab integration with Google Kubernetes Engine. Follow this link and apply for credit.

Create a Kubernetes cluster

To create a new cluster on Google Kubernetes Engine (GKE), use Infrastructure as Code (IaC) approach by following steps in Create a Google GKE cluster guide. The guide requires you to create a new project that uses Terraform to create a GKE cluster and install a GitLab agent for Kubernetes. This project is where configuration for the GitLab agent for Kubernetes resides.

Create an application project from a template

Use a GitLab project template to get started. As the name suggests, those projects provide a bare-bones application built on some well-known frameworks.

Create the application project in the group hierarchy at the same level or below the project for cluster management. Otherwise, it fails to authorize the agent.

  1. On the left sidebar, at the top, select Create new ( plus ) and New project/repository.
  2. Select Create from template.
  3. Select the Ruby on Rails template.
  4. 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 Ultimate plan.
  5. Select Create project.

Now you have an application project you are going to deploy to the GKE cluster.

Configure the agent

Now we need to configure the GitLab agent for Kubernetes for us to be able to use it to deploy the application project.

  1. Go to the project we created to manage the cluster.
  2. Go to the agent configuration file (.gitlab/agents/<agent-name>/config.yaml) and edit it.
  3. Configure ci_access:projects attribute. Use application’s project path as id:
ci_access:
  projects:
    - id: path/to/application-project
Install Ingress

After your cluster is running, you must install NGINX Ingress Controller as a load balancer, to route traffic from the internet to your application. Install the NGINX Ingress Controller through the GitLab Cluster management project template, or manually with Google Cloud Shell:

  1. Go to your cluster’s details page, and select the Advanced Settings tab.

  2. Select the link to Google Kubernetes Engine to visit the cluster on Google Cloud Console.

  3. On the GKE cluster page, select Connect, then select Run in Cloud Shell.

  4. After the Cloud Shell starts, run these commands to install NGINX Ingress Controller:

    helm upgrade --install ingress-nginx ingress-nginx \
    --repo https://kubernetes.github.io/ingress-nginx \
    --namespace gitlab-managed-apps --create-namespace
    
    # Check that the ingress controller is installed successfully
    kubectl get service ingress-nginx-controller -n gitlab-managed-apps
Configure Auto DevOps

Follow these steps to configure the base domain and other settings required for Auto DevOps.

  1. A few minutes after you install NGINX, the load balancer obtains an IP address, and you can get the external IP address with the following command:

    kubectl get service ingress-nginx-controller -n gitlab-managed-apps -ojson | jq -r '.status.loadBalancer.ingress[].ip'

    Replace gitlab-managed-apps if you have overwritten your namespace.

    Copy this IP address, as you need it in the next step.

  2. Go back to the application project.

  3. On the left sidebar, select Settings > CI/CD and expand Variables.

Enable Auto DevOps and run the pipeline

While Auto DevOps is enabled by default, Auto DevOps can be disabled for both the instance (for GitLab Self-Managed instances) and the group. Complete these steps to enable Auto DevOps if it’s disabled:

  1. On the left sidebar, select Search or go to and find the application project.

  2. Select Settings > CI/CD.

  3. Expand Auto DevOps.

  4. Select Default to Auto DevOps pipeline to display more options.

  5. In Deployment strategy, select your desired continuous deployment strategy to deploy the application to production after the pipeline successfully runs on the default branch.

  6. Select Save changes.

  7. Edit .gitlab-ci.yml file to include Auto DevOps template and commit the change to master branch:

    include:
    - template: Auto-DevOps.gitlab-ci.yml

The commit should trigger a pipeline. In the next section, we explain what each job does in the pipeline.

Deploy the application

When your pipeline runs, what is it doing?

To view the jobs in the pipeline, select 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.

The jobs are separated into stages:

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 Operate > Environments. This page displays details about the deployed applications, and the right-hand column displays icons that link you to common environment tasks:

GitLab displays the deploy board 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 selecting the square takes you to the pod’s logs page.

The example shows only one pod hosting the application at the moment, but you can add more pods by defining the REPLICAS CI/CD variable in Settings > CI/CD > Variables.

Work with branches

Next, create a feature branch to add content to your application:

  1. In your project’s repository, go to the following file: app/views/welcome/index.html.erb. This file should only contain a paragraph: <p>You're on Rails!</p>.

  2. Open the GitLab Web IDE to make the change.

  3. Edit the file so it contains:

    <p>You're on Rails! Powered by GitLab Auto DevOps.</p>
  4. Stage the file. Add a commit message, then create a new branch and a merge request by selecting Commit.

After submitting the merge request, GitLab runs your pipeline, and all the jobs in it, as described previously, in addition to a few more that run only on branches other than the default branch.

After a few minutes a test fails, which means a test was ‘broken’ by your change. Select the failed test job to see more information about it:

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

To fix the broken test:

  1. Return to your merge request.
  2. In the upper right corner, select Code, then select Open in Web IDE.
  3. In the left-hand directory of files, find the test/controllers/welcome_controller_test.rb file, and select it to open it.
  4. Change line 7 to say You're on Rails! Powered by GitLab Auto DevOps.
  5. On the left sidebar, select Source Control ( merge ).
  6. Write a commit message, and select Commit.

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. You can visit it by selecting the View app external-link button to see your changes deployed.

After merging the merge request, GitLab runs the pipeline on the default branch, and then deploys the application to production.

Conclusion

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 all in GitLab. Despite its automatic nature, Auto DevOps can also be configured and customized to fit your workflow. Here are some helpful resources for further reading:

  1. Auto DevOps
  2. Multiple Kubernetes clusters
  3. Incremental rollout to production
  4. Disable jobs you don’t need with CI/CD variables
  5. Use your own buildpacks to build your application

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4