DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Continuous Deployment of Docker Apps to Kubernetes

Continuous Deployment of Docker Apps to Kubernetes

How you integrate a functioning Kubernetes Deployment ultimately depends on your Kubernetes host. Google Cloud is commonly used.

Zachary Flower user avatar by
Zachary Flower
·
Jan. 03, 17 · Opinion
Like (2)
Save
Tweet
Share
7.93K Views

Join the DZone community and get the full member experience.

Join For Free

In the first post of this series, we introduced using Kubernetes for deployments. In this post, we’ll get started with integrating Codeship into the workflow.

Given a functioning Kubernetes Deployment (remember our discussion from the last post about the difference between deployment and Kubernetes’ Deployment), how do we integrate it into our Codeship workflow? The answer to this question ultimately depends on your Kubernetes host, but because the official documentation uses Google Cloud as an example, this is the platform I’ll address.

Integrating Codeship With Kubernetes

Codeship has already built out some Google Cloud integrations into their CI Platform for Docker that we can use to authenticate and deploy new images to Google Cloud.

Before we can do anything, however, we need to create an encrypted environment file using Codeship’s CLI tool in order to authenticate to Google Cloud. Codeship already has a tutorial of how to do this, so I won’t go over it here.

The environment variables that need to be set are:

  • Google Cloud Key: GOOGLE_AUTH_JSON. 
  • Google Authentication Email: GOOGLE_AUTH_EMAIL. 
  • Google Project ID: GOOGLE_PROJECT_ID.  

Once we have an encrypted environment file (and have saved our Google Cloud environment variables to gc.env.encrypted), we next need to define the Google Cloud service in the codeship-services.yml file.

screen-shot-2016-12-21-at-7-05-03-pm

Notice that there are two services defined, rather than one. This is because one is for interacting with Google Cloud services (google_cloud_deployment), while another is used to enable Docker image push functionality to the Google Cloud Registry (gcr_dockercfg). We’ve built a turnkey version of this for you here.

This is only half of the puzzle, however. Although it creates the necessary services for interacting with Google Cloud, it doesn’t automatically deploy newly built images or update a Kubernetes Deployment.

Google Container Registry Pushing

Thanks to Codeship’s built-in push steps, deploying a Docker image to a remote registry is a pretty painless process. Using the gcr_dockercfg service defined above, all we need to do is add a step to the codeshipsteps.yml file with our Google Container Registry URL as the destination.

It’s important to remember here that we will be deploying our application image, so be sure to replace the app service name with the name of the service your own application is running on.

screen-shot-2016-12-21-at-7-09-56-pm

The parameters above should be pretty self-explanatory, but the basic idea is that the app image gets pushed up to the Google Container Registry using the previously defined gcr_dockercfg service for authentication.

While this step does push updated images to the registry, there is a problem with it as currently defined. Without a set Docker image tag, Codeship will push updated images to the latest tag. Now, this isn’t a bad thing in and of itself (in fact, it’s expected), but in order to trigger automatic Kubernetes Deployment updates, we need to be able to set a distinct tag for each push.

To accomplish this, Codeship provides an image_tag declaration that allows us to set any tag other than latest to push our image up to. Codeship has a nice list of variables that can be used for this declaration; however, to keep things simple, let’s use the current build’s Unix timestamp because it’s relatively unique and repeatable.

With the new image_tag declaration, the previous step should now look like this:

screen-shot-2016-12-21-at-7-13-14-pm

Now, when we push up our app image to the Google Container Registry, it will be tagged with the current build’s Unix timestamp.

Kubernetes Continuous Integration/Deployment Docker (software) app Google (verb) Cloud

Published at DZone with permission of Zachary Flower. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How to Cut the Release Inspection Time From 4 Days to 4 Hours
  • Explainer: Building High Performing Data Product Platform
  • Simulating and Troubleshooting StackOverflowError in Kotlin
  • NEXT.JS 13: Be Dynamic Without Limits

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: