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

Commit

Permalink
Add experimental load balancers support for workers powered by a spot…
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Dec 16, 2016
1 parent 1b99d35 commit 43680e0
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
47 changes: 47 additions & 0 deletions config/templates/cloud-config-worker
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ coreos:
Type=oneshot
RemainAfterExit=true
ExecStart=/opt/bin/tag-spot-instance

{{if .Experimental.LoadBalancer.Enabled}}
- name: add-to-load-balancers.service
enable: true
command: start
runtime: true
content: |
[Unit]
Description=Add this spot instance to load balancers
After=network-online.target

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/opt/bin/add-to-load-balancers
{{end}}
{{end}}

{{ if $.ElasticFileSystemID }}
Expand Down Expand Up @@ -483,6 +499,37 @@ write_files:
echo done.'

sudo rkt rm --uuid-file=/var/run/coreos/tag-spot-instance.uuid
{{if .Experimental.LoadBalancer.Enabled}}
- path: /opt/bin/add-to-load-balancers
owner: root:root
permissions: 0700
content: |
#!/bin/bash -e

instance_id=$(curl http://169.254.169.254/latest/meta-data/instance-id)

sudo rkt run \
--volume=ssl,kind=host,source=/etc/kubernetes/ssl,readOnly=false \
--mount=volume=ssl,target=/etc/kubernetes/ssl \
--uuid-file-save=/var/run/coreos/add-to-load-balancers.uuid \
--volume=dns,kind=host,source=/etc/resolv.conf,readOnly=true --mount volume=dns,target=/etc/resolv.conf \
--net=host \
--trust-keys-from-https \
--insecure-options=ondisk \
{{.AWSCliImageRepo}}:{{.AWSCliTag}} --exec=/bin/bash -- \
-vxc \
'echo adding this spot instance to load balancers; \
instance_id="'$instance_id'"; \
lbs=({{range $i, $lb := .Experimental.LoadBalancer.Names}}"{{$lb}}" {{end}}); \
add_to_lb="/usr/bin/aws --region {{.Region}} elb register-instances-with-load-balancer --instances $instance_id --load-balancer-name"; \
for lb in ${lbs[@]}; do \
echo "$lb"; \
$add_to_lb "$lb"; \
done; \
echo done.'

sudo rkt rm --uuid-file=/var/run/coreos/add-to-load-balancers.uuid
{{end}}
{{end}}

- path: /opt/bin/taint-and-uncordon
Expand Down
7 changes: 7 additions & 0 deletions nodepool/config/templates/stack-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,13 @@
"Effect": "Allow",
"Resource": "*"
},
{{if .Experimental.LoadBalancer.Enabled}}
{
"Action": "elasticloadbalancing:*",
"Effect": "Allow",
"Resource": "*"
},
{{end}}
{{end}}
{
"Action": [
Expand Down

0 comments on commit 43680e0

Please sign in to comment.