diff --git a/Puppetfile b/Puppetfile index 93fb901..5f0fe22 100644 --- a/Puppetfile +++ b/Puppetfile @@ -12,4 +12,5 @@ mod 'puppetlabs-stdlib', '6.6.0' mod 'puppet-augeasproviders_sysctl', '3.2.0' mod 'puppet-augeasproviders_core', '3.2.1' mod 'puppet-kmod', '3.2.0' +mod 'puppetlabs-vcsrepo', '6.1.0' diff --git a/data/k8s_base.yaml b/data/k8s_base.yaml index aebcd54..adc572e 100644 --- a/data/k8s_base.yaml +++ b/data/k8s_base.yaml @@ -7,6 +7,7 @@ kubernetes::cni_provider: flannel kubernetes::etcd_ip: "%{networking.ip}" kubernetes::kube_api_advertise_address: "%{networking.ip}" kubernetes::install_dashboard: true +kubernetes::ttl: 0h kubernetes::etcd_peers: "%{alias('terraform.tag_ip.controller')}" kubernetes::controller_address: "%{lookup('terraform.tag_ip.controller.0')}:6443" diff --git a/hiera.yaml b/hiera.yaml index 6cc5d0f..389c470 100644 --- a/hiera.yaml +++ b/hiera.yaml @@ -14,6 +14,9 @@ hierarchy: - name: "Terraform data" paths: - "terraform_data.yaml" + - name: "User data" + paths: + - "user_data.yaml" - name: "Other YAML hierarchy levels" paths: - "common.yaml" diff --git a/manifests/autoscaler.pp b/manifests/autoscaler.pp new file mode 100644 index 0000000..12445b3 --- /dev/null +++ b/manifests/autoscaler.pp @@ -0,0 +1,64 @@ +class autoscaler () +{ + $instances = lookup('terraform.instances') + + $pool_instances = $instances.filter |$name, $instance| { + 'pool' in $instance['tags'] + } + $yaml_instances = $pool_instances.map |$name, $instance| { + { + $name => { + 'specs' => $instance['specs'], + }, + } + } + + $yaml_provider = { + 'tfe' => { + 'token' => lookup('tfe_token'), + 'workspace' => lookup('tfe_workspace') + } + } + + $yaml_content = { + 'provider' => $yaml_provider, + 'instances' => $yaml_instances, + } + + file { '/etc/kubernetes/autoscaler.yaml': + content => $yaml_content.to_yaml, + } + + vcsrepo { '/etc/kubernetes/k8s-autoscaler': + ensure => present, + provider => git, + source => 'https://github.com/etiennedub/k8s-autoscaler-python.git', + } + + exec { 'autoscaler_config': + command => 'kubectl create cm externalgrpc-autoscaler-cluster-config --from-file=autoscaler.yaml --namespace=kube-system -o yaml --dry-run | kubectl apply -f -', + path => ['/usr/bin'], + cwd => '/etc/kubernetes/', + environment => ['KUBECONFIG=/etc/kubernetes/admin.conf'], + refreshonly => true, + subscribe => File['/etc/kubernetes/autoscaler.yaml'], + tries => 4, + try_sleep => 15, + timeout => 15, + } + + exec { 'autoscaler_deploy': + command => 'kubectl apply -f cluster-autoscaler-config.yaml -f ./cluster-autoscaler.yaml -f ./externalgrpc-autoscaler-service.yaml -f ./externalgrpc-autoscaler.yaml', + path => ['/usr/bin'], + cwd => '/etc/kubernetes/k8s-autoscaler/deploy', + environment => ['KUBECONFIG=/etc/kubernetes/admin.conf'], + refreshonly => true, + subscribe => Vcsrepo['/etc/kubernetes/k8s-autoscaler'], + tries => 4, + try_sleep => 15, + timeout => 15, + require => [ + Exec['autoscaler_config'], + ], + } +} diff --git a/manifests/site.pp b/manifests/site.pp index df6f408..705019a 100644 --- a/manifests/site.pp +++ b/manifests/site.pp @@ -38,6 +38,7 @@ content => inline_template($host_template) } + if 'controller' in $tags { class { 'kubernetes': controller => true, @@ -46,6 +47,10 @@ File['/etc/hosts'] ] } + class { 'autoscaler': + require => Class['kubernetes'] + } + } elsif 'worker' in $tags { class { 'kubernetes': worker => true,