diff options
Diffstat (limited to 'doc/ci/autodeploy/index.md')
-rw-r--r-- | doc/ci/autodeploy/index.md | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/doc/ci/autodeploy/index.md b/doc/ci/autodeploy/index.md index a714689ebd5..5272e9e8e68 100644 --- a/doc/ci/autodeploy/index.md +++ b/doc/ci/autodeploy/index.md @@ -15,6 +15,10 @@ You can use [project services][project-services] to store credentials to your infrastructure provider and they will be available during the deployment. +## Quick start + +We made a [simple guide](quick_start_guide.md) to using Auto Deploy with GitLab.com. + ## Supported templates The list of supported auto deploy templates is available in the @@ -35,6 +39,85 @@ enable [Kubernetes service][kubernetes-service]. 1. Test your deployment configuration using a [Review App][review-app] that was created automatically for you. +## Using the Kubernetes deploy example project with Nginx + +The Autodeploy templates are based on the [kubernetes-deploy][kube-deploy] +project which is used to simplify the deployment process to Kubernetes by +providing intelligent `build`, `deploy` and `destroy` commands which you can +use in your `.gitlab-ci.yml` as-is. It uses Heroku'ish build packs to do some +of the work, plus some of GitLab's own tools to package it all up. For your +convenience, a [Docker image][kube-image] is also provided. + +--- + +A simple example would be the deployment of Nginx on Kubernetes. +Consider a `nginx-deployment.yaml` file in your project with contents: + +```yaml +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: __CI_ENVIRONMENT_SLUG__ + labels: + app: __CI_ENVIRONMENT_SLUG__ + track: stable +spec: + replicas: 3 + template: + metadata: + labels: + app: __CI_ENVIRONMENT_SLUG__ + track: stable + spec: + containers: + - name: nginx + image: nginx:1.7.9 + ports: + - containerPort: 80 +``` + +The important part is where we set up `app: __CI_ENVIRONMENT_SLUG__`. As you'll +see later this is replaced by the [`CI_ENVIRONMENT_SLUG` env variable][variables]. + +The `.gitlab-ci.yml` would be: + +```yaml +image: registry.gitlab.com/gitlab-examples/kubernetes-deploy + +stages: + - deploy + +kubernetes deploy: + stage: deploy + environment: + name: production + script: + - echo "$KUBE_CA_PEM" > kube_ca.pem + - cat kube_ca.pem + - kubectl config set-cluster default-cluster --server=$KUBE_URL --certificate-authority="$(pwd)/kube_ca.pem" + - kubectl config set-credentials default-admin --token=$KUBE_TOKEN + - kubectl config set-context default-system --cluster=default-cluster --user=default-admin --namespace $KUBE_NAMESPACE + - kubectl config use-context default-system + + - sed -i "s/__CI_ENVIRONMENT_SLUG__/$CI_ENVIRONMENT_SLUG/" nginx-deployment.yaml + - cat nginx-deployment.yaml + - kubectl cluster-info + - kubectl get deployments -l app=$CI_ENVIRONMENT_SLUG + - kubectl create -f nginx-deployment.yaml || kubectl replace -f nginx-deployment.yaml +``` + +Notice that we use a couple of Kubernetes environment variables to configure +the Kubernetes cluster. These are exposed from the +[Kubernetes service](../../user/project/integrations/kubernetes.md#deployment-variables). +The most important one is the `$KUBE_NAMESPACE` which should be unique for +every project. + +Next, we replace `__CI_ENVIRONMENT_SLUG__` with the content of the +`CI_ENVIRONMENT_SLUG` variable, so that the `app` label has the correct value. + +Finally, the Nginx pod is created from the definition of the +`nginx-deployment.yaml` file. + ## Private Project Support > Experimental support [introduced][mr-2] in GitLab 9.1. @@ -67,6 +150,8 @@ PostgreSQL provisioning can be disabled by setting the variable `DISABLE_POSTGRE [kubernetes-service]: ../../user/project/integrations/kubernetes.md [docker-in-docker]: ../docker/using_docker_build.md#use-docker-in-docker-executor [review-app]: ../review_apps/index.md +[kube-image]: https://gitlab.com/gitlab-examples/kubernetes-deploy/container_registry "Kubernetes deploy Container Registry" +[kube-deploy]: https://gitlab.com/gitlab-examples/kubernetes-deploy "Kubernetes deploy example project" [container-registry]: https://docs.gitlab.com/ce/user/project/container_registry.html [postgresql]: https://www.postgresql.org/ |