You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/actions/guides/deploying-to-google-kubernetes-engine.md
+69-47Lines changed: 69 additions & 47 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,68 +11,89 @@ versions:
11
11
{% data reusables.actions.enterprise-github-hosted-runners %}
12
12
13
13
### 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.
15
14
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).
17
18
18
19
### 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:
-[`gcloud` CLI and Cloud SDK](https://cloud.google.com/sdk/gcloud#the_gcloud_cli_and_cloud_sdk).
20
28
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:
23
30
24
31
{% raw %}
25
32
```bash{:copy}
26
-
gcloud container clusters create $GKE_CLUSTER \
33
+
$ gcloud container clusters create $GKE_CLUSTER \
27
34
--project=$GKE_PROJECT \
28
35
--zone=$GKE_ZONE
29
36
```
30
37
{% endraw %}
31
38
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:
34
42
35
43
{% raw %}
36
44
```bash{:copy}
37
-
gcloud services enable \
45
+
$ gcloud services enable \
38
46
containerregistry.googleapis.com \
39
47
container.googleapis.com
40
48
```
41
49
{% endraw %}
42
50
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
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.
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.
76
97
77
98
{% raw %}
78
99
```yaml{:copy}
@@ -84,9 +105,9 @@ on:
84
105
85
106
env:
86
107
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.
90
111
IMAGE: static-site
91
112
92
113
jobs:
@@ -146,9 +167,10 @@ jobs:
146
167
{% endraw %}
147
168
148
169
### 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:
150
172
151
173
1.[GKE starter workflow](https://github.com/actions/starter-workflows/blob/master/ci/google.yml) for the full starter workflow
152
174
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
153
175
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