Skip to content

Commit c1d7414

Browse files
authored
Kube (brentley#5)
* wip deployment.yml * updating to support k8s * updating deployment for k8s * trying to discover if we are in k8s * more k8s mods * experimenting with changing ports * experimenting with changing ports * experimenting with changing ports * attempts at timeouts
1 parent af8810e commit c1d7414

File tree

7 files changed

+122
-53
lines changed

7 files changed

+122
-53
lines changed

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ FROM ruby:2.5-slim
33
COPY Gemfile Gemfile.lock /usr/src/app/
44
WORKDIR /usr/src/app
55

6-
RUN apt-get update && apt-get -y install curl libgmp3-dev ruby-dev build-essential libsqlite3-dev && \
6+
RUN apt-get update && apt-get -y install curl jq libgmp3-dev ruby-dev build-essential libsqlite3-dev && \
77
bundle install && \
88
apt-get autoremove -y --purge && \
99
apt-get remove -y --auto-remove --purge ruby-dev libgmp3-dev build-essential libsqlite3-dev && \

app/controllers/application_controller.rb

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ def index
1212
begin
1313
req = Net::HTTP::Get.new(nodejs_uri.to_s)
1414
res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http|
15+
http.read_timeout = 2
16+
http.open_timeout = 2
1517
http.request(req)
1618
}
1719

@@ -30,6 +32,8 @@ def index
3032
begin
3133
crystalreq = Net::HTTP::Get.new(crystal_uri.to_s)
3234
crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http|
35+
http.read_timeout = 2
36+
http.open_timeout = 2
3337
http.request(crystalreq)
3438
}
3539

@@ -72,6 +76,11 @@ def expand_url(url)
7276
srv = resolver.getresource(host, Resolv::DNS::Resource::IN::SRV)
7377
uri.host = srv.target.to_s
7478
uri.port = srv.port.to_s
79+
logger.info "uri port is #{uri.port}"
80+
if uri.port == 0
81+
uri.port = 80
82+
logger.info "uri port is now #{uri.port}"
83+
end
7584
rescue => e
7685
logger.error e.message
7786
logger.error e.backtrace.join("\n")

app/views/application/index.html.erb

+48-48
Original file line numberDiff line numberDiff line change
@@ -30,153 +30,153 @@ body {
3030
<p style="text-align:center;"><%= image_tag "a-N-N.svg" %></p>
3131
<% end %>
3232

33-
<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
33+
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
3434
<p style="text-align:center;"><%= image_tag "a-N-N.svg" %></p>
3535
<% end %>
36-
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
36+
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
3737
<p style="text-align:center;"><%= image_tag "b-N-N.svg" %></p>
3838
<% end %>
39-
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
39+
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
4040
<p style="text-align:center;"><%= image_tag "c-N-N.svg" %></p>
4141
<% end %>
4242

43-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /no backend found/ %>
43+
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /no backend found/ %>
4444
<p style="text-align:center;"><%= image_tag "a-a-N.svg" %></p>
4545
<% end %>
46-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /no backend found/ %>
46+
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /no backend found/ %>
4747
<p style="text-align:center;"><%= image_tag "a-b-N.svg" %></p>
4848
<% end %>
49-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /no backend found/ %>
49+
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /no backend found/ %>
5050
<p style="text-align:center;"><%= image_tag "a-c-N.svg" %></p>
5151
<% end %>
52-
<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /AZ-1a/ %>
52+
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /AZ-a/ %>
5353
<p style="text-align:center;"><%= image_tag "a-N-a.svg" %></p>
5454
<% end %>
55-
<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /AZ-1b/ %>
55+
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /AZ-b/ %>
5656
<p style="text-align:center;"><%= image_tag "a-N-b.svg" %></p>
5757
<% end %>
58-
<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /AZ-1c/ %>
58+
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /AZ-c/ %>
5959
<p style="text-align:center;"><%= image_tag "a-N-c.svg" %></p>
6060
<% end %>
6161

62-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /no backend found/ %>
62+
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /no backend found/ %>
6363
<p style="text-align:center;"><%= image_tag "b-a-N.svg" %></p>
6464
<% end %>
65-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /no backend found/ %>
65+
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /no backend found/ %>
6666
<p style="text-align:center;"><%= image_tag "b-b-N.svg" %></p>
6767
<% end %>
68-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /no backend found/ %>
68+
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /no backend found/ %>
6969
<p style="text-align:center;"><%= image_tag "b-c-N.svg" %></p>
7070
<% end %>
71-
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /AZ-1a/ %>
71+
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /AZ-a/ %>
7272
<p style="text-align:center;"><%= image_tag "b-N-a.svg" %></p>
7373
<% end %>
74-
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /AZ-1b/ %>
74+
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /AZ-b/ %>
7575
<p style="text-align:center;"><%= image_tag "b-N-b.svg" %></p>
7676
<% end %>
77-
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /AZ-1c/ %>
77+
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /AZ-c/ %>
7878
<p style="text-align:center;"><%= image_tag "b-N-c.svg" %></p>
7979
<% end %>
8080

81-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /no backend found/ %>
81+
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /no backend found/ %>
8282
<p style="text-align:center;"><%= image_tag "c-a-N.svg" %></p>
8383
<% end %>
84-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /no backend found/ %>
84+
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /no backend found/ %>
8585
<p style="text-align:center;"><%= image_tag "c-b-N.svg" %></p>
8686
<% end %>
87-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /no backend found/ %>
87+
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /no backend found/ %>
8888
<p style="text-align:center;"><%= image_tag "c-c-N.svg" %></p>
8989
<% end %>
90-
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /AZ-1a/ %>
90+
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /AZ-a/ %>
9191
<p style="text-align:center;"><%= image_tag "c-N-a.svg" %></p>
9292
<% end %>
93-
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /AZ-1b/ %>
93+
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /AZ-b/ %>
9494
<p style="text-align:center;"><%= image_tag "c-N-b.svg" %></p>
9595
<% end %>
96-
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /AZ-1c/ %>
96+
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /AZ-c/ %>
9797
<p style="text-align:center;"><%= image_tag "c-N-c.svg" %></p>
9898
<% end %>
9999

100-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1a/ %>
100+
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /AZ-a/ %>
101101
<p style="text-align:center;"><%= image_tag "a-a-a.svg" %></p>
102102
<% end %>
103-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1b/ %>
103+
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /AZ-b/ %>
104104
<p style="text-align:center;"><%= image_tag "a-a-b.svg" %></p>
105105
<% end %>
106-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1c/ %>
106+
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /AZ-c/ %>
107107
<p style="text-align:center;"><%= image_tag "a-a-c.svg" %></p>
108108
<% end %>
109-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1a/ %>
109+
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /AZ-a/ %>
110110
<p style="text-align:center;"><%= image_tag "a-b-a.svg" %></p>
111111
<% end %>
112-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1b/ %>
112+
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /AZ-b/ %>
113113
<p style="text-align:center;"><%= image_tag "a-b-b.svg" %></p>
114114
<% end %>
115-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1c/ %>
115+
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /AZ-c/ %>
116116
<p style="text-align:center;"><%= image_tag "a-b-c.svg" %></p>
117117
<% end %>
118-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1a/ %>
118+
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /AZ-a/ %>
119119
<p style="text-align:center;"><%= image_tag "a-c-a.svg" %></p>
120120
<% end %>
121-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1b/ %>
121+
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /AZ-b/ %>
122122
<p style="text-align:center;"><%= image_tag "a-c-b.svg" %></p>
123123
<% end %>
124-
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1c/ %>
124+
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /AZ-c/ %>
125125
<p style="text-align:center;"><%= image_tag "a-c-c.svg" %></p>
126126
<% end %>
127127

128-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1a/ %>
128+
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /AZ-a/ %>
129129
<p style="text-align:center;"><%= image_tag "b-a-a.svg" %></p>
130130
<% end %>
131-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1b/ %>
131+
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /AZ-b/ %>
132132
<p style="text-align:center;"><%= image_tag "b-a-b.svg" %></p>
133133
<% end %>
134-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1c/ %>
134+
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /AZ-c/ %>
135135
<p style="text-align:center;"><%= image_tag "b-a-c.svg" %></p>
136136
<% end %>
137-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1a/ %>
137+
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /AZ-a/ %>
138138
<p style="text-align:center;"><%= image_tag "b-b-a.svg" %></p>
139139
<% end %>
140-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1b/ %>
140+
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /AZ-b/ %>
141141
<p style="text-align:center;"><%= image_tag "b-b-b.svg" %></p>
142142
<% end %>
143-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1c/ %>
143+
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /AZ-c/ %>
144144
<p style="text-align:center;"><%= image_tag "b-b-c.svg" %></p>
145145
<% end %>
146-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1a/ %>
146+
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /AZ-a/ %>
147147
<p style="text-align:center;"><%= image_tag "b-c-a.svg" %></p>
148148
<% end %>
149-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1b/ %>
149+
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /AZ-b/ %>
150150
<p style="text-align:center;"><%= image_tag "b-c-b.svg" %></p>
151151
<% end %>
152-
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1c/ %>
152+
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /AZ-c/ %>
153153
<p style="text-align:center;"><%= image_tag "b-c-c.svg" %></p>
154154
<% end %>
155155

156-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1a/ %>
156+
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /AZ-a/ %>
157157
<p style="text-align:center;"><%= image_tag "c-a-a.svg" %></p>
158158
<% end %>
159-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1b/ %>
159+
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /AZ-b/ %>
160160
<p style="text-align:center;"><%= image_tag "c-a-b.svg" %></p>
161161
<% end %>
162-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1c/ %>
162+
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /AZ-c/ %>
163163
<p style="text-align:center;"><%= image_tag "c-a-c.svg" %></p>
164164
<% end %>
165-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1a/ %>
165+
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /AZ-a/ %>
166166
<p style="text-align:center;"><%= image_tag "c-b-a.svg" %></p>
167167
<% end %>
168-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1b/ %>
168+
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /AZ-b/ %>
169169
<p style="text-align:center;"><%= image_tag "c-b-b.svg" %></p>
170170
<% end %>
171-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1c/ %>
171+
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /AZ-c/ %>
172172
<p style="text-align:center;"><%= image_tag "c-b-c.svg" %></p>
173173
<% end %>
174-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1a/ %>
174+
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /AZ-a/ %>
175175
<p style="text-align:center;"><%= image_tag "c-c-a.svg" %></p>
176176
<% end %>
177-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1b/ %>
177+
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /AZ-b/ %>
178178
<p style="text-align:center;"><%= image_tag "c-c-b.svg" %></p>
179179
<% end %>
180-
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1c/ %>
180+
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /AZ-c/ %>
181181
<p style="text-align:center;"><%= image_tag "c-c-c.svg" %></p>
182182
<% end %>

kubernetes/deployment.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: ecsdemo-frontend
5+
labels:
6+
app: ecsdemo-frontend
7+
namespace: default
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: ecsdemo-frontend
13+
strategy:
14+
rollingUpdate:
15+
maxSurge: 25%
16+
maxUnavailable: 25%
17+
type: RollingUpdate
18+
template:
19+
metadata:
20+
labels:
21+
app: ecsdemo-frontend
22+
spec:
23+
containers:
24+
- image: brentley/ecsdemo-frontend:latest
25+
imagePullPolicy: Always
26+
name: ecsdemo-frontend
27+
ports:
28+
- containerPort: 3000
29+
protocol: TCP
30+
env:
31+
- name: CRYSTAL_URL
32+
value: "http://ecsdemo-crystal.default.svc.cluster.local/crystal"
33+
- name: NODEJS_URL
34+
value: "http://ecsdemo-nodejs.default.svc.cluster.local/"

kubernetes/ingress.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
apiVersion: extensions/v1beta1
2+
kind: Ingress
3+
metadata:
4+
name: ecsdemo-frontend
5+
spec:
6+
backend:
7+
serviceName: ecsdemo-frontend
8+
servicePort: 80

kubernetes/service.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: ecsdemo-frontend
5+
spec:
6+
selector:
7+
app: ecsdemo-frontend
8+
type: LoadBalancer
9+
ports:
10+
- protocol: TCP
11+
port: 3000
12+
targetPort: 3000
13+

startup.sh

+9-4
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ NETWORK=$(echo ${IP} | cut -f3 -d.)
77

88
case "${NETWORK}" in
99
100)
10-
zone=1a
10+
zone=a
1111
color=Crimson
1212
;;
1313
101)
14-
zone=1b
14+
zone=b
1515
color=CornflowerBlue
1616
;;
1717
102)
18-
zone=1c
18+
zone=c
1919
color=LightGreen
2020
;;
2121
*)
@@ -24,9 +24,14 @@ case "${NETWORK}" in
2424
;;
2525
esac
2626

27+
# kubernetes sets routes differently -- so we will discover our IP differently
28+
if [[ ${IP} == "" ]]; then
29+
IP=$(hostname -i)
30+
fi
31+
2732
# Am I on ec2 instances?
2833
if [[ ${zone} == "unknown" ]]; then
29-
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | cut -f3 -d-)
34+
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
3035
fi
3136

3237
export CODE_HASH="$(cat code_hash.txt)"

0 commit comments

Comments
 (0)