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
Changes from 1 commit
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
116 changes: 69 additions & 47 deletions content/actions/guides/deploying-to-google-kubernetes-engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,68 +11,89 @@ versions:
{% data reusables.actions.enterprise-github-hosted-runners %}

### Introduction
[Google Kubernetes Engine](https://cloud.google.com/kubernetes-engine) (GKE) is a managed Kubernetes cluster service from Google Cloud and is a great option for hosting your containerized workloads in the cloud or on premise.

This guide will show you how to use GitHub Actions to build and deploy a containerized application from Google Container Registry (GCR) to GKE.
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
To adopt this workflow, you will first need to complete the following setup steps for your [Kubernetes](https://kubernetes.io/) project. This guide assumes you already have a Dockerfile and a Kubernetes Deployment configuration file in the root of your project. See [here](https://github.com/google-github-actions/setup-gcloud/tree/master/example-workflows/gke) for a concrete example.
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).

#### Create a GKE cluster
For example, after [authenticating](https://cloud.google.com/sdk/gcloud/reference/auth/login) with the [`gcloud` CLI](https://cloud.google.com/sdk/gcloud/reference), part of the [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 \
$ gcloud container clusters create $GKE_CLUSTER \
--project=$GKE_PROJECT \
--zone=$GKE_ZONE
```
{% endraw %}

#### Enable required APIs
The Kubernetes Engine and Container Registry APIs are needed:
#### Enabling the APIs

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

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

#### Configure service account and store credentials as a secret, `GKE_SA_KEY`
Create a new service account, add roles to it, retrieve keys for it, and store it as a base64-encoded, [encrypted repository secret](https://docs.github.com/en/free-pro-team@latest/actions/reference/encrypted-secrets) named `GKE_SA_KEY`.

Also store the project ID as a secret named `GKE_PROJECT`.

{% raw %}
```bash{:copy}
# Create new service account
gcloud iam service-accounts create $SA_NAME

# Retrieve email address of service account just created
gcloud iam service-accounts list

# Add roles to service account
# Note: restrict these further in production
gcloud projects add-iam-policy-binding $GKE_PROJECT \
--member=serviceAccount:$SA_EMAIL \
--role=roles/container.admin \
--role=roles/storage.admin

# Download a JSON keyfile
gcloud iam service-accounts keys create key.json --iam-account=$SA_EMAIL

export GKE_SA_KEY=$(cat key.json | base64)
```
{% endraw %}

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

### Workflow

Now that the prerequisite steps are done, consider the following workflow, which will build and push a container image to GCR, and then use Kubernetes native tools like `kubectl` and `kustomize` to pull this image into the cluster deployment.
#### 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}
Expand All @@ -84,9 +105,9 @@ on:

env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
GKE_CLUSTER: cluster-1 # TODO: update to cluster name
GKE_ZONE: us-central1-c # TODO: update to cluster zone
DEPLOYMENT_NAME: gke-test # TODO: update to deployment name
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:
Expand Down Expand Up @@ -146,9 +167,10 @@ jobs:
{% endraw %}

### Additional resources
The following additional resources may also be of use:

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)
4. [Deploying a containerized web application](https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app)