7
7
8
8
## Install Terraform
9
9
10
- Install Terraform if it is not already installed (visit [ terraform.io] ( https://terraform.io ) for other distributions):
10
+ 1 . Install Terraform if it is not already installed (visit [ terraform.io] ( https://terraform.io ) for other distributions):
11
11
12
12
```
13
13
./terraform-install.sh
14
14
```
15
15
16
+ ## Change to the example directory
17
+
18
+ ```
19
+ cd example-gke-k8s-helm/
20
+ ```
21
+
16
22
## Set up the environment
17
23
24
+ 1 . Set the project, replace ` YOUR_PROJECT ` with your project ID:
25
+
18
26
```
19
- gcloud auth application-default login
27
+ PROJECT=YOUR_PROJECT
28
+ gcloud config set project ${PROJECT}
29
+ ```
30
+
31
+ 2 . Configure the environment for Terraform:
32
+
33
+ ```
34
+ [[ $CLOUD_SHELL ]] || gcloud auth application-default login
20
35
export GOOGLE_PROJECT=$(gcloud config get-value project)
21
36
```
22
37
38
+ 3 . Create the terraform.tfvars file:
39
+
40
+ ```
41
+ cat > terraform.tfvars <<EOF
42
+ helm_version = "$(helm version -c --short | egrep -o 'v[0-9].[0-9].[0-9]')"
43
+ acme_email = "$(gcloud config get-value account)"
44
+ EOF
45
+
46
+ cat terraform.tfvars
47
+ ```
48
+
23
49
## Enable service management API
24
50
25
51
This example creates a Cloud Endpoints service and requires that the Service Manangement API is enabled.
26
52
53
+ 1 . Enable the Service Management API:
54
+
27
55
```
28
56
gcloud services enable servicemanagement.googleapis.com
29
57
```
30
58
31
- ## Install helm
59
+ ## Install Helm
60
+
61
+ 1 . Install the latest version of Helm:
32
62
33
63
```
34
64
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > get_helm.sh
@@ -38,48 +68,49 @@ chmod 700 get_helm.sh
38
68
helm init --client-only
39
69
```
40
70
41
- ## Install the helm provider
42
-
43
- ```
44
- wget https://github.com/mcuadros/terraform-provider-helm/releases/download/v0.5.1/terraform-provider-helm_v0.5.1_$(uname | tr '[:upper:]' '[:lower:]')_amd64.tar.gz
45
- tar -xvf terraform-provider-helm*.tar.gz
46
-
47
- mkdir -p ~/.terraform.d/plugins/
48
- mv terraform-provider-helm*/terraform-provider-helm ~/.terraform.d/plugins/
49
- ```
50
-
51
- ## Create the ` terraform.tfvars ` file
71
+ 2 . Install the Terraform Helm provider:
52
72
53
73
```
54
- cat > terraform.tfvars <<EOF
55
- helm_version = "$(helm version -c --short | egrep -o 'v[0-9].[0-9].[0-9]')"
56
- acme_email = "$(gcloud config get-value account)"
57
- EOF
74
+ (
75
+ set -x; cd "$(mktemp -d)" &&
76
+ curl -fsSLO "https://github.com/mcuadros/terraform-provider-helm/releases/download/v0.5.1/terraform-provider-helm_v0.5.1_$(uname | tr '[:upper:]' '[:lower:]')_amd64.tar.gz" &&
77
+ tar -xvf terraform-provider-helm*.tar.gz &&
78
+ mkdir -p ~/.terraform.d/plugins/ &&
79
+ mv terraform-provider-helm*/terraform-provider-helm ~/.terraform.d/plugins/
80
+ )
58
81
```
59
82
60
83
## Run Terraform
61
84
62
- If you have run this example before within the last 30 days, undelete the Cloud Endpoints service named ` drupal ` :
85
+ 1 . If you have run this example before within the last 30 days, undelete the Cloud Endpoints service named ` drupal ` :
63
86
64
87
```
65
88
gcloud endpoints services undelete drupal.endpoints.$(gcloud config get-value project).cloud.goog
66
89
```
67
90
91
+ 2 . Run Terraform:
92
+
68
93
```
69
94
terraform init
70
- terraform plan
71
- terraform apply
95
+ terraform plan -out terraform.tfplan
96
+ terraform apply terraform.tfplan
72
97
```
73
98
74
99
## Testing
75
100
76
- After the Drupal pods start and are ready, open the interface by navigating to the URL:
101
+ 1 . Wait for the load balancer to be provisioned:
102
+
103
+ ```
104
+ ./test.sh
105
+ ```
106
+
107
+ 2 . After the Drupal pods start and are ready, open the interface by navigating to the URL:
77
108
78
109
```
79
- echo https:// $(terraform output endpoint)
110
+ echo $(terraform output endpoint)
80
111
```
81
112
82
- Login with the credentials displayed in the following commands:
113
+ 3 . Login with the credentials displayed in the following commands:
83
114
84
115
```
85
116
echo User: $(terraform output drupal_user)
@@ -88,19 +119,25 @@ echo Password: $(terraform output drupal_password)
88
119
89
120
## Connecting with kubectl and helm
90
121
122
+ 1 . Get the cluster credentials and configure kubectl:
123
+
91
124
```
92
125
gcloud container clusters get-credentials $(terraform output cluster_name) --zone $(terraform output cluster_zone)
126
+ ```
93
127
128
+ 2 . Verify kubectl connectivity:
129
+
130
+ ```
94
131
kubectl get pods
95
132
96
133
helm list
97
134
```
98
135
99
136
## Cleanup
100
137
101
- Delete the ` nginx-ingress ` helm release first so that the forwarding rule and firewall rule are cleaned up by the GCE controller:
138
+ 1 . Delete the ` nginx-ingress ` helm release first so that the forwarding rule and firewall rule are cleaned up by the GCE controller:
102
139
103
140
```
104
- terraform destroy -target helm_release.nginx-ingress && sleep 60 && \
141
+ terraform destroy -input=false -auto-approve - target helm_release.nginx-ingress && sleep 60 && \
105
142
terraform destroy
106
143
```
0 commit comments