mirror of
https://github.com/phfroidmont/self-hosting.git
synced 2025-12-25 13:46:59 +01:00
Use tinc for private networking
This commit is contained in:
parent
904167ec30
commit
224bdffc8b
9 changed files with 29 additions and 41 deletions
|
|
@ -1,18 +1,5 @@
|
||||||
---
|
---
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
initial_master: master1
|
|
||||||
tinc_primary_router: proxy1
|
|
||||||
vpn_interface: tun0
|
|
||||||
|
|
||||||
# Kubernetes
|
|
||||||
kubernetes_apt_key: https://packages.cloud.google.com/apt/doc/apt-key.gpg
|
|
||||||
kubernetes_apt_channel: main
|
|
||||||
kubernetes_release: xenial
|
|
||||||
kubernetes_version: 1.11.3
|
|
||||||
kubernetes_version_apt: "{{kubernetes_version}}-00"
|
|
||||||
kubernetes_port: 6443
|
|
||||||
|
|
||||||
etcd_version: "3.2.24"
|
|
||||||
|
|
||||||
harden_linux_root_password: "{{k8s_scaleway_root_password}}"
|
harden_linux_root_password: "{{k8s_scaleway_root_password}}"
|
||||||
harden_linux_deploy_user: deploy
|
harden_linux_deploy_user: deploy
|
||||||
10
inventories/staging/group_vars/all.yml
Normal file
10
inventories/staging/group_vars/all.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
kubeadm_enabled: true
|
||||||
|
kube_api_anonymous_auth: true
|
||||||
|
skip_non_kubeadm_warning: false
|
||||||
|
helm_enabled: true
|
||||||
|
ingress_nginx_enabled: true
|
||||||
|
ingress_nginx_host_network: true
|
||||||
|
ingress_nginx_nodeselector:
|
||||||
|
node-role.kubernetes.io/node: ""
|
||||||
|
cert_manager_enabled: true
|
||||||
|
|
@ -1,2 +1,6 @@
|
||||||
|
---
|
||||||
|
ip: "{{vpn_ip}}"
|
||||||
kube_network_plugin: flannel
|
kube_network_plugin: flannel
|
||||||
bin_dir: /usr/local/bin
|
bin_dir: /usr/local/bin
|
||||||
|
cluster_name: banditlair-staging
|
||||||
|
dns_domain: k8s.staging.banditlair.com
|
||||||
|
|
|
||||||
2
inventories/staging/group_vars/kube-master.yml
Normal file
2
inventories/staging/group_vars/kube-master.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
vpn_ip: 192.168.66.{{ 0 +(inventory_hostname|regex_replace('\D+','')|int) }}
|
||||||
2
inventories/staging/group_vars/kube-node.yml
Normal file
2
inventories/staging/group_vars/kube-node.yml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
vpn_ip: 192.168.66.{{ 100 +( inventory_hostname|regex_replace('\D+','')|int) }}
|
||||||
5
k8s.yml
5
k8s.yml
|
|
@ -1,4 +1,9 @@
|
||||||
---
|
---
|
||||||
|
- hosts: k8s-cluster
|
||||||
|
roles:
|
||||||
|
- role: tinc
|
||||||
|
tags: tinc
|
||||||
|
|
||||||
- name: Include kubespray tasks
|
- name: Include kubespray tasks
|
||||||
import_playbook: kubespray/cluster.yml
|
import_playbook: kubespray/cluster.yml
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,7 @@
|
||||||
---
|
---
|
||||||
api_floating_ip: 192.168.66.253
|
|
||||||
netname: meshvpn
|
netname: meshvpn
|
||||||
scw_private_domain: priv.cloud.scaleway.com
|
scw_private_domain: priv.cloud.scaleway.com
|
||||||
tinc_primary_router: proxy1
|
tinc_primary_router: master1
|
||||||
tinc_route_default_ip: 192.168.66.1
|
tinc_route_default_ip: 192.168.66.1
|
||||||
tinc_route_get_ip: 169.254.42.42
|
tinc_route_get_ip: 169.254.42.42
|
||||||
vpn_interface: tun0
|
vpn_interface: tun0
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,9 @@
|
||||||
---
|
---
|
||||||
|
- name: Install tinc
|
||||||
|
apt:
|
||||||
|
name: tinc
|
||||||
|
state: latest
|
||||||
|
|
||||||
- name: Ensure tinc netname directory exists
|
- name: Ensure tinc netname directory exists
|
||||||
file:
|
file:
|
||||||
path: /etc/tinc/{{ netname }}/hosts
|
path: /etc/tinc/{{ netname }}/hosts
|
||||||
|
|
@ -55,12 +60,7 @@
|
||||||
lineinfile:
|
lineinfile:
|
||||||
dest: /etc/tinc/{{ netname }}/hosts/{{ inventory_hostname }}
|
dest: /etc/tinc/{{ netname }}/hosts/{{ inventory_hostname }}
|
||||||
line: |-
|
line: |-
|
||||||
{%- if "k8s_proxy" in group_names -%}
|
|
||||||
{%- set interface = 'ansible_' + tinc_private_interface | default('eth0') -%}
|
|
||||||
Address = {{ vars[interface].ipv4.address }}
|
|
||||||
{%- else -%}
|
|
||||||
Address = {{ ansible_eth0.ipv4.address }}
|
Address = {{ ansible_eth0.ipv4.address }}
|
||||||
{%- endif -%}
|
|
||||||
create: yes
|
create: yes
|
||||||
notify:
|
notify:
|
||||||
- restart tinc
|
- restart tinc
|
||||||
|
|
@ -74,14 +74,6 @@
|
||||||
notify:
|
notify:
|
||||||
- restart tinc
|
- restart tinc
|
||||||
|
|
||||||
# in case of multimaster we need to add a subnet line
|
|
||||||
- name: Ensure that keepalived ip is properly set in tinc host file on k8s_masters
|
|
||||||
lineinfile:
|
|
||||||
dest: /etc/tinc/{{ netname }}/hosts/{{ inventory_hostname }}
|
|
||||||
line: "Subnet = {{ api_floating_ip }}/{{ vpn_subnet_cidr_netmask }}"
|
|
||||||
create: yes
|
|
||||||
when: groups.k8s_masters | length > 1
|
|
||||||
|
|
||||||
- name: Check whether /etc/tinc/netname/hosts/inventory_hostname contains "-----END RSA PUBLIC KEY-----"
|
- name: Check whether /etc/tinc/netname/hosts/inventory_hostname contains "-----END RSA PUBLIC KEY-----"
|
||||||
command: awk '/^-----END RSA PUBLIC KEY-----$/' /etc/tinc/{{ netname }}/hosts/{{ inventory_hostname }}
|
command: awk '/^-----END RSA PUBLIC KEY-----$/' /etc/tinc/{{ netname }}/hosts/{{ inventory_hostname }}
|
||||||
changed_when: "public_key.stdout != '-----END RSA PUBLIC KEY-----'"
|
changed_when: "public_key.stdout != '-----END RSA PUBLIC KEY-----'"
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,3 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
ifconfig {{ vpn_interface }} {{ vpn_ip }} netmask {{ vpn_netmask }}
|
ifconfig {{ vpn_interface }} {{ vpn_ip }} netmask {{ vpn_netmask }}
|
||||||
|
|
||||||
{% if inventory_hostname != tinc_primary_router %}
|
|
||||||
ROUTE_GET_IP={{ tinc_route_get_ip }}
|
|
||||||
INTERFACE=$(ip route get $ROUTE_GET_IP | head -n1 | sed -E 's/.+ dev ([^ ]+).+/\1/')
|
|
||||||
GATEWAY=$(ip route | awk '$3 == "'$INTERFACE'" { print $1 }' | cut -d'/' -f1)
|
|
||||||
|
|
||||||
ip route add 10.0.0.0/8 via $GATEWAY dev $INTERFACE
|
|
||||||
ip route add 169.254.0.0/16 via $GATEWAY dev $INTERFACE
|
|
||||||
ip route add 172.16.0.0/12 via $GATEWAY dev $INTERFACE
|
|
||||||
ip route add 192.168.0.0/16 via $GATEWAY dev $INTERFACE
|
|
||||||
|
|
||||||
ip route replace default via {{ tinc_route_default_ip }}
|
|
||||||
{% endif %}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue