feat: adding rke2
- manage rke2 repos - add rke2 module (init, params, install, config, service) - exclude setting ips for cilium interfaces - split roles::infra::k8s::node -> control/compute roles - moved common k8s config into k8s.yaml - add bootstrap_node, manage server and token fields in rke2 config - manage install of helm
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
#!/usr/bin/bash
|
||||
/var/lib/rancher/rke2/bin/kubectl --kubeconfig=/etc/rancher/rke2/rke2.yaml get --raw /livez
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
apiVersion: helm.cattle.io/v1
|
||||
kind: HelmChartConfig
|
||||
metadata:
|
||||
name: rke2-cilium
|
||||
namespace: kube-system
|
||||
spec:
|
||||
valuesContent: |-
|
||||
kubeProxyReplacement: true
|
||||
k8sServiceHost: "localhost"
|
||||
k8sServicePort: "6443"
|
||||
encryption:
|
||||
enabled: true
|
||||
type: wireguard
|
||||
hubble:
|
||||
enabled: true
|
||||
relay:
|
||||
enabled: true
|
||||
ui:
|
||||
enabled: true
|
||||
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require_relative '../util/helm'
|
||||
|
||||
Facter.add(:helm_repos) do
|
||||
confine kernel: 'Linux'
|
||||
confine enc_role: [
|
||||
'roles::infra::k8s::control',
|
||||
'roles::infra::k8s::compute'
|
||||
]
|
||||
|
||||
setcode do
|
||||
Facter::Util::Helm.get_helm_repos('/usr/bin/helm')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,28 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'facter'
|
||||
require 'json'
|
||||
|
||||
# a simple helm module
|
||||
module Facter::Util::Helm
|
||||
def self.get_helm_repos(helm_cmd)
|
||||
return [] unless File.executable?(helm_cmd)
|
||||
|
||||
output = Facter::Core::Execution.execute("#{helm_cmd} repo list --output json", on_fail: nil)
|
||||
return [] if output.to_s.strip.empty?
|
||||
|
||||
parse_helm_output(output)
|
||||
rescue StandardError => e
|
||||
Facter.debug("helm_repos fact error: #{e}")
|
||||
[]
|
||||
end
|
||||
|
||||
def self.parse_helm_output(output)
|
||||
JSON.parse(output).map do |repo|
|
||||
{
|
||||
'name' => repo['name'],
|
||||
'url' => repo['url']
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,66 @@
|
||||
# config rke2
|
||||
class rke2::config (
|
||||
Enum['server', 'agent'] $node_type = $rke2::node_type,
|
||||
Stdlib::Absolutepath $config_file = $rke2::config_file,
|
||||
Hash $config_hash = $rke2::config_hash,
|
||||
Stdlib::HTTPSUrl $join_url = $rke2::join_url,
|
||||
Stdlib::Fqdn $bootstrap_node = $rke2::bootstrap_node,
|
||||
String $node_token = $rke2::node_token,
|
||||
){
|
||||
|
||||
# if agent, add token. what other fields should i add?
|
||||
# how can I add a tls secret using kubectl to add ephemeral certs.
|
||||
|
||||
# if its not the bootstrap node, add join path to config
|
||||
if $node_type == 'server' {
|
||||
if $trusted['certname'] != $bootstrap_node {
|
||||
$config = merge($config_hash, {
|
||||
server => $join_url,
|
||||
token => $node_token,
|
||||
} )
|
||||
}else{
|
||||
$config = $config_hash
|
||||
}
|
||||
} elsif $node_type == 'agent' {
|
||||
$config = merge($config_hash, {
|
||||
server => $join_url,
|
||||
token => $node_token,
|
||||
} )
|
||||
}else{
|
||||
$config = $config_hash
|
||||
}
|
||||
|
||||
# create the config file
|
||||
file { $config_file:
|
||||
ensure => file,
|
||||
content => Sensitive($config.to_yaml),
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
}
|
||||
|
||||
# create a script to verify k8s api is up (used by consul)
|
||||
file {'/usr/local/bin/check_k8s_api.sh':
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0755',
|
||||
source => 'puppet:///modules/rke2/check_k8s_api.sh'
|
||||
}
|
||||
|
||||
# symlink kubectl to path
|
||||
file {'/usr/bin/kubectl':
|
||||
ensure => link,
|
||||
target => '/var/lib/rancher/rke2/bin/kubectl',
|
||||
}
|
||||
|
||||
# manage cilium config
|
||||
file {'/var/lib/rancher/rke2/server/manifests/rke2-cilium-config.yaml':
|
||||
ensure => file,
|
||||
owner => 'root',
|
||||
group => 'root',
|
||||
mode => '0644',
|
||||
source => 'puppet:///modules/rke2/rke2-cilium-config.yaml'
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
# manage helm
|
||||
class rke2::helm (
|
||||
Stdlib::Fqdn $bootstrap_node = $rke2::bootstrap_node,
|
||||
Boolean $helm_install = $rke2::helm_install,
|
||||
Hash $helm_repos = $rke2::helm_repos
|
||||
){
|
||||
|
||||
# when installing helm, manage the repos
|
||||
if $helm_install {
|
||||
|
||||
package {'helm':
|
||||
ensure => installed,
|
||||
}
|
||||
|
||||
# on the bootstrap node only
|
||||
if $trusted['certname'] == $bootstrap_node {
|
||||
|
||||
# check if the repo already exists
|
||||
$helm_repos.each | String $repo, Stdlib::HTTPSUrl $url | {
|
||||
|
||||
# if repo isnt in repo list from helm, install it
|
||||
if ! $facts['helm_repos'].any |$existing| { $existing['name'] == $repo } {
|
||||
|
||||
exec { "helm_add_repo_${repo}":
|
||||
command => "helm repo add ${repo} ${url}",
|
||||
path => ['/usr/bin'],
|
||||
environment => [
|
||||
'KUBECONFIG=/etc/rancher/rke2/rke2.yaml',
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
# manage rke2
|
||||
class rke2 (
|
||||
Enum['server', 'agent'] $node_type = $rke2::params::node_type,
|
||||
Stdlib::Absolutepath $config_file = $rke2::params::config_file,
|
||||
Hash $config_hash = $rke2::params::config_hash,
|
||||
Stdlib::HTTPSUrl $join_url = $rke2::params::join_url,
|
||||
Stdlib::Fqdn $bootstrap_node = $rke2::params::bootstrap_node,
|
||||
String $node_token = $rke2::params::node_token,
|
||||
Boolean $helm_install = $rke2::params::helm_install,
|
||||
Hash $helm_repos = $rke2::params::helm_repos
|
||||
) inherits rke2::params {
|
||||
|
||||
include rke2::install
|
||||
include rke2::config
|
||||
include rke2::service
|
||||
include rke2::helm
|
||||
|
||||
Class['rke2::install'] -> Class['rke2::config'] -> Class['rke2::service'] -> Class['rke2::helm']
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
# install rke2
|
||||
class rke2::install (
|
||||
Enum['server', 'agent'] $node_type = $rke2::node_type,
|
||||
){
|
||||
|
||||
package {"rke2-${node_type}":
|
||||
ensure => installed,
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
# rke2 params
|
||||
class rke2::params (
|
||||
Enum['server', 'agent'] $node_type = 'agent',
|
||||
Stdlib::Absolutepath $config_file = '/etc/rancher/rke2/config.yaml',
|
||||
Hash $config_hash = {},
|
||||
Stdlib::HTTPSUrl $join_url = 'https://127.0.0.1:9345',
|
||||
Stdlib::Fqdn $bootstrap_node = 'localhost.localdomain',
|
||||
String $node_token = '',
|
||||
Boolean $helm_install = false,
|
||||
Hash $helm_repos = [],
|
||||
) {}
|
||||
@@ -0,0 +1,13 @@
|
||||
# manage rke2 service
|
||||
class rke2::service (
|
||||
Enum['server', 'agent'] $node_type = $rke2::node_type,
|
||||
Stdlib::Absolutepath $config_file = $rke2::config_file,
|
||||
){
|
||||
|
||||
service {"rke2-${node_type}":
|
||||
ensure => true,
|
||||
enable => true,
|
||||
subscribe => File[$config_file],
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user