Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add GKE, Amazon ECS, and Azure App Service deployment guides #2085

Merged
merged 22 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
7c5ab3e
Add GKE deployment guide
imjohnbo Dec 14, 2020
bfff856
Updating GKE workflow based on latest starter workflow
imjohnbo Dec 15, 2020
8e35ec0
Remove kustomize example
imjohnbo Dec 15, 2020
c970d5a
Add prerequisites
imjohnbo Dec 15, 2020
93de394
Added edits and structural changes to guide
Dec 16, 2020
5a43098
Small changes to the list of links
Dec 16, 2020
8837b7d
Add Amazon ECS guide
swinton Dec 14, 2020
fc4d5fb
Add Azure App Service guide
swinton Dec 14, 2020
7ba46cd
Add links to guides
swinton Dec 15, 2020
d81f474
Remove duplicated items
swinton Dec 16, 2020
d836fd1
Update content/actions/guides/deploying-to-azure-app-service.md
runleonarun Dec 16, 2020
cf968af
Merge branch 'main' into deployment-guides/add-gke
runleonarun Dec 16, 2020
9a9970d
Revise intro sentence per @imjohnbo's suggestion
lucascosti Dec 17, 2020
3ef5057
GKE article edits for lists
lucascosti Dec 17, 2020
ea9be20
Added edits and style changes to Amazon guide
lucascosti Dec 17, 2020
f7e1d81
Added edits and style changes to Azure web app guide
lucascosti Dec 17, 2020
45f810f
Replace pseudo environment variables with obvious replaceables in exa…
lucascosti Dec 17, 2020
1772d74
Fix bad link URL
lucascosti Dec 17, 2020
f810e4f
Update content/actions/guides/deploying-to-amazon-elastic-container-s…
runleonarun Dec 17, 2020
b68c1ee
Update content/actions/guides/deploying-to-amazon-elastic-container-s…
runleonarun Dec 17, 2020
8162972
Update content/actions/guides/deploying-to-amazon-elastic-container-s…
runleonarun Dec 17, 2020
3aeac43
Merge branch 'main' into deployment-guides/add-gke
runleonarun Dec 17, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 176 additions & 0 deletions content/actions/guides/deploying-to-google-kubernetes-engine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
---
title: Deploying to Google Kubernetes Engine
intro: You can deploy to Google Kubernetes Engine as part of your continuous deployment (CD) workflows.
product: '{% data reusables.gated-features.actions %}'
versions:
free-pro-team: '*'
enterprise-server: '>=2.22'
---

{% data reusables.actions.enterprise-beta %}
{% data reusables.actions.enterprise-github-hosted-runners %}

### Introduction

This guide explains how to use {% data variables.product.prodname_actions %} to build a containerized application in Google Container Registry (GCR) and deploy it to Google Kubernetes Engine (GKE).
runleonarun marked this conversation as resolved.
Show resolved Hide resolved

GKE is a managed Kubernetes cluster service from Google Cloud that can host your containerized workloads in the cloud or in your own datacenter. For more information, see [Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine).

### Prerequisites
Before you proceed with creating the workflow, you will need to complete the following steps for your Kubernetes project. This guide assumes the root of your project already has a `Dockerfile` and a Kubernetes Deployment configuration file. For an example, see [google-github-actions](https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke).

#### Creating a GKE cluster

