Skip to content
This repository has been archived by the owner on Jul 27, 2021. It is now read-only.

Kube #5

Merged
merged 10 commits into from Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Expand Up @@ -3,7 +3,7 @@ FROM ruby:2.5-slim
COPY Gemfile Gemfile.lock /usr/src/app/
WORKDIR /usr/src/app

RUN apt-get update && apt-get -y install curl libgmp3-dev ruby-dev build-essential libsqlite3-dev && \
RUN apt-get update && apt-get -y install curl jq libgmp3-dev ruby-dev build-essential libsqlite3-dev && \
bundle install && \
apt-get autoremove -y --purge && \
apt-get remove -y --auto-remove --purge ruby-dev libgmp3-dev build-essential libsqlite3-dev && \
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -12,6 +12,8 @@ def index
begin
req = Net::HTTP::Get.new(nodejs_uri.to_s)
res = Net::HTTP.start(nodejs_uri.host, nodejs_uri.port) {|http|
http.read_timeout = 2
http.open_timeout = 2
http.request(req)
}

Expand All @@ -30,6 +32,8 @@ def index
begin
crystalreq = Net::HTTP::Get.new(crystal_uri.to_s)
crystalres = Net::HTTP.start(crystal_uri.host, crystal_uri.port) {|http|
http.read_timeout = 2
http.open_timeout = 2
http.request(crystalreq)
}

Expand Down Expand Up @@ -72,6 +76,11 @@ def expand_url(url)
srv = resolver.getresource(host, Resolv::DNS::Resource::IN::SRV)
uri.host = srv.target.to_s
uri.port = srv.port.to_s
logger.info "uri port is #{uri.port}"
if uri.port == 0
uri.port = 80
logger.info "uri port is now #{uri.port}"
end
rescue => e
logger.error e.message
logger.error e.backtrace.join("\n")
Expand Down
96 changes: 48 additions & 48 deletions app/views/application/index.html.erb
Expand Up @@ -30,153 +30,153 @@ body {
<p style="text-align:center;"><%= image_tag "a-N-N.svg" %></p>
<% end %>

<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "a-N-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "b-N-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "c-N-N.svg" %></p>
<% end %>

<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "a-a-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "a-b-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "a-c-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "a-N-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "a-N-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /no backend found/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-a/ and @text =~ /no backend found/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "a-N-c.svg" %></p>
<% end %>

<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "b-a-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "b-b-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "b-c-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "b-N-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "b-N-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /no backend found/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-b/ and @text =~ /no backend found/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "b-N-c.svg" %></p>
<% end %>

<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "c-a-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "c-b-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /no backend found/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /no backend found/ %>
<p style="text-align:center;"><%= image_tag "c-c-N.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "c-N-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "c-N-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /no backend found/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-c/ and @text =~ /no backend found/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "c-N-c.svg" %></p>
<% end %>

<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "a-a-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "a-a-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-a/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "a-a-c.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "a-b-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "a-b-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-b/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "a-b-c.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "a-c-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "a-c-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1a/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-a/ and @text =~ /AZ-c/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "a-c-c.svg" %></p>
<% end %>

<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "b-a-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "b-a-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-a/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "b-a-c.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "b-b-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "b-b-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-b/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "b-b-c.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "b-c-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "b-c-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1b/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-b/ and @text =~ /AZ-c/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "b-c-c.svg" %></p>
<% end %>

<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "c-a-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "c-a-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1a/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-a/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "c-a-c.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "c-b-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "c-b-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1b/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-b/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "c-b-c.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1a/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /AZ-a/ %>
<p style="text-align:center;"><%= image_tag "c-c-a.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1b/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /AZ-b/ %>
<p style="text-align:center;"><%= image_tag "c-c-b.svg" %></p>
<% end %>
<% if @az =~ /AZ-1c/ and @text =~ /AZ-1c/ and @crystal =~ /AZ-1c/ %>
<% if @az =~ /AZ-c/ and @text =~ /AZ-c/ and @crystal =~ /AZ-c/ %>
<p style="text-align:center;"><%= image_tag "c-c-c.svg" %></p>
<% end %>
34 changes: 34 additions & 0 deletions kubernetes/deployment.yaml
@@ -0,0 +1,34 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecsdemo-frontend
labels:
app: ecsdemo-frontend
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: ecsdemo-frontend
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
labels:
app: ecsdemo-frontend
spec:
containers:
- image: brentley/ecsdemo-frontend:latest
imagePullPolicy: Always
name: ecsdemo-frontend
ports:
- containerPort: 3000
protocol: TCP
env:
- name: CRYSTAL_URL
value: "http://ecsdemo-crystal.default.svc.cluster.local/crystal"
- name: NODEJS_URL
value: "http://ecsdemo-nodejs.default.svc.cluster.local/"
8 changes: 8 additions & 0 deletions kubernetes/ingress.yaml
@@ -0,0 +1,8 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: ecsdemo-frontend
spec:
backend:
serviceName: ecsdemo-frontend
servicePort: 80
13 changes: 13 additions & 0 deletions kubernetes/service.yaml
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: ecsdemo-frontend
spec:
selector:
app: ecsdemo-frontend
type: LoadBalancer
ports:
- protocol: TCP
port: 3000
targetPort: 3000

13 changes: 9 additions & 4 deletions startup.sh
Expand Up @@ -7,15 +7,15 @@ NETWORK=$(echo ${IP} | cut -f3 -d.)

case "${NETWORK}" in
100)
zone=1a
zone=a
color=Crimson
;;
101)
zone=1b
zone=b
color=CornflowerBlue
;;
102)
zone=1c
zone=c
color=LightGreen
;;
*)
Expand All @@ -24,9 +24,14 @@ case "${NETWORK}" in
;;
esac

# kubernetes sets routes differently -- so we will discover our IP differently
if [[ ${IP} == "" ]]; then
IP=$(hostname -i)
fi

# Am I on ec2 instances?
if [[ ${zone} == "unknown" ]]; then
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | cut -f3 -d-)
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
fi

export CODE_HASH="$(cat code_hash.txt)"
Expand Down