Puppet Class: k8s::server

Defined in:
manifests/server.pp

Summary

Sets up a Kubernetes server instance

Overview

Parameters:

  • aggregator_ca_cert (Stdlib::Unixpath) (defaults to: "${cert_path}/aggregator-ca.pem")
  • aggregator_ca_key (Stdlib::Unixpath) (defaults to: "${cert_path}/aggregator-ca.key")
  • api_port (Integer[1]) (defaults to: 6443)

    Cluster API port

  • ca_cert (Stdlib::Unixpath) (defaults to: "${cert_path}/ca.pem")

    path to the ca cert

  • ca_key (Stdlib::Unixpath) (defaults to: "${cert_path}/ca.key")

    path to the ca key

  • cert_path (Stdlib::Unixpath) (defaults to: '/etc/kubernetes/certs')

    path to cert files

  • cluster_cidr (K8s::CIDR) (defaults to: $k8s::cluster_cidr)

    cluster cidr

  • cluster_domain (String) (defaults to: $k8s::cluster_domain)

    cluster domain name

  • direct_control_plane_url (String) (defaults to: "https://${fact('networking.ip')}:${api_port}")

    direct clust API connection

  • dns_service_address (K8s::IP_addresses) (defaults to: $k8s::dns_service_address)

    cluster dns service address

  • ensure (K8s::Ensure) (defaults to: $k8s::ensure)

    set ensure for installation or deinstallation

  • etcd_cluster_name (String[1]) (defaults to: $k8s::etcd_cluster_name)

    name of the etcd cluster for searching its nodes in the puppetdb

  • etcd_servers (Optional[Array[Stdlib::HTTPUrl]]) (defaults to: undef)

    list etcd servers if no puppetdb is used

  • firewall_type (Optional[K8s::Firewall]) (defaults to: $k8s::firewall_type)

    define the type of firewall to use

  • generate_ca (Boolean) (defaults to: false)

    initially generate ca

  • manage_certs (Boolean) (defaults to: true)

    whether to manage certs or not

  • manage_components (Boolean) (defaults to: true)

    whether to manage components or not

  • manage_crictl (Boolean) (defaults to: false)

    whether to install crictl or not

  • manage_etcd (Boolean) (defaults to: $k8s::manage_etcd)

    whether to manage etcd or not

  • manage_firewall (Boolean) (defaults to: $k8s::manage_firewall)

    whether to manage firewall or not

  • manage_kubeadm (Boolean) (defaults to: false)

    whether to install kubeadm or not

  • manage_resources (Boolean) (defaults to: true)

    whether to manage cluster internal resources or not

  • manage_signing (Boolean) (defaults to: $k8s::puppetdb_discovery)

    whether to manage cert signing or not

  • control_plane_url (String) (defaults to: $k8s::control_plane_url)

    cluster API connection

  • node_on_server (Boolean) (defaults to: true)

    whether to use controller also as nodes or not

  • puppetdb_discovery_tag (String[1]) (defaults to: $k8s::puppetdb_discovery_tag)

    enable puppetdb resource searching



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'manifests/server.pp', line 30

class k8s::server (
  K8s::Ensure $ensure  = $k8s::ensure,
  Integer[1] $api_port = 6443,

  K8s::CIDR $cluster_cidr                = $k8s::cluster_cidr,
  K8s::IP_addresses $dns_service_address = $k8s::dns_service_address,
  String $cluster_domain                 = $k8s::cluster_domain,
  String $direct_control_plane_url       = "https://${fact('networking.ip')}:${api_port}",
  String $control_plane_url              = $k8s::control_plane_url,

  Stdlib::Unixpath $cert_path          = '/etc/kubernetes/certs',
  Stdlib::Unixpath $ca_key             = "${cert_path}/ca.key",
  Stdlib::Unixpath $ca_cert            = "${cert_path}/ca.pem",
  Stdlib::Unixpath $aggregator_ca_key  = "${cert_path}/aggregator-ca.key",
  Stdlib::Unixpath $aggregator_ca_cert = "${cert_path}/aggregator-ca.pem",

  Boolean $generate_ca              = false,
  Boolean $manage_etcd              = $k8s::manage_etcd,
  Boolean $manage_firewall          = $k8s::manage_firewall,
  Boolean $manage_certs             = true,
  Boolean $manage_signing           = $k8s::puppetdb_discovery,
  Boolean $manage_components        = true,
  Boolean $manage_resources         = true,
  Boolean $node_on_server           = true,
  Boolean $manage_kubeadm           = false,
  Boolean $manage_crictl            = false,
  String[1] $puppetdb_discovery_tag = $k8s::puppetdb_discovery_tag,

  Optional[Array[Stdlib::HTTPUrl]] $etcd_servers = undef,
  Optional[K8s::Firewall] $firewall_type         = $k8s::firewall_type,
  String[1] $etcd_cluster_name                   = $k8s::etcd_cluster_name,

) {
  if $manage_etcd {
    class { 'k8s::server::etcd':
      ensure          => $ensure,
      generate_ca     => $generate_ca,
      manage_certs    => $manage_certs,
      manage_firewall => $manage_firewall,
      manage_members  => $k8s::puppetdb_discovery,
    }
  }
  if $manage_certs {
    include k8s::server::tls
  }
  if $manage_components {
    include k8s::server::apiserver
    include k8s::server::wait_online

    # XXX Think of a better way to do this
    if $control_plane_url == 'https://kubernetes:6443' {
      class { 'k8s::server::controller_manager':
        control_plane_url => 'https://localhost:6443',
      }
      class { 'k8s::server::scheduler':
        control_plane_url => 'https://localhost:6443',
      }
    } else {
      include k8s::server::controller_manager
      include k8s::server::scheduler
    }
  }
  if $manage_resources {
    include k8s::server::resources
  }

  if $ensure == 'present' and $manage_signing {
    # Needs the PuppetDB terminus installed

    $pql_query = [
      'resources[certname] {',
      'type = \'Class\' and',
      'title = \'K8s::Node::Kubelet\' and',
      "parameters.puppetdb_discovery_tag = '${puppetdb_discovery_tag}'",
      'order by certname }',
    ].join(' ')

    $cluster_nodes = puppetdb_query($pql_query)
    $cluster_nodes.each |$node| { k8s::server::tls::k8s_sign { $node['certname']: } }
  }

  include k8s::install::kubectl

  if $manage_kubeadm {
    include k8s::install::kubeadm
  }

  if $manage_crictl {
    include k8s::install::crictl
  }

  kubeconfig { '/root/.kube/config':
    ensure          => $ensure,
    server          => "https://localhost:${api_port}",
    require         => File['/root/.kube'],
    current_context => 'default',

    ca_cert         => $ca_cert,
    client_cert     => "${cert_path}/admin.pem",
    client_key      => "${cert_path}/admin.key",
  }

  if $node_on_server {
    $_dir = $k8s::server::tls::cert_path

    class { 'k8s::node':
      ensure            => $ensure,
      control_plane_url => "https://localhost:${api_port}",
      node_auth         => 'cert',
      proxy_auth        => 'cert',
      ca_cert           => $ca_cert,
      node_cert         => "${_dir}/node.pem",
      node_key          => "${_dir}/node.key",
      proxy_cert        => "${_dir}/kube-proxy.pem",
      proxy_key         => "${_dir}/kube-proxy.key",
    }
  }
}