anchor.diff:    labels:
       app: tutorial
   spec:
  +  # TODO: replace with a value that fits your application
     replicas: 3
     selector:
       matchLabels:
  
positive.code: # Deploying to Kubernetes
  
  This tutorial teaches deploying to Kubernetes. You'll need to prepare your
  agents with the required packages, cluster access, and Docker registry access
  before hand.
  
  <%= estimated_time "30 minutes" %>
  
  <%= toc %>
  
  ## Overview
  
  <%= image "final_test_pipeline.png" %>
  
  You'll automate deploys from `master` to Kubernetes by the end of the tutorial.
  
  This tutorial uses two pipelines. The first pipeline builds, tests, and pushes
  a Docker image to a registry. The second pipeline-our deploy pipeline-is
  provided a `DOCKER_IMAGE` environmentment for deployment to Kubernetes. You'll
  see how to trigger manual deployments, then link the pipelines for automated
  deployments.
  
  This tutorial assumes:
  
  1. You have an existing test pipeline that pushes a Docker image to a registry
  2. You have a Kubernetes cluster authenticated to the Docker registry
  4. Agents have `kubectl` installed
  3. Agents have `kubectl` access to the Kubernetes cluster
  
  <section class="Docs__note">
    <p>
      This setup is outside this tutorial's scope. However, you may refer to the
      <a href="#notes">notes</a> for high level advice.
    </p>
  </section>
  
  ## Create the Deploy Pipeline
  
  Buildkite supports multiple pipelines per project. The best practice is to use
  separate pipelines for testing and deploying.  Deploy pipelines are just
  like other pipelines except they're triggered by different events. You can use
  the [Github Deployment API](https://buildkite.com/blog/github-deployments) or
  [trigger steps](https://buildkite.com/docs/pipelines/trigger-step).
  
  Start by [creating a new pipline](https://buildkite.com/docs/pipelines/defining-steps)
  that uploads steps from `.buildkite/pipeline.deploy.yml`.
  
  <%= image "new_pipeline.png" %>
  
  Now, configure the Github webhook to send deployment events.
  
  <%= image "pipeline_webhook.png" %>
  
  Next, open the pipeline settings in Buildkite. Select "Trigger builds on deployments."
  
  <%= image "pipeline_settings.png" %>
  
  Finally, create `.buildkite/pipeline.deploy.yml`. A single step will do for now:
  
  ```yml
  steps:
  
negative.code: 
  echo '--- \:kubernetes\: Shipping'
  envsubst < k8s/app.yml | kubectl apply -f -
  
  
  echo '--- \:zzz\: Waiting for rollout'
  # TODO: add the wait step
  ```
  
  You can test pipeline now that everything is in place. All you need is your
  Docker image.
  
  ## Test the Pipeline
  
  Open the deployment pipline and click "New Build". Click "Options" and set the
  `DOCKER_IMAGE` environment variable.
  
  <%= image "manual_deployment.png" %>
  
  