Giter Club home page Giter Club logo

gcb-to-k8s's Introduction

gcb-to-k8s

When your Cloud Build builds change states, it can trigger events about these changes and initiating a rolling update to kubernetes.

Continuous Deployment Practices

  1. Setup Google Cloud Build
  • stage: build new container image, and use short_commit_sha1 as container image's tag name.
  • production: build new container image, and use git tag_name as container image's tag name.
  1. Config and deploy this cloud function to initating rolling update to stage/prod kubernetes cluster accordingly.

Costs

This practice uses billable components of Google Cloud Platform, including:

  • Cloud Build
  • Cloud Functions
  • Cloud Pub/Sub

Before you begin

  1. Select or create a Google Cloud Platform project.
  2. Make sure that billing is enabled for your Google Cloud Platform project.
  3. Enable the Cloud Functions, Cloud Pub/Sub, and Kubernetes Engine APIs.
  4. Install and initialize the Cloud SDK.
  5. Update and install gcloud components:
gcloud components update &&
gcloud components install alpha beta

Creating the Cloud Function

Create a Cloud Storage bucket to stage your Cloud Functions files, where [STAGING_BUCKET_NAME] is a globally-unique bucket name (such as [PROJECT-ID]_cloudbuilds):

gsutil mb gs://[STAGING_BUCKET_NAME]

You should see the following output:

Creating gs://[PROJECT-ID]_cloudbuilds/[STAGING_BUCKET_NAME]...

Email notifications

The following sections walk you through setting up email notifications using the Mailgun API.

If you are new to Mailgun, follow their quickstart documentation.

Prepare Mailgun settings

  1. If you haven't already, create a Mailgun account.
  2. Add a new domain, then follow Mailgun's instructions for verifying your domain. This may take up to 48 hours.
  3. From the domains page, click your domain to open its settings page.
  4. From your domain's settings page, copy the domain's API key and save it for later use.

You must also have the following:

  • An email address for sending email. This email address can belong to the domain you provide. If you are not sure which email address to use, check with your domain provider. You can also provide an nonexistent email if you do not expect a response from the recipient, such as [email protected].
  • An email address for receiving email. The recipient can be any email address.

Rolling update k8s deployment

Put kube-config.yaml within this repo's directory.

Creating configuration

Then, create the config file in this repo's directory:

{
    "MAILGUN_API_KEY":"[API_KEY]",
    "MAILGUN_DOMAIN":"email.com",
    "MAILGUN_FROM":"[email protected]",
    "MAILGUN_TO":"[email protected]",
    "KUBE_CONFIG": "./kube-config.yaml",
    "KUBE_NAMESPACE": "default",
    "KUBE_APPLABEL": "your-k8s-app",
    "KUBE_IMAGE_NAME": "you-k8s-app",
    "KUBE_IMAGE": "gcr.io/[PROJECT-ID]/[STAGING_IMAGE_NAME]"
}

In this file, you must provide the following information:

  • MAILGUN_API_KEY, the API key you collected
  • MAILGUN_DOMAIN, the domain you added
  • MAILGUN_FROM, the email address belonging to the domain from which email is sent (even one that doesn't exist)
  • MAILGUN_TO, the email address to which email is sent
  • KUBE_CONFIG, the kubernetes config yaml file
  • KUBE_NAMESPACE, ths kubernetes namespace
  • KUBE_APPLABEL, the lable or name of the kubernetes deployment
  • KUBE_IMAGE_NAME, the container image name in the kubernetes deployment
  • KUBE_IMAGE, the container image, without tag, in the kubernetes deployment

Deploying the Cloud Function

To deploy the function, run the following command in the gcb_email directory:

gcloud functions deploy subscribe --stage-bucket [STAGING_BUCKET_NAME] --trigger-topic cloud-builds --runtime nodejs8

where [STAGING_BUCKET_NAME] is the name of your staging Cloud Storage Bucket, such as [PROJECT-ID]_cloudbuilds.

After you've completed deployment of the Cloud Function, you should receive an email notification and a k8s rolling update is performed when a build event occurs.

Based on the article of https://cloud.google.com/cloud-build/docs/configure-third-party-notifications

gcb-to-k8s's People

Contributors

tomasen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.