Skip to content

Commit 93de394

Browse files
author
Martin Lopes
committed
Added edits and structural changes to guide
1 parent c970d5a commit 93de394

1 file changed

Lines changed: 69 additions & 47 deletions

File tree

content/actions/guides/deploying-to-google-kubernetes-engine.md

Lines changed: 69 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,68 +11,89 @@ versions:
1111
{% data reusables.actions.enterprise-github-hosted-runners %}
1212

1313
### Introduction
14-
[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.
1514

16-
This guide will show you how to use GitHub Actions to build and deploy a containerized application from Google Container Registry (GCR) to GKE.
15+
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).
16+
17+
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).
1718

1819
### Prerequisites
19-
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.
20+
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).
21+
22+
#### Creating a GKE cluster
23+
24+
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:
25+
- [`gcloud auth login`](https://cloud.google.com/sdk/gcloud/reference/auth/login).
26+
- [`gcloud` CLI](https://cloud.google.com/sdk/gcloud/reference).
27+
- [`gcloud` CLI and Cloud SDK](https://cloud.google.com/sdk/gcloud#the_gcloud_cli_and_cloud_sdk).
2028

21-
#### Create a GKE cluster
22-
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):
29+
For example:
2330

2431
{% raw %}
2532
```bash{:copy}
26-
gcloud container clusters create $GKE_CLUSTER \
33+
$ gcloud container clusters create $GKE_CLUSTER \
2734
--project=$GKE_PROJECT \
2835
--zone=$GKE_ZONE
2936
```
3037
{% endraw %}
3138

32-
#### Enable required APIs
33-
The Kubernetes Engine and Container Registry APIs are needed:
39+
#### Enabling the APIs
40+
41+
Enable the Kubernetes Engine and Container Registry APIs. For example:
3442

3543
{% raw %}
3644
```bash{:copy}
37-
gcloud services enable \
45+
$ gcloud services enable \
3846
containerregistry.googleapis.com \
3947
container.googleapis.com
4048
```
4149
{% endraw %}
4250

43-
#### Configure service account and store credentials as a secret, `GKE_SA_KEY`
44-
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`.
45-
46-
Also store the project ID as a secret named `GKE_PROJECT`.
47-
48-
{% raw %}
49-
```bash{:copy}
50-
# Create new service account
51-
gcloud iam service-accounts create $SA_NAME
52-
53-
# Retrieve email address of service account just created
54-
gcloud iam service-accounts list
55-
56-
# Add roles to service account
57-
# Note: restrict these further in production
58-
gcloud projects add-iam-policy-binding $GKE_PROJECT \
59-
--member=serviceAccount:$SA_EMAIL \
60-
--role=roles/container.admin \
61-
--role=roles/storage.admin
62-
63-
# Download a JSON keyfile
64-
gcloud iam service-accounts keys create key.json --iam-account=$SA_EMAIL
65-
66-
export GKE_SA_KEY=$(cat key.json | base64)
67-
```
68-
{% endraw %}
69-
70-
#### (Optional) Set up `kustomize`
71-
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`.
72-
73-
### Workflow
74-
75-
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.
51+
#### Configuring a service account and storing its credentials
52+
53+
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`.
54+
55+
1. Create a new service account:
56+
{% raw %}
57+
```
58+
$ gcloud iam service-accounts create $SA_NAME
59+
```
60+
{% endraw %}
61+
1. Retrieve the email address of the service account you just created:
62+
{% raw %}
63+
```
64+
$ gcloud iam service-accounts list
65+
```
66+
{% endraw %}
67+
1. Add roles to the service account. Note: Apply more restrictive roles to suit your requirements.
68+
{% raw %}
69+
```
70+
$ gcloud projects add-iam-policy-binding $GKE_PROJECT \
71+
--member=serviceAccount:$SA_EMAIL \
72+
--role=roles/container.admin \
73+
--role=roles/storage.admin
74+
```
75+
{% endraw %}
76+
1. Download the JSON keyfile for the service account:
77+
{% raw %}
78+
```
79+
$ gcloud iam service-accounts keys create key.json --iam-account=$SA_EMAIL
80+
```
81+
{% endraw %}
82+
1. Store the project ID as a secret named `GKE_PROJECT`:
83+
{% raw %}
84+
```
85+
$ export GKE_SA_KEY=$(cat key.json | base64)
86+
```
87+
{% endraw %}
88+
89+
#### (Optional) Configuring kustomize
90+
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).
91+
92+
### Creating the workflow
93+
94+
Once you've completed the prerequisites, you can proceed with creating the workflow.
95+
96+
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.
7697

7798
{% raw %}
7899
```yaml{:copy}
@@ -84,9 +105,9 @@ on:
84105
85106
env:
86107
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
87-
GKE_CLUSTER: cluster-1 # TODO: update to cluster name
88-
GKE_ZONE: us-central1-c # TODO: update to cluster zone
89-
DEPLOYMENT_NAME: gke-test # TODO: update to deployment name
108+
GKE_CLUSTER: cluster-1 # Add your cluster name here.
109+
GKE_ZONE: us-central1-c # Add your cluster zone here.
110+
DEPLOYMENT_NAME: gke-test # Add your deployment name here.
90111
IMAGE: static-site
91112
92113
jobs:
@@ -146,9 +167,10 @@ jobs:
146167
{% endraw %}
147168

148169
### Additional resources
149-
The following additional resources may also be of use:
170+
171+
For more information on the tools used in these examples, see the following documentation:
150172

151173
1. [GKE starter workflow](https://github.com/actions/starter-workflows/blob/master/ci/google.yml) for the full starter workflow
152174
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
153175
3. [Kustomize](https://kustomize.io/), the Kubernetes YAML customization engine
154-
4. [Deploying a containerized web application](https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app)
176+
4. [Deploying a containerized web application](https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app)

0 commit comments

Comments
 (0)