To create the GKE cluster, you will first need to authenticate using the `gcloud` CLI. For more information on this step, see the following articles:
- [`gcloud auth login`](https://cloud.google.com/sdk/gcloud/reference/auth/login).
- [`gcloud` CLI](https://cloud.google.com/sdk/gcloud/reference).
- [`gcloud` CLI and Cloud SDK](https://cloud.google.com/sdk/gcloud#the_gcloud_cli_and_cloud_sdk).

For example:

{% raw %}
```bash{:copy}
$ gcloud container clusters create $GKE_CLUSTER \
--project=$GKE_PROJECT \
--zone=$GKE_ZONE
```
{% endraw %}

#### Enabling the APIs

Enable the Kubernetes Engine and Container Registry APIs. For example:

{% raw %}
```bash{:copy}
$ gcloud services enable \
containerregistry.googleapis.com \
container.googleapis.com
```
{% endraw %}

#### Configuring a service account and storing its credentials

This procedure demonstrates how to create the service account for your GKE integration. It explains how to create the account, add roles to it, retrieve its keys, and store them as a base64-encoded [encrypted repository secret](/actions/reference/encrypted-secrets) named `GKE_SA_KEY`.

1. Create a new service account:
{% raw %}
```
$ gcloud iam service-accounts create $SA_NAME
```
{% endraw %}
1. Retrieve the email address of the service account you just created:
{% raw %}
```
$ gcloud iam service-accounts list
```
{% endraw %}
1. Add roles to the service account. Note: Apply more restrictive roles to suit your requirements.
{% raw %}
```
$ gcloud projects add-iam-policy-binding $GKE_PROJECT \
--member=serviceAccount:$SA_EMAIL \
--role=roles/container.admin \
--role=roles/storage.admin
```
{% endraw %}
1. Download the JSON keyfile for the service account:
{% raw %}
```
$ gcloud iam service-accounts keys create key.json --iam-account=$SA_EMAIL
```
{% endraw %}
1. Store the project ID as a secret named `GKE_PROJECT`:
{% raw %}
```
$ export GKE_SA_KEY=$(cat key.json | base64)
```
{% endraw %}

#### (Optional) Configuring kustomize
Kustomize is an optional tool used for managing YAML specs. After creating a _kustomization_ file, the workflow below can be used to dynamically set fields of the image and pipe in the result to `kubectl`. For more information, see [kustomize usage](https://github.com/kubernetes-sigs/kustomize#usage).

### Creating the workflow

Once you've completed the prerequisites, you can proceed with creating the workflow.

The following example workflow demonstrates how to build a container image and push it to GCR. It then uses the Kubernetes tools (such as `kubectl` and `kustomize`) to pull the image into the cluster deployment.

{% raw %}
```yaml{:copy}
name: Build and Deploy to GKE

on:
release:
types: [created]

env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: cluster-1 # Add your cluster name here.
GKE_ZONE: us-central1-c # Add your cluster zone here.
DEPLOYMENT_NAME: gke-test # Add your deployment name here.
IMAGE: static-site

jobs:
setup-build-publish-deploy:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v2

# Setup gcloud CLI
- uses: google-github-actions/setup-gcloud@v0.2.0
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}

# Configure docker to use the gcloud command-line tool as a credential helper
- run: |-
gcloud --quiet auth configure-docker

# Get the GKE credentials so we can deploy to the cluster
- uses: google-github-actions/get-gke-credentials@v0.2.1
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
credentials: ${{ secrets.GKE_SA_KEY }}

# Build the Docker image
- name: Build
run: |-
docker build \
--tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.

# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"

# Set up kustomize
- name: Set up Kustomize
run: |-
curl -sfLo kustomize https://github.com/kubernetes-sigs/kustomize/releases/download/v3.1.0/kustomize_3.1.0_linux_amd64
chmod u+x ./kustomize

# Deploy the Docker image to the GKE cluster
- name: Deploy
run: |-
./kustomize edit set image gcr.io/PROJECT_ID/IMAGE:TAG=gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA
./kustomize build . | kubectl apply -f -
kubectl rollout status deployment/$DEPLOYMENT_NAME
kubectl get services -o wide
```
{% endraw %}

### Additional resources

For more information on the tools used in these examples, see the following documentation:

1. [GKE starter workflow](https://github.com/actions/starter-workflows/blob/master/ci/google.yml) for the full starter workflow
2. [Google GitHub actions example workflows](https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/) for more starter workflows and accompanying code
3. [Kustomize](https://kustomize.io/), the Kubernetes YAML customization engine
4. [Deploying a containerized web application](https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app)
6 changes: 6 additions & 0 deletions content/actions/guides/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ You can use {% data variables.product.prodname_actions %} to create custom conti
{% link_in_list /building-and-testing-java-with-gradle %}
{% link_in_list /building-and-testing-java-with-ant %}

### Creating custom continuous deployment workflows

You can use {% data variables.product.prodname_actions %} to create custom continuous deployment (CD) workflows that deploy projects to a number of cloud partner ecosystems.

{% link_in_list /deploying-to-google-kubernetes-engine %}

### Publishing software packages

You can automate publishing software packages as part your continuous delivery (CD) workflow. Packages can be published to any package host and to {% data reusables.gated-features.packages %}.
Expand Down