Skip to content

Commit

Permalink
Kube tool (#91)
Browse files Browse the repository at this point in the history
* weave updated

* flannel complete

* calico and clean up

* Update other_params.rb

* Update other_params.rb

* adding service api back

* adding service api back

* adding service api back

* fixing up typos

* updates for kube_api_service_ip address

* fixing bad variable name and unit test
  • Loading branch information
davejrt authored and scotty-c committed Apr 15, 2018
1 parent 0e3623c commit 1313e14
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ If you do not already have Docker installed on your workstation, install it [her

The kubetool docker image takes each of the parameters as environment variables. When run as follows it will output a `kubernetes.yaml` file in your current working directory:
```
docker run --rm -v $(pwd):/mnt -e OS=debian -e VERSION=1.9.2 -e CONTAINER_RUNTIME=docker -e CNI_PROVIDER=weave -e FQDN=kubernetes -e IP=172.17.10.101 -e BOOTSTRAP_CONTROLLER_IP=172.17.10.101 -e ETCD_INITIAL_CLUSTER="etcd-kube-master=http://172.17.10.101:2380" -e ETCD_IP="%{::ipaddress_enp0s8}" -e KUBE_API_ADVERTISE_ADDRESS="%{::ipaddress_enp0s8}" -e SERVICE_API_IP=10.96.0.1 -e INSTALL_DASHBOARD=true puppet/kubetool
docker run --rm -v $(pwd):/mnt -e OS=debian -e VERSION=1.9.2 -e CONTAINER_RUNTIME=docker -e CNI_PROVIDER=weave -e FQDN=kubernetes -e IP=172.17.10.101 -e BOOTSTRAP_CONTROLLER_IP=172.17.10.101 -e ETCD_INITIAL_CLUSTER="etcd-kube-master=http://172.17.10.101:2380" -e ETCD_IP="%{::ipaddress_enp0s8}" -e KUBE_API_ADVERTISE_ADDRESS="%{::ipaddress_enp0s8}" -e INSTALL_DASHBOARD=true puppet/kubetool
```

The parameters are:
Expand All @@ -66,7 +66,6 @@ The parameters are:
* `BOOTSTRAP_CONTROLLER_IP`: the ip address of the controller puppet will use to create things like cluster role bindings, kube dns, and the Kubernetes dashboard.
* `ETCD_INITIAL_CLUSTER`: the server addresses. When in production, include three, five, or seven nodes for etcd.
* `ETCD_IP` and `KUBE_API_ADVERTISE_ADDRESS`: the IP each etcd/apiserver instance will use on each controller. We recommend passing the fact for the interface to be used by the cluster.
* `SERVICE_API_IP`: the IP that the kubernetes service will be available on inside the cluster. Dependent on overlay network range.
* `INSTALL_DASHBOARD`: a boolean to install the dashboard or not.

The kubetool creates a `kubernetes.yaml` file. To view the file contents on
Expand Down Expand Up @@ -480,13 +479,13 @@ Defaults to `undef` (don't specify for kube-apiserver). kube_tool sets this per

The cluster service IP to use for kube-dns.

Defaults to `10.96.0.10`
Defaults to `undef`

#### `kube_api_ip`
#### `kube_api_service_ip`

The cluster service IP to use for the kube api.

Defaults to `10.96.0.1`
Defaults to `undef`

## Limitations

Expand Down
4 changes: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
# The service IP to use for kube-dns.
# Defaults to 10.96.0.10
#
# [*kube_api_ip*]
# [*kube_api_service_ip*]
# The service IP to use for the kube api.
# Defaults to 10.96.0.1
#
Expand Down Expand Up @@ -294,7 +294,7 @@
Boolean $taint_master = $kubernetes::params::taint_master,
String $node_label = $kubernetes::params::node_label,
String $kube_dns_ip = $kubernetes::params::kube_dns_ip,
String $kube_api_ip = $kubernetes::params::kube_api_ip,
String $kube_api_service_ip = $kubernetes::params::kube_api_service_ip,
String $kube_proxy_version = $kubernetes::params::kube_proxy_version,

) inherits kubernetes::params {
Expand Down
4 changes: 2 additions & 2 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
$taint_master = true
$node_label = $::hostname
$cluster_service_cidr = undef
$kube_api_ip = '10.96.0.1'
$kube_dns_ip = '10.96.0.10'
$kube_api_service_ip = undef
$kube_dns_ip = undef

}
14 changes: 11 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
context 'with controller => true and worker => true' do
let(:params) do
{ 'controller' => true,
'worker' => true
'worker' => true,
'kube_api_service_ip' => '10.96.0.1',
'kube_dns_ip' => '10.96.0.10',
}
end

Expand All @@ -25,7 +27,10 @@

context 'with controller => true' do
let(:params) do
{ 'controller' => true }
{ 'controller' => true,
'kube_api_service_ip' => '10.96.0.1',
'kube_dns_ip' => '10.96.0.10'
}
end

it { should contain_class('kubernetes') }
Expand All @@ -39,7 +44,10 @@

context 'with worker => true' do
let(:params) do
{ 'worker' => true}
{ 'worker' => true,
'kube_api_service_ip' => '10.96.0.1',
'kube_dns_ip' => '10.96.0.10'
}
end

it { should contain_class('kubernetes') }
Expand Down
2 changes: 1 addition & 1 deletion tooling/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ RUN set -x && \

WORKDIR /mnt

ENTRYPOINT ["sh", "-c", "/etc/k8s/kube_tool.rb -o ${OS} -v ${VERSION} -r ${CONTAINER_RUNTIME} -c ${CNI_PROVIDER} -f ${FQDN} -i ${IP} -b ${BOOTSTRAP_CONTROLLER_IP} -e ${ETCD_INITIAL_CLUSTER} -t ${ETCD_IP} -a ${KUBE_API_ADVERTISE_ADDRESS} -s ${SERVICE_API_IP} -d ${INSTALL_DASHBOARD}"]
ENTRYPOINT ["sh", "-c", "/etc/k8s/kube_tool.rb -o ${OS} -v ${VERSION} -r ${CONTAINER_RUNTIME} -c ${CNI_PROVIDER} -f ${FQDN} -i ${IP} -b ${BOOTSTRAP_CONTROLLER_IP} -e ${ETCD_INITIAL_CLUSTER} -t ${ETCD_IP} -a ${KUBE_API_ADVERTISE_ADDRESS} -d ${INSTALL_DASHBOARD}"]
12 changes: 4 additions & 8 deletions tooling/kube_tool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
:etcd_initial_cluster => nil,
:etcd_ip => nil,
:kube_api_advertise_address => nil,
:kube_api_cluster_address => nil,
:install_dashboard => nil
:install_dashboard => nil,
:kube_api_service_ip => '10.96.0.1'
}

parser = OptionParser.new do|opts|
Expand Down Expand Up @@ -63,10 +63,6 @@
options[:kube_api_advertise_address] = api_address;
end

opts.on('-s', '--cluster-api-address cluster_api_address', 'the ClusterIP address that kube api will listen on internally') do |cluster_api_address|
options[:kube_api_cluster_address] = cluster_api_address;
end

opts.on('-d', '--install-dashboard dashboard', 'install the kube dashboard') do |dashboard|
options[:install_dashboard] = dashboard;
end
Expand All @@ -82,10 +78,10 @@

class Kube_tool
def build_hiera(hash)
OtherParams.create(hash[:os], hash[:version], hash[:container_runtime], hash[:cni_provider], hash[:bootstrap_controller_ip], hash[:fqdn], hash[:etcd_initial_cluster], hash[:etcd_ip], hash[:kube_api_advertise_address], hash[:install_dashboard], hash[:kube_api_cluster_address])
OtherParams.create(hash[:os], hash[:version], hash[:container_runtime], hash[:cni_provider], hash[:bootstrap_controller_ip], hash[:fqdn], hash[:etcd_initial_cluster], hash[:etcd_ip], hash[:kube_api_advertise_address], hash[:install_dashboard], hash[:kube_api_service_ip])
PreChecks.checks
CreateCerts.ca
CreateCerts.api_servers(hash[:fqdn], hash[:ip], hash[:bootstrap_controller_ip], hash[:kube_api_cluster_address])
CreateCerts.api_servers(hash[:fqdn], hash[:ip], hash[:bootstrap_controller_ip], hash[:kube_api_service_ip])
PreChecks.checks
CreateCerts.sa
CreateCerts.admin
Expand Down
17 changes: 10 additions & 7 deletions tooling/kube_tool/other_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class OtherParams

def OtherParams.create(os, version, container_runtime, cni_provider, bootstrap_controller_ip, fqdn, etcd_initial_cluster, etcd_ip, kube_api_advertise_address, install_dashboard, cluster_api_address)
def OtherParams.create(os, version, container_runtime, cni_provider, bootstrap_controller_ip, fqdn, etcd_initial_cluster, etcd_ip, kube_api_advertise_address, install_dashboard, kube_api_service_ip)
if install_dashboard.match('true')
install = true
else
Expand All @@ -16,19 +16,20 @@ def OtherParams.create(os, version, container_runtime, cni_provider, bootstrap_c

cni_cluster_cidr = nil
cni_node_cidr = nil
cni_node_cidr = true
cluster_service_cidr = '10.96.0.0/12'
kube_dns_ip = '10.96.0.10'

if cni_provider.match('weave')
cni_network_provider = 'https://git.io/weave-kube-1.6'
cni_cluster_cidr = '10.32.0.0/12'
elsif
cni_provider.match('flannel')
cni_network_provider = 'https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml'
cni_cluster_cidr = '10.244.0.0/16'
cni_node_cidr = true
elsif cni_provider.match('calico')
cni_network_provider = 'https://docs.projectcalico.org/v2.6/getting-started/kubernetes/installation/hosted/kubeadm/1.6/calico.yaml'
cni_network_provider = 'https://docs.projectcalico.org/v3.0/getting-started/kubernetes/installation/hosted/kubeadm/1.7/calico.yaml'
cni_cluster_cidr = '192.168.0.0/16'
cni_node_cidr = true
elsif cni_provider.match('romana')
cni_network_provider = 'https://raw.githubusercontent.com/romana/romana/master/containerize/specs/romana-kubeadm.yml'
end

data = Hash.new
Expand All @@ -38,13 +39,15 @@ def OtherParams.create(os, version, container_runtime, cni_provider, bootstrap_c
data['kubernetes::cni_network_provider'] = cni_network_provider
data['kubernetes::cni_cluster_cidr'] = cni_cluster_cidr
data['kubernetes::cni_node_cidr'] = cni_node_cidr
data['kubernetes::cluster_service_cidr'] = cluster_service_cidr
data['kubernetes::kubernetes_fqdn'] = fqdn
data['kubernetes::bootstrap_controller_ip'] = bootstrap_controller_ip
data['kubernetes::etcd_initial_cluster'] = etcd_initial_cluster
data['kubernetes::etcd_ip'] = etcd_ip
data['kubernetes::kube_api_advertise_address'] = kube_api_advertise_address
data['kubernetes::install_dashboard'] = install
data['kubernetes::kube_api_ip'] = cluster_api_address
data['kubernetes::kube_api_service_ip'] = kube_api_service_ip
data['kubernetes::kube_dns_ip'] = kube_dns_ip
File.open("kubernetes.yaml", "w+") { |file| file.write(data.to_yaml) }

end
Expand Down

0 comments on commit 1313e14

Please sign in to comment.