Compare commits

...

5 Commits

Author SHA1 Message Date
chris 5eb79cac28 hetzner draft 2019-05-30 13:37:13 +02:00
chris a5348eed9c disable frontend 2019-05-30 13:37:13 +02:00
chris 2fc2e53cc2 no masters 2019-05-30 13:37:13 +02:00
chris 421a49f6e8 add frontend host 2019-05-30 13:37:13 +02:00
chris b0f7fe9616 empty inventory 2019-05-30 13:37:13 +02:00
20 changed files with 106 additions and 37 deletions

View File

@ -1,6 +1,6 @@
# Setup up k8s cluster # Setup up k8s cluster
currently only supports single master, stacked etcd cluster with three to six worker nodes. currently only supports single controller, stacked etcd cluster with three to six worker nodes.
run: run:

58
setup/create-servers.py Normal file
View File

@ -0,0 +1,58 @@
#!/usr/bin/env python
import yaml
import requests
ips = {}
config = yaml.load(open('hetzner-config.yaml', 'r'))
headers = {"Authorization": "Bearer {}".format(config['api_key'])}
def create_server(server_name, server_type='cx11', server_location='ngb1'):
location = input(server_name + ' location: ')
frontend = {
"name": server_name,
"server_type": server_type,
"location": server_location,
"start_after_create": True,
"image": "debian-9",
"ssh_keys": [key.get('name') for key in config.get('ssh_keys')],
"user_data": "#cloud-config\nruncmd:\n- [touch, /root/cloud-init-worked]\n",
"automount": False,
}
resp = requests.post('https://api.hetzner.cloud/v1/servers', headers=headers, json=frontend)
ip = resp.json().get('server').get('public_net').get('ipv4').get('ip')
frontend_dns = {
"ip": ip,
"dns_ptr": "{}.{}".format(server_name, config.get('domain'))
}
requests.post('https://api.hetzner.cloud/v1/servers/{}/actions/change_dns_ptr'.format(
resp.json().get('server').get('id')
), headers=headers, json=frontend_dns)
return ip
for ssh_key in config['ssh_keys']:
requests.post('https://api.hetzner.cloud/v1/ssh_keys', headers=headers, json={
"name": ssh_key.get('name'),
"public_key": ssh_key.get('pubkey'),
})
locations_req = requests.get('https://api.hetzner.cloud/v1/locations', headers=headers)
locations = [loc['name'] for loc in locations_req.json().get('locations')]
print('valid locations: {}'.format(locations))
for host in ['control01', 'control02', 'control03']:
ips[host] = server_create(host)
print("YOUR NEW INVENTORY")
print("[frontend]")
print("cluster-frontend ansible_ssh_host={}".format(ips['frontend']))
print("[control]")
print("cluster-control01 ansible_ssh_host={}".format(ips['control01']))
print("#cluster-control02 ansible_ssh_host={}".format(ips['control02']))
print("#cluster-control03 ansible_ssh_host={}".format(ips['control03']))

View File

@ -1,5 +1,5 @@
cd host_vars cd host_vars
for i in cluster-master01 cluster-master02 cluster-master03 cluster-worker01 cluster-worker02 cluster-worker03 cluster-worker04 cluster-worker05 cluster-worker06 for i in cluster-frontend cluster-control01 cluster-control02 cluster-control03 cluster-worker01 cluster-worker02 cluster-worker03 cluster-worker04 cluster-worker05 cluster-worker06
do do
sed -i "s#^wg_secret_key.*#wg_secret_key: $(wg genkey)#" ${i}.yaml sed -i "s#^wg_secret_key.*#wg_secret_key: $(wg genkey)#" ${i}.yaml
pubkey=$(cat ${i}.yaml | yq .wg_secret_key | sed 's/"//g' | wg pubkey) pubkey=$(cat ${i}.yaml | yq .wg_secret_key | sed 's/"//g' | wg pubkey)

View File

@ -0,0 +1,5 @@
api_key: "123"
domain: 'cluster.kritis.systems'
ssh_keys:
- name: your_key
pubkey: ssh-ed25519 AAAA1

View File

@ -0,0 +1,3 @@
wg_secret_key: kKQhmkBWXxSTcZX50BstuxfSfpMDgrhA1wldx1d6q0Y=
wg_public_key: vOIriQKWsL4haBCVFUCqp25ciBQrPf88CUtkMNQYGSY=
wg_ip: 10.42.23.11

View File

@ -0,0 +1,3 @@
wg_secret_key: IIn4Eiy6AXDevSIWfJwG9pme11gnC2DT/ieZuGdB+0M=
wg_public_key: +8OofyGdGtmp6/NMGsxcUfUlqctvm/GZeoGj9fNOe2w=
wg_ip: 10.42.23.12

View File

@ -0,0 +1,3 @@
wg_secret_key: YM+dYmWJxk5ccTLOLjU+4z/p1gNfMtK6gW0x2Eb8C3s=
wg_public_key: RE7Uf3uBnllAk6m5qdbuYdh/GRaoSpHTCY63pVaZF2w=
wg_ip: 10.42.23.13

View File

@ -0,0 +1,3 @@
wg_secret_key: mLZKKs1VKW33pIBZJCYZhkfeU/sSLx7h+Eqfk10ue3w=
wg_public_key: 3X5My19hXKILg0Sk6uEPprulY8mBayVbucEaMFTromw=
wg_ip: 10.42.23.1

View File

@ -1,3 +0,0 @@
wg_secret_key: uC00qKf4vbfQ1Mn/ndWFX9h3JXKDv5ijIXpjchY/2Gc=
wg_public_key: 4a0DAKvszfFGxDn8Pq9OMdyZbqiELNalF/bOU+lS4ww=
wg_ip: 10.42.23.11

View File

@ -1,3 +0,0 @@
wg_secret_key: QNqBGoi2Vd/J0Zc+s5G0y+yPFqV9kmqH9pGxb5ojDGE=
wg_public_key: 8wmpoiFyWhHEAP88dR1bBsZP7bQOKAUkNMki5S/9uFc=
wg_ip: 10.42.23.12

View File

@ -1,3 +0,0 @@
wg_secret_key: sM+AFAKPGOcXNalGCGoBbCXG9msG5qF66Wz49CVvL2A=
wg_public_key: PhCEr0T1F0ABbFN0ngkIcLQ8OXmQZj+/U3DgAsWXXA8=
wg_ip: 10.42.23.13

View File

@ -1,3 +1,3 @@
wg_secret_key: MMw5jxqi+4iO3pS1C99+Hck9jabDssQuQ3yC5Rhsgn0= wg_secret_key: MHD6h2gFkzd2VhCVZtz89Jt9SxdcxwvZRqQ1PDZYBnk=
wg_public_key: GG1AGeGLX2KiCiK+/5wH3JhHDZvKHexfZgVhyX3I8Ag= wg_public_key: WOqHy73XjVWjsyt2ZEMkJdXhtmKIx8E9/fPN3o7vcDQ=
wg_ip: 10.42.23.21 wg_ip: 10.42.23.21

View File

@ -1,3 +1,3 @@
wg_secret_key: KBMAarDchzYpPIq7J9LRUgll5jeo9wJkgjwC+tJc80Y= wg_secret_key: 4Jk5ybHjBIyigcn7NPHgkms7JY1If/R/s8tqbR77MUk=
wg_public_key: CiOc+aYn9xCvLLm2rDEE0HrfY9n/kHggwK0LNRDD0Qg= wg_public_key: QUT9iS/yxXKWWRQtLJ+AW5f3inVcwCHC3MLN4KJ3Uk4=
wg_ip: 10.42.23.22 wg_ip: 10.42.23.22

View File

@ -1,3 +1,3 @@
wg_secret_key: AE9mrGQ3jJCqdWj6ZAHu9mdULr4HyBV5vE1+Wzjo+FY= wg_secret_key: WHc8cheBKC0I57bXUsfSUFDrRoPzafSFKUb7cdThbFs=
wg_public_key: hJ2CtHqxeB321TJZD+7bzSMNA1GzEteckUb//6KzjhQ= wg_public_key: nGf7wf8CvVtp1cfdngRda22TiqTMrFQY+KeZds8gnV8=
wg_ip: 10.42.23.23 wg_ip: 10.42.23.23

View File

@ -1,3 +1,3 @@
wg_secret_key: WFMMXY1HPcIUw2I/2Z8x6wyR0r/CnGYeV6Rmyt6WbXo= wg_secret_key: 6D/qBcJV+fxouP0ljRLYBcOxDPgd25BrKy6GKQWZ+nA=
wg_public_key: Tc+GCAYefY+MJMwDVqyjLuR0JPvZMFj2xtS9oTAQvSg= wg_public_key: /HrA+19Ws+7SCDpAKnOpVhjGE7L25dez9PvApdgOIRc=
wg_ip: 10.42.23.24 wg_ip: 10.42.23.24

View File

@ -1,3 +1,3 @@
wg_secret_key: oEql4vfFXVqdI6HiSDyQsSK19Xs+IzyMrz+7gbRgWWQ= wg_secret_key: CKKgfHZ+kKLiuY3vu8ICITrZqouf1Hg3ZJuVQJHJ32o=
wg_public_key: xQozpZLyW7Gl+xYsLBvegmEtjhB7vBP2sKBJgfP22D4= wg_public_key: ZdKh3IbP32xhUmSEMiDCmT28+RtoedhoF8ycE3StGQs=
wg_ip: 10.42.23.25 wg_ip: 10.42.23.25

View File

@ -1,3 +1,3 @@
wg_secret_key: WCvlYVbX/ieEU6ZLNJcQEAl9YcHASiLMgrmkU9cUElI= wg_secret_key: aK31k1FRtBeuUwdMd5haafX8czRcz7p8Ij7Ev9BzCHo=
wg_public_key: iV+fDDW5bw9ANklUKa9Vbqi+fwJCzqebahcT7nE6PCA= wg_public_key: 1QyStXJpOGnsuLOjyOPiT1krelpZGDDrC3peGVL8BzQ=
wg_ip: 10.42.23.26 wg_ip: 10.42.23.26

View File

@ -1,12 +1,15 @@
[master] #[frontend]
cluster-master01 ansible_ssh_host=212.47.246.128 #cluster-frontend ansible_ssh_host=
#cluster-master02 ansible_ssh_host=
#cluster-master03 ansible_ssh_host= [control]
cluster-control01 ansible_ssh_host=
#cluster-control02 ansible_ssh_host=
#cluster-control03 ansible_ssh_host=
[worker] [worker]
cluster-worker01 ansible_ssh_host=51.15.238.164 cluster-worker01 ansible_ssh_host=
cluster-worker02 ansible_ssh_host=51.158.115.24 cluster-worker02 ansible_ssh_host=
cluster-worker03 ansible_ssh_host=51.158.108.159 cluster-worker03 ansible_ssh_host=
#cluster-worker04 ansible_ssh_host= #cluster-worker04 ansible_ssh_host=
#cluster-worker05 ansible_ssh_host= #cluster-worker05 ansible_ssh_host=
#cluster-worker06 ansible_ssh_host= #cluster-worker06 ansible_ssh_host=

View File

@ -106,7 +106,7 @@
name: docker name: docker
state: restarted state: restarted
- hosts: master - hosts: control
tasks: tasks:
- name: install haproxy - name: install haproxy
apt: apt:
@ -129,13 +129,13 @@
name: haproxy name: haproxy
state: restarted state: restarted
- hosts: cluster-master01 - hosts: cluster-control01
tasks: tasks:
- name: init kubeadm - name: init kubeadm
shell: kubeadm init --apiserver-advertise-address 10.42.23.11 --pod-network-cidr=10.244.0.0/16 > kubeadm.log shell: kubeadm init --apiserver-advertise-address 10.42.23.11 --pod-network-cidr=10.244.0.0/16 > kubeadm.log
args: args:
creates: kubeadm.log creates: kubeadm.log
- name: fetch kubeadm.log from master - name: fetch kubeadm.log from control
fetch: fetch:
src: kubeadm.log src: kubeadm.log
dest: kubeadm-{{ inventory_hostname }}.log dest: kubeadm-{{ inventory_hostname }}.log
@ -152,7 +152,7 @@
- hosts: worker - hosts: worker
tasks: tasks:
- name: fetch join command - name: fetch join command
command: tail -2 kubeadm-cluster-master01.log command: tail -2 kubeadm-cluster-control01.log
register: joincommand register: joincommand
delegate_to: localhost delegate_to: localhost

View File

@ -3,9 +3,9 @@ PrivateKey = {{ wg_secret_key }}
ListenPort = 51820 ListenPort = 51820
[Peer] [Peer]
Endpoint = {{ hostvars['cluster-master01'].ansible_ssh_host }}:51820 Endpoint = {{ hostvars['cluster-control01'].ansible_ssh_host }}:51820
PublicKey = {{ hostvars['cluster-master01'].wg_public_key }} PublicKey = {{ hostvars['cluster-control01'].wg_public_key }}
AllowedIPs = {{ hostvars['cluster-master01'].wg_ip }}/32 AllowedIPs = {{ hostvars['cluster-control01'].wg_ip }}/32
[Peer] [Peer]
Endpoint = {{ hostvars['cluster-worker01'].ansible_ssh_host }}:51820 Endpoint = {{ hostvars['cluster-worker01'].ansible_ssh_host }}:51820