Compare commits
4 Commits
role_kuber
...
role_kuber
| Author | SHA1 | Date | |
|---|---|---|---|
| 83507bf027 | |||
| c2dcd88420 | |||
| fbe64d43b5 | |||
| 225c38df61 |
17
kubernetes/defaults/main.yml
Normal file
17
kubernetes/defaults/main.yml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
kubernetes:
|
||||||
|
ipPool:
|
||||||
|
ipv4:
|
||||||
|
cluster_cidr: 10.42.0.0/16
|
||||||
|
service_cidr: 10.43.0.0/16
|
||||||
|
nodeip_cidr: 10.41.0.0/24
|
||||||
|
ipv6:
|
||||||
|
cluster_cidr: fd42::/56
|
||||||
|
service_cidr: fd43::/112
|
||||||
|
|
||||||
|
nodeIp_interface: <interface to grab nodeIp from>
|
||||||
|
|
||||||
|
control_plane:
|
||||||
|
dns_name: <control-plane dns-reachable-name>
|
||||||
|
|
||||||
|
shared_token: <shared token for nodes to join>
|
||||||
30
kubernetes/docs/architecture.puml
Normal file
30
kubernetes/docs/architecture.puml
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
@startuml
|
||||||
|
|
||||||
|
component netmaker as nm1
|
||||||
|
component netmaker as nm2
|
||||||
|
component ... as nm3
|
||||||
|
|
||||||
|
interface interface as if1
|
||||||
|
interface interface as if2
|
||||||
|
interface ... as if3
|
||||||
|
|
||||||
|
component kubernetes as kn1
|
||||||
|
component kubernetes as kn2
|
||||||
|
component ... as kn3
|
||||||
|
|
||||||
|
nm1 -up- if1
|
||||||
|
kn1 -down-( if1
|
||||||
|
|
||||||
|
nm2 -up- if2
|
||||||
|
kn2 -down-( if2
|
||||||
|
|
||||||
|
nm3 -up- if3
|
||||||
|
kn3 -down-( if3
|
||||||
|
|
||||||
|
nm1 -right- nm2
|
||||||
|
nm2 -right- nm3
|
||||||
|
|
||||||
|
kn1 .right. kn2
|
||||||
|
kn2 .right. kn3
|
||||||
|
|
||||||
|
@enduml
|
||||||
@@ -31,6 +31,5 @@ disabled_plugins = []
|
|||||||
# level = "info"
|
# level = "info"
|
||||||
|
|
||||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc]
|
||||||
|
|
||||||
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options]
|
||||||
SystemdCgroup = true
|
SystemdCgroup = true
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
apiVersion: helm.cattle.io/v1
|
||||||
|
kind: HelmChartConfig
|
||||||
|
metadata:
|
||||||
|
name: rke2-canal
|
||||||
|
namespace: kube-system
|
||||||
|
spec:
|
||||||
|
valuesContent: |-
|
||||||
|
flannel:
|
||||||
|
backend: "wireguard"
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
FROM golang:1-buster
|
|
||||||
|
|
||||||
# Add PPA
|
|
||||||
RUN echo "deb http://ppa.launchpad.net/dqlite/dev/ubuntu bionic main" > /etc/apt/sources.list.d/ppa_dqlite_dev_bionic.list
|
|
||||||
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 50FB3D04
|
|
||||||
# Install dependencies
|
|
||||||
RUN apt update -y && apt install -y build-essential git libraft-dev libsqlite3-dev libdqlite-dev
|
|
||||||
|
|
||||||
# Clone
|
|
||||||
RUN git clone https://github.com/canonical/k8s-dqlite --branch v1.0.4 /k8s-dqlite
|
|
||||||
WORKDIR /k8s-dqlite
|
|
||||||
|
|
||||||
# Compile
|
|
||||||
ENV CGO_LDFLAGS_ALLOW="-Wl,-z,now"
|
|
||||||
RUN go build -o k8s-dqlite -tags libsqlite3,dqlite k8s-dqlite.go
|
|
||||||
Binary file not shown.
@@ -1,3 +1,19 @@
|
|||||||
- name: reload_sysctl
|
- name: reload_sysctl
|
||||||
command: sysctl --system
|
command: sysctl --system
|
||||||
|
|
||||||
|
- name: restart_containerd
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: containerd
|
||||||
|
state: restarted
|
||||||
|
|
||||||
|
- name: reload_networking
|
||||||
|
service:
|
||||||
|
name: networking
|
||||||
|
state: restarted
|
||||||
|
async: 5
|
||||||
|
poll: 0
|
||||||
|
notify: wait_for_connection
|
||||||
|
|
||||||
|
- name: wait_for_connection
|
||||||
|
wait_for_connection:
|
||||||
|
delay: 5
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
---
|
---
|
||||||
dependencies:
|
dependencies:
|
||||||
- { role: docker }
|
- role: docker
|
||||||
|
- role: netmaker
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
- name: Deploy Cilium-CLI
|
|
||||||
ansible.builtin.unarchive:
|
|
||||||
src: https://github.com/cilium/cilium-cli/releases/latest/download/cilium-linux-amd64.tar.gz
|
|
||||||
dest: /usr/local/bin
|
|
||||||
remote_src: yes
|
|
||||||
mode: u=rwx,g=rx,o=rx
|
|
||||||
|
|
||||||
- name: Install Cilium
|
|
||||||
when: "inventory_hostname == groups['kubernetes'][0]"
|
|
||||||
command: -cilium install
|
|
||||||
environment:
|
|
||||||
KUBECONFIG: /etc/kubernetes/admin.conf
|
|
||||||
17
kubernetes/tasks/install_helm.yml
Normal file
17
kubernetes/tasks/install_helm.yml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
- name: Add Balto key
|
||||||
|
apt_key:
|
||||||
|
url: https://baltocdn.com/helm/signing.asc
|
||||||
|
state: present
|
||||||
|
|
||||||
|
- name: Add Balto Repository
|
||||||
|
apt_repository:
|
||||||
|
repo: "deb https://baltocdn.com/helm/stable/debian/ all main"
|
||||||
|
state: present
|
||||||
|
filename: kubernetes
|
||||||
|
update_cache: yes
|
||||||
|
|
||||||
|
- name: Install helm
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- helm
|
||||||
|
state: latest
|
||||||
65
kubernetes/tasks/install_rke2.yml
Normal file
65
kubernetes/tasks/install_rke2.yml
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
- name: Create rke-helm-manifests-folder
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: '/var/lib/rancher/rke2/server/manifests/'
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
|
||||||
|
- name: Deploy helm-manifests
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: 'helm-manifests/'
|
||||||
|
dest: '/var/lib/rancher/rke2/server/manifests/'
|
||||||
|
|
||||||
|
- name: Create rke-folder
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: /etc/rancher/rke2/
|
||||||
|
state: directory
|
||||||
|
mode: '0755'
|
||||||
|
|
||||||
|
- name: Deploy rke2 config
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: rke2/config.yaml.template
|
||||||
|
dest: /etc/rancher/rke2/config.yaml
|
||||||
|
|
||||||
|
- name: Install RKE2
|
||||||
|
command: bash -c "curl -sfL https://get.rke2.io | sh -"
|
||||||
|
|
||||||
|
- name: Add RKE2 environment-vars to /etc/profile.d/
|
||||||
|
blockinfile:
|
||||||
|
path: /etc/profile.d/rke2-bin.sh
|
||||||
|
marker: "# {mark} ANSIBLE MANAGED BLOCK | rke2"
|
||||||
|
block: |
|
||||||
|
export PATH="/var/lib/rancher/rke2/bin/:$PATH"
|
||||||
|
export KUBECONFIG="/etc/rancher/rke2/rke2.yaml"
|
||||||
|
create: true
|
||||||
|
|
||||||
|
- name: Enable and start rke2-server service for 1st-node
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: rke2-server
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
when: "inventory_hostname == groups['kubernetes'][0]"
|
||||||
|
|
||||||
|
- name: Waiting for kubelet to accept connections
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
port: 10250
|
||||||
|
state: started
|
||||||
|
when: "inventory_hostname == groups['kubernetes'][0]"
|
||||||
|
|
||||||
|
- name: Enable and start rke2-server service for other nodes
|
||||||
|
ansible.builtin.service:
|
||||||
|
name: rke2-server
|
||||||
|
enabled: yes
|
||||||
|
state: started
|
||||||
|
when: "inventory_hostname != groups['kubernetes'][0]"
|
||||||
|
register: rke2_start
|
||||||
|
until: "rke2_start is not failed"
|
||||||
|
retries: 2
|
||||||
|
delay: 10
|
||||||
|
|
||||||
|
- name: Waiting for kubelet to accept connections on other nodes
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
host: "{{ inventory_hostname }}"
|
||||||
|
port: 10250
|
||||||
|
state: started
|
||||||
|
when: "inventory_hostname != groups['kubernetes'][0]"
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
- name: Add Google-Cloud key
|
|
||||||
apt_key:
|
|
||||||
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Add Kubernetes Repository
|
|
||||||
apt_repository:
|
|
||||||
repo: "deb https://apt.kubernetes.io/ kubernetes-xenial main"
|
|
||||||
state: present
|
|
||||||
filename: kubernetes
|
|
||||||
update_cache: yes
|
|
||||||
|
|
||||||
- name: Install kubernetes-tools
|
|
||||||
package:
|
|
||||||
name:
|
|
||||||
- kubeadm
|
|
||||||
- kubelet
|
|
||||||
- kubectl
|
|
||||||
state: latest
|
|
||||||
|
|
||||||
- name: Hold upgrades for kubernetes-tools
|
|
||||||
dpkg_selections:
|
|
||||||
name: "{{ item }}"
|
|
||||||
selection: hold
|
|
||||||
loop:
|
|
||||||
- kubeadm
|
|
||||||
- kubelet
|
|
||||||
- kubectl
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
- name: Join other nodes to cluster
|
|
||||||
when: "inventory_hostname != groups['kubernetes'][0]"
|
|
||||||
command:
|
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
- name: Initialize Kubernetes Cluster
|
|
||||||
when: "inventory_hostname == groups['kubernetes'][0]"
|
|
||||||
command: kubeadm init --control-plane-endpoint={{ control_plane.dns_name }}
|
|
||||||
#--upload-certs
|
|
||||||
|
|
||||||
- name: Set environment-var for config
|
|
||||||
lineinfile:
|
|
||||||
dest: ~/.bashrc
|
|
||||||
line: "export KUBECONFIG=/etc/kubernetes/admin.conf"
|
|
||||||
@@ -1,9 +1,6 @@
|
|||||||
- import_tasks: ./prerequisites.yml
|
- import_tasks: ./prerequisites.yml
|
||||||
|
|
||||||
- import_tasks: ./k8s_deploy.yml
|
- import_tasks: ./install_helm.yml
|
||||||
|
|
||||||
- import_tasks: ./k8s_setup.yml
|
- import_tasks: ./install_rke2.yml
|
||||||
|
|
||||||
- import_tasks: ./deploy_cilium.yml
|
|
||||||
|
|
||||||
#- import_tasks: ./k8s_setup-cluster.yml
|
|
||||||
|
|||||||
@@ -1,21 +1,69 @@
|
|||||||
- name: Load br_netfilter kernel-module
|
#- name: Load br_netfilter kernel-module
|
||||||
modprobe:
|
# modprobe:
|
||||||
name: br_netfilter
|
# name: br_netfilter
|
||||||
state: present
|
# state: present
|
||||||
|
|
||||||
- name: Set sysctl settings for iptables bridged traffic
|
- name: Set sysctl settings for iptables bridged traffic
|
||||||
copy:
|
copy:
|
||||||
dest: "/etc/sysctl.d/kubernetes.conf"
|
dest: "/etc/sysctl.d/kubernetes.conf"
|
||||||
content: |
|
content: |
|
||||||
net.bridge.bridge-nf-call-ip6tables = 1
|
net.bridge.bridge-nf-call-ip6tables = 1
|
||||||
net.bridge.bridge-nf-call-iptables = 1
|
net.bridge.bridge-nf-call-iptables = 1
|
||||||
|
|
||||||
|
net.ipv4.conf.all.forwarding=1
|
||||||
|
net.ipv6.conf.all.forwarding=1
|
||||||
notify: reload_sysctl
|
notify: reload_sysctl
|
||||||
|
|
||||||
- import_tasks: ./prerequisites/swap.yml
|
#- name: Disable swap
|
||||||
|
# command: swapoff -a
|
||||||
|
|
||||||
- import_tasks: ./prerequisites/containerd.yml
|
- name: Install iptables
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
#- containerd
|
||||||
|
- iptables
|
||||||
|
state: latest
|
||||||
|
|
||||||
|
- name: Check if containerd-service exists & is started
|
||||||
|
service:
|
||||||
|
name: containerd
|
||||||
|
state: started
|
||||||
|
ignore_errors: true
|
||||||
|
register: containerd_status
|
||||||
|
|
||||||
|
- name: Install containerd when not exists
|
||||||
|
package:
|
||||||
|
name:
|
||||||
|
- containerd
|
||||||
|
when: containerd_status is failed
|
||||||
|
|
||||||
|
- name: Create containerd config-folder
|
||||||
|
file:
|
||||||
|
path: /etc/containerd
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Deploy containerd-config
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: containerd_config.toml
|
||||||
|
dest: /etc/containerd/config.toml
|
||||||
|
mode: u=rw,g=r,o=r
|
||||||
|
notify: restart_containerd
|
||||||
|
|
||||||
|
# todo: Move to netmaker-role as handler?
|
||||||
|
- name: Gather facts to get changes
|
||||||
|
ansible.builtin.gather_facts:
|
||||||
|
|
||||||
|
- name: Getting nodeIp-data from interface
|
||||||
|
set_fact:
|
||||||
|
nodeip_ipv4: "{{ ansible_facts[ kubernetes.ipPool.nodeIp_interface ].ipv4.address }}"
|
||||||
|
nodeip_ipv6: "{{ ansible_facts[ kubernetes.ipPool.nodeIp_interface ].ipv6[0].address }}"
|
||||||
|
|
||||||
- name: Set control-plane-dns-endpoint towards local-ip
|
- name: Set control-plane-dns-endpoint towards local-ip
|
||||||
lineinfile:
|
blockinfile:
|
||||||
dest: /etc/hosts
|
path: /etc/hosts
|
||||||
line: "{{ ansible_facts.default_ipv6.address }} k8s-control-plane.system.ruekov.eu"
|
marker: "# {mark} ANSIBLE MANAGED BLOCK | k8s"
|
||||||
|
block: |
|
||||||
|
{{ nodeip_ipv4 }} {{ kubernetes.control_plane.dns_name }}
|
||||||
|
|
||||||
|
- name: Run handlers to reload configurations
|
||||||
|
meta: flush_handlers
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
- name: Check if containerd-service exists & is started
|
|
||||||
service:
|
|
||||||
name: containerd
|
|
||||||
state: started
|
|
||||||
ignore_errors: true
|
|
||||||
register: containerd_status
|
|
||||||
|
|
||||||
- name: Install containerd when not exists
|
|
||||||
package:
|
|
||||||
name:
|
|
||||||
- containerd
|
|
||||||
when: containerd_status is failed
|
|
||||||
|
|
||||||
- name: Create containerd config-folder
|
|
||||||
file:
|
|
||||||
path: /etc/containerd
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Deploy containerd-config
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: containerd_config.toml
|
|
||||||
dest: /etc/containerd/config.toml
|
|
||||||
mode: u=rw,g=r,o=r
|
|
||||||
notify: restart_containerd
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
- name: Disable swap-mounts
|
|
||||||
replace:
|
|
||||||
path: /etc/fstab
|
|
||||||
regexp: '^([ \t]*(?!#)\S+[ \t]+swap[ \t]+.*)'
|
|
||||||
replace: '# \1'
|
|
||||||
|
|
||||||
- name: Disable active swap immediately
|
|
||||||
command: swapoff -va
|
|
||||||
changed_when: "command.stdout != ''"
|
|
||||||
register: command
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{% if inventory_hostname != groups['kubernetes'][0] %}
|
|
||||||
Cluster:
|
|
||||||
{% for node in groups['kubernetes'] if node != inventory_hostname %}
|
|
||||||
- {{ node }}:29001
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
Address: 0.0.0.0:29001
|
|
||||||
16
kubernetes/templates/rke2/config.yaml.template
Normal file
16
kubernetes/templates/rke2/config.yaml.template
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
## Base ##
|
||||||
|
container-runtime-endpoint: unix:///run/containerd/containerd.sock
|
||||||
|
|
||||||
|
{% if inventory_hostname != groups['kubernetes'][0] %}
|
||||||
|
server: https://{{ kubernetes.control_plane.dns_name }}:9345
|
||||||
|
{% endif %}
|
||||||
|
token: {{ kubernetes.shared_token }}
|
||||||
|
tls-san:
|
||||||
|
- {{ kubernetes.control_plane.dns_name }}
|
||||||
|
|
||||||
|
## Networking ##
|
||||||
|
#cni: cilium
|
||||||
|
|
||||||
|
cluster-cidr: {{ kubernetes.ipPool.ipv4.cluster_cidr }},{{ kubernetes.ipPool.ipv6.cluster_cidr }}
|
||||||
|
service-cidr: {{ kubernetes.ipPool.ipv4.service_cidr }},{{ kubernetes.ipPool.ipv6.service_cidr }}
|
||||||
|
node-ip: {{ nodeip_ipv4 }},{{ nodeip_ipv6 }}
|
||||||
Reference in New Issue
Block a user