diff --git a/states/kubernetes/config.sls b/states/kubernetes/config.sls index 3f9dbe1..375eb80 100644 --- a/states/kubernetes/config.sls +++ b/states/kubernetes/config.sls @@ -1,2 +1,7 @@ --- {%- from "kubernetes/map.jinja" import kubernetes with context %} +{% for name in ['iptables', 'ip6tables'] %} +kubernetes-alternatives-{{ name }}: + cmd.run: + - name: "update-alternatives --set {{ name }} /usr/sbin/{{ name }}-legacy" +{% endfor %} \ No newline at end of file diff --git a/states/kubernetes/containerd.sls b/states/kubernetes/containerd.sls new file mode 100644 index 0000000..fe3be15 --- /dev/null +++ b/states/kubernetes/containerd.sls @@ -0,0 +1,13 @@ +--- +{%- from "kubernetes/map.jinja" import kubernetes with context %} +kubernetes-containerd-conf: + file.managed: + - name: /etc/containerd/config.toml + - source: salt://kubernetes/templates/config.toml.j2 + - template: jinja + - watch_in: + - service: kubernetes-containerd-service + +kubernetes-containerd-reset-cni: + file.absent: + - name: /etc/cni/net.d/10-flannel.conflist diff --git a/states/kubernetes/defaults.yaml b/states/kubernetes/defaults.yaml index f27213c..c86ed26 100644 --- a/states/kubernetes/defaults.yaml +++ b/states/kubernetes/defaults.yaml @@ -10,3 +10,7 @@ kubernetes: - ip_vs_wrr - ip_vs_sh - nf_conntrack + sysctls: + net.ipv4.ip_forward: 1 + net.ipv6.conf.all.forwarding: 1 + net.ipv6.conf.all.disable_ipv6: 0 diff --git a/states/kubernetes/init.sls b/states/kubernetes/init.sls index e91769e..f967547 100644 --- a/states/kubernetes/init.sls +++ b/states/kubernetes/init.sls @@ -2,4 +2,8 @@ include: - repos - .install - - .prepare + - .containerd + - .sysctl + - .modules + - .config + - .service diff --git a/states/kubernetes/install.sls b/states/kubernetes/install.sls index 0c90089..40a58b4 100644 --- a/states/kubernetes/install.sls +++ b/states/kubernetes/install.sls @@ -3,8 +3,12 @@ kubernetes-install-pkgs: pkg.installed: - pkgs: - - kubelet + - containerd.io + - cri-tools + - iptables - kubeadm - kubectl - - containerd + - kubelet + - kubernetes-cni + - nftables - wireguard-tools diff --git a/states/kubernetes/modules.sls b/states/kubernetes/modules.sls new file mode 100644 index 0000000..1a7f8ef --- /dev/null +++ b/states/kubernetes/modules.sls @@ -0,0 +1,13 @@ +--- +{%- from "kubernetes/map.jinja" import kubernetes with context %} +{% for module in kubernetes.required_modules %} +kubernetes-modules-load-{{ module }}: + cmd.run: + - name: modprobe {{ module }} +{% endfor %} + +kubernetes-modules-loadatstartup: + file.managed: + - name: /etc/modules-load.d/kubernetes.conf + - source: salt://kubernetes/templates/modules.j2 + - template: jinja diff --git a/states/kubernetes/prepare.sls b/states/kubernetes/prepare.sls deleted file mode 100644 index ba90404..0000000 --- a/states/kubernetes/prepare.sls +++ /dev/null @@ -1,29 +0,0 @@ ---- -{%- from "kubernetes/map.jinja" import kubernetes with context %} -kubernetes-prepare-containerd-conf: - file.managed: - - name: /etc/containerd/config.toml - - source: salt://kubernetes/templates/config.toml.j2 - - template: jinja - -kubernetes-prepare-reset-cni: - file.absent: - - name: /etc/cni/net.d/10-flannel.conflist - -{% for module in kubernetes.required_modules %} -kubernetes-modules-load-{{ module }}: - cmd.run: - - name: modprobe {{ module }} -{% endfor %} - -kubernetes-modules-loadatstartup: - file.managed: - - name: /etc/sysctl.d/10-kube.conf - - source: salt://kubernetes/templates/sysctl.conf.j2 - - template: jinja - -{% for name in ['iptables', 'ip6tables'] %} -kubernetes-alternatives-{{ name }}: - cmd.run: - - name: "update-alternatives --set {{ name }} /usr/sbin/{{ name }}-legacy" -{% endfor %} \ No newline at end of file diff --git a/states/kubernetes/service.sls b/states/kubernetes/service.sls index 3f9dbe1..67c55c6 100644 --- a/states/kubernetes/service.sls +++ b/states/kubernetes/service.sls @@ -1,2 +1,10 @@ --- {%- from "kubernetes/map.jinja" import kubernetes with context %} +kubernetes-containerd-service: + service.running: + - name: containerd + +kubernetes-systemd-resolved: + service.running: + - name: systemd-resolved + - enable: true diff --git a/states/kubernetes/sysctl.sls b/states/kubernetes/sysctl.sls new file mode 100644 index 0000000..b2d7377 --- /dev/null +++ b/states/kubernetes/sysctl.sls @@ -0,0 +1,17 @@ +--- +{%- from "kubernetes/map.jinja" import kubernetes with context %} +kubernetes-sysctls: + file.keyvalue: + - name: /etc/sysctl.conf + - key_values: +{%- for k,v in kubernetes.sysctls.items() %} + {{ k }}: {{ v }} +{%- endfor %} + - separator: '=' + - uncomment: '# ' + - key_ignore_case: True + - append_if_not_found: True + +kubernetes-sysctl-command: + cmd.run: + - name: "sysctl --system" diff --git a/states/kubernetes/templates/sysctl.conf.j2 b/states/kubernetes/templates/modules.j2 similarity index 100% rename from states/kubernetes/templates/sysctl.conf.j2 rename to states/kubernetes/templates/modules.j2