-
Notifications
You must be signed in to change notification settings - Fork 0
/
4_frontend_deployment.yaml
121 lines (119 loc) · 4.75 KB
/
4_frontend_deployment.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
-
hosts: localhost
vars_files:
- external_vars.yaml
vars:
gcloud_creds_text: "{{ lookup('pipe', 'gcloud config config-helper --format=json') }}"
gcloud_credentials: "{{ gcloud_creds_text | json_query('@') }}"
tags: create
tasks:
-
name: Gather cluster facts
gcp_container_cluster_facts:
project: "{{ gcp_project_id }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_cred_file }}"
zone: "{{gcp_zone }}"
register: clusters
-
set_fact:
cluster: "{{ clusters['items'] | selectattr('name', 'match', cluster_name) | first }}"
-
name: Create a Frontend deployment
k8s:
host: "https://{{ cluster.endpoint }}"
ca_cert: "{{ cluster.masterAuth.clusterCaCertificate }}"
#validate_certs: false
api_key: "{{ gcloud_credentials.credential.access_token }}"
namespace: "default"
definition:
apiVersion: apps/v1
kind: Deployment
metadata:
name: frontend-server
spec:
replicas: 2
selector:
matchLabels:
app: "{{ app_name }}"
role: master
tier: frontend
template:
metadata:
labels:
app: "{{ app_name }}"
role: master
tier: frontend
spec:
containers:
-
# https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.11/#container-v1-core
name: frontend
image: eu.gcr.io/networksandbox-232012/frontend
resources:
requests:
cpu: 100m
memory: 100Mi
ports:
-
containerPort: 8080
register: deployment
-
name: This is the deployment
debug:
var: deployment
-
name: Create a Frontend service
k8s:
host: "https://{{ cluster.endpoint }}"
ca_cert: "{{ cluster.masterAuth.clusterCaCertificate }}"
#validate_certs: false
api_key: "{{ gcloud_credentials.credential.access_token }}"
namespace: "default"
definition:
apiVersion: v1
kind: Service
metadata:
name: frontend-service
labels:
app: "{{ app_name }}"
role: master
tier: frontend
spec:
type: LoadBalancer
#loadBalancerIP: "YOUR.IP.ADDRESS.HERE"
ports:
-
port: 8080
targetPort: 8080
selector:
app: "{{ app_name }}"
role: master
tier: frontend
register: service
-
name: This is the service
debug:
var: service
-
name: Wait for the service external IP
k8s_facts:
host: "https://{{ cluster.endpoint }}"
ca_cert: "{{ cluster.masterAuth.clusterCaCertificate }}"
#validate_certs: false
api_key: "{{ gcloud_credentials.credential.access_token }}"
kind: Service
field_selectors:
- metadata.name=frontend-service
register: services
until: "services.resources[0].status.loadBalancer.ingress[0].ip is defined"
retries: 90
delay: 5
-
set_fact:
frontend_service_ip: "{{ services.resources[0].status.loadBalancer.ingress[0].ip }}"
-
name: This is the Frontend service IP
debug:
var: frontend_service_ip
# vim: set sw=4 ts=4 et indk= :