2017-09-07 16:39:09 -04:00
|
|
|
|
# Auto DevOps: quick start guide
|
|
|
|
|
|
2017-09-21 09:33:59 -04:00
|
|
|
|
> [Introduced][ce-37115] in GitLab 10.0.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
This is a step-by-step guide to deploying a project hosted on GitLab.com to
|
|
|
|
|
Google Cloud, using Auto DevOps.
|
|
|
|
|
|
|
|
|
|
We made a minimal [Ruby
|
2017-09-21 09:33:59 -04:00
|
|
|
|
application](https://gitlab.com/auto-devops-examples/minimal-ruby-app) to use
|
|
|
|
|
as an example for this guide. It contains two main files:
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
* `server.rb` - our application. It will start an HTTP server on port 5000 and
|
|
|
|
|
render "Hello, world!"
|
|
|
|
|
* `Dockerfile` - to build our app into a container image. It will use a ruby
|
|
|
|
|
base image and run `server.rb`
|
|
|
|
|
|
|
|
|
|
## Fork sample project on GitLab.com
|
|
|
|
|
|
|
|
|
|
Let’s start by forking our sample application. Go to [the project
|
2017-09-12 14:22:56 -04:00
|
|
|
|
page](https://gitlab.com/auto-devops-examples/minimal-ruby-app) and press the
|
|
|
|
|
**Fork** button. Soon you should have a project under your namespace with the
|
|
|
|
|
necessary files.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
2018-05-17 08:57:49 -04:00
|
|
|
|
You can also start a new project from a
|
|
|
|
|
[GitLab project template](https://gitlab.com/gitlab-org/project-templates) if
|
|
|
|
|
you want to use a different language.
|
|
|
|
|
|
2017-11-26 11:08:08 -05:00
|
|
|
|
## Setup your own cluster on Google Kubernetes Engine
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
If you do not already have a Google Cloud account, create one at
|
|
|
|
|
https://console.cloud.google.com.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
2017-11-26 11:08:08 -05:00
|
|
|
|
Visit the [**Kubernetes Engine**](https://console.cloud.google.com/kubernetes/list)
|
2017-09-12 14:22:56 -04:00
|
|
|
|
tab and create a new cluster. You can change the name and leave the rest of the
|
|
|
|
|
default settings. Once you have your cluster running, you need to connect to the
|
|
|
|
|
cluster by following the Google interface.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
## Connect to Kubernetes cluster
|
|
|
|
|
|
|
|
|
|
You need to have the Google Cloud SDK installed. e.g.
|
2017-09-12 14:22:56 -04:00
|
|
|
|
On macOS, install [homebrew](https://brew.sh):
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
1. Install Brew Caskroom: `brew install caskroom/cask/brew-cask`
|
|
|
|
|
2. Install Google Cloud SDK: `brew cask install google-cloud-sdk`
|
2017-09-12 14:22:56 -04:00
|
|
|
|
3. Add `kubectl` with: `gcloud components install kubectl`
|
2017-09-07 16:39:09 -04:00
|
|
|
|
4. Log in: `gcloud auth login`
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
Now go back to the Google interface, find your cluster, follow the instructions
|
|
|
|
|
under "Connect to the cluster" and open the Kubernetes Dashboard. It will look
|
|
|
|
|
something like:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
gcloud container clusters get-credentials ruby-autodeploy \ --zone europe-west2-c --project api-project-XXXXXXX
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Finally, run `kubectl proxy`.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
![connect to cluster](img/guide_connect_cluster.png)
|
|
|
|
|
|
|
|
|
|
## Copy credentials to GitLab.com project
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
Once you have the Kubernetes Dashboard interface running, you should visit
|
|
|
|
|
**Secrets** under the "Config" section. There, you should find the settings we
|
|
|
|
|
need for GitLab integration: `ca.crt` and token.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
![connect to cluster](img/guide_secret.png)
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
You need to copy-paste the `ca.crt` and token into your project on GitLab.com in
|
|
|
|
|
the Kubernetes integration page under project
|
|
|
|
|
**Settings > Integrations > Project services > Kubernetes**. Don't actually copy
|
|
|
|
|
the namespace though. Each project should have a unique namespace, and by leaving
|
|
|
|
|
it blank, GitLab will create one for you.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
![connect to cluster](img/guide_integration.png)
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
For the API URL, you should use the "Endpoint" IP from your cluster page on
|
|
|
|
|
Google Cloud Platform.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
## Expose application to the world
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
In order to be able to visit your application, you need to install an NGINX
|
|
|
|
|
ingress controller and point your domain name to its external IP address. Let's
|
|
|
|
|
see how that's done.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
### Set up Ingress controller
|
|
|
|
|
|
|
|
|
|
You’ll need to make sure you have an ingress controller. If you don’t have one, do:
|
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
brew install kubernetes-helm
|
|
|
|
|
helm init
|
|
|
|
|
helm install --name ruby-app stable/nginx-ingress
|
|
|
|
|
```
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
This should create several services including `ruby-app-nginx-ingress-controller`.
|
|
|
|
|
You can list your services by running `kubectl get svc` to confirm that.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
### Point DNS at Cluster IP
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
Find out the external IP address of the `ruby-app-nginx-ingress-controller` by
|
|
|
|
|
running:
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
```sh
|
|
|
|
|
kubectl get svc ruby-app-nginx-ingress-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
|
|
|
|
|
```
|
|
|
|
|
|
2018-02-07 09:35:54 -05:00
|
|
|
|
NOTE: **Note:**
|
|
|
|
|
If your ingress controller has been installed in a different way, you can find
|
|
|
|
|
how to get the external IP address in the
|
|
|
|
|
[Cluster documentation](../../user/project/clusters/index.md#getting-the-external-ip-address).
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
Use this IP address to configure your DNS. This part heavily depends on your
|
|
|
|
|
preferences and domain provider. But in case you are not sure, just create an
|
|
|
|
|
A record with a wildcard host like `*.<your-domain>`.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
Use `nslookup minimal-ruby-app-staging.<yourdomain>` to confirm that domain is
|
|
|
|
|
assigned to the cluster IP.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
## Set up Auto DevOps
|
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
In your GitLab.com project, go to **Settings > CI/CD** and find the Auto DevOps
|
|
|
|
|
section. Select "Enable Auto DevOps", add in your base domain, and save.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
Next, a pipeline needs to be triggered. Since the test project doesn't have a
|
|
|
|
|
`.gitlab-ci.yml`, you need to either push a change to the repository or
|
2017-09-21 09:33:59 -04:00
|
|
|
|
manually visit `https://gitlab.com/<username>/minimal-ruby-app/pipelines/new`,
|
2017-09-12 14:22:56 -04:00
|
|
|
|
where `<username>` is your username.
|
|
|
|
|
|
|
|
|
|
This will create a new pipeline with several jobs: `build`, `test`, `codequality`,
|
|
|
|
|
and `production`. The `build` job will create a Docker image with your new
|
|
|
|
|
change and push it to the Container Registry. The `test` job will test your
|
|
|
|
|
changes, whereas the `codequality` job will run static analysis on your changes.
|
|
|
|
|
Finally, the `production` job will deploy your changes to a production application.
|
|
|
|
|
|
|
|
|
|
Once the deploy job succeeds you should be able to see your application by
|
|
|
|
|
visiting the Kubernetes dashboard. Select the namespace of your project, which
|
|
|
|
|
will look like `minimal-ruby-app-23`, but with a unique ID for your project,
|
|
|
|
|
and your app will be listed as "production" under the Deployment tab.
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
2017-09-12 14:22:56 -04:00
|
|
|
|
Once its ready, just visit `http://minimal-ruby-app.example.com` to see the
|
|
|
|
|
famous "Hello, world!"!
|
2017-09-07 16:39:09 -04:00
|
|
|
|
|
|
|
|
|
[ce-37115]: https://gitlab.com/gitlab-org/gitlab-ce/issues/37115
|