Commit c51c8fa0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Change auto deploy guide to use kubernetes template

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 5552d05d
...@@ -2,17 +2,16 @@ ...@@ -2,17 +2,16 @@
This is a step-by-step guide to deploying a project hosted on GitLab.com to Google Cloud, using Auto Deploy. This is a step-by-step guide to deploying a project hosted on GitLab.com to Google Cloud, using Auto Deploy.
We made a Ruby application to use as an example for this guide. It contains several files that we need to make auto deploy possible. We made a minimal [Ruby application](https://gitlab.com/gitlab-examples/minimal-ruby-app) to use as an example for this guide. It contains several files that we need to make auto deploy possible.
* `server.rb` - our application. It will start an HTTP server on port 5000 and render “Hello, world!” * `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` * `Dockerfile` - to build our app into a container image. It will use a ruby base image and run `server.rb`
* `.gitlab-ci.yml` - GitLab CI configuration file with only 2 jobs: build a docker image and deploy it to kubernetes
These are the absolute minimal requirement to have your application automatically build and deploy to Google Container Engine every time you push to the repository. These are the absolute minimal requirement to have your application automatically build and deploy to Google Container Engine every time you push to the repository.
### Fork sample project on GitLab.com ### Fork sample project on GitLab.com
Let’s start by forking our sample application. Go to [the project page](https://gitlab.com/gitlab-examples/ruby-autodeploy) and press the `Fork` button. In few minutes you should have a project under your namespace with all the necessary files. Let’s start by forking our sample application. Go to [the project page](https://gitlab.com/gitlab-examples/minimal-ruby-app) and press the `Fork` button. In few minutes you should have a project under your namespace with all the necessary files.
### Setup your own cluster on Google Container Engine ### Setup your own cluster on Google Container Engine
...@@ -33,7 +32,7 @@ Connect to the cluster and open Kubernetes Dashboard ...@@ -33,7 +32,7 @@ Connect to the cluster and open Kubernetes Dashboard
![connect to cluster](img/guide_connect_cluster.png) ![connect to cluster](img/guide_connect_cluster.png)
### Copy credentials to GitLab.com ### Copy credentials to GitLab.com project
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. 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.
...@@ -56,27 +55,34 @@ You’ll need to make sure you have an ingress controller. If you don’t have o ...@@ -56,27 +55,34 @@ You’ll need to make sure you have an ingress controller. If you don’t have o
```sh ```sh
brew install kubernetes-helm brew install kubernetes-helm
helm init helm init
helm install --name production stable/nginx-ingress helm install --name ruby-app stable/nginx-ingress
``` ```
This should create several services including `production-nginx-ingress-controller`. You can list your services by running `kubectl get svc` to confirm that. This should create several services including `ruby-app-nginx-ingress-controller`. You can list your services by running `kubectl get svc` to confirm that.
#### Point DNS at Cluster IP #### Point DNS at Cluster IP
Find out the external IP address of the `production-nginx-ingress-controller` by running: Find out the external IP address of the `ruby-app-nginx-ingress-controller` by running:
```sh ```sh
kubectl get svc production-nginx-ingress-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}' kubectl get svc ruby-app-nginx-ingress-controller -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
``` ```
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>`. 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>`.
Use `nslookup production.<yourdomain>` to confirm that domain is assigned to the cluster IP. Use `nslookup minimal-ruby-app-staging.<yourdomain>` to confirm that domain is assigned to the cluster IP.
### Build and run your code ### Setup Auto Deploy
Now we are going to make a change in the source code. It will create CI jobs and get your application built and deployed. Visit your project on GitLab.com and edit `.gitlab-ci.yml`. Replace `example.com` and `production.example.com` with your domain names. Visit home page of your GitLab.com project and press "Setup Auto Deploy" button.
Once submitted, your changes should create a new pipeline with 2 jobs: build and deploy. The build job will create a docker image with your new change and push it to the GitLab Container Registry. Deploy job will run this image on your cluster. 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 `ruby-autodeploy-23`, but with a unique ID for your project, and your app will be listed as “production” under the Deployment tab. ![auto deploy button](img/auto_deploy_btn.png)
Once its ready - just visit http://production.yourdomain.com to see “Hello, world!”
You will be redirected to new file page where you can apply one of the several Auto Deploy templates. Select "Kubernetes", replace "domain.example.com" with your domain name and any other adjustments you feel comfortable with.
![auto deplote template](img/auto_deploy_dropdown.png)
Once submitted, your changes should create a new pipeline with several jobs. If you made only domain changes it will be 3 jobs: build, staging and production. The build job will create a docker image with your new change and push it to the GitLab Container Registry. Staging job will deploy this image on your cluster. 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 `ruby-autodeploy-23`, but with a unique ID for your project, and your app will be listed as “staging” under the Deployment tab.
Once its ready - just visit http://minimal-ruby-app-staging.yourdomain.com to see “Hello, world!”
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment