Skip to content
This repository was archived by the owner on Jan 10, 2021. It is now read-only.

Commit 22e46ba

Browse files
committed
0.1.37: Working on configuration for flannel
1 parent c5cbe24 commit 22e46ba

8 files changed

Lines changed: 368 additions & 51 deletions

File tree

.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Gem::Specification.new do |spec|
22
spec.name = 'kubinator'
3-
spec.version = '0.1.36'
3+
spec.version = '0.1.37'
44
spec.summary = "Deployment automation for Kubernetes"
55
spec.authors = ["Patrick Crummett"]
66
spec.homepage = 'https://github.com/phR0ze/kubinator'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Vagrantfile
77
logging-*
88
Gemfile.lock
99
kubectl-*
10+
config/*.conf

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ strictly the responsiblity of the user and not the developer/creator of ***kubin
2929
* [Deploy Kubernetes](#deploy-kubernetes)
3030
* [Vagrant Node Access](#vagrant-node-access)
3131
* [Troubleshooting](#trouble-shooting)
32+
* [kubeadm config](#kubeadm-config)
3233
* [Networking Validation](#networking-validation)
3334
* [Cross Node Connectivity Fails](#cross-node-connectivity-fails)
3435

@@ -178,6 +179,21 @@ scp vagrant@192.168.56.10:/etc/kubernetes/kubelet.conf .
178179

179180
## Troubleshooting <a name="troubleshooting"/></a>
180181

182+
### kubeadm config <a name="kubeadm-config"/></a>
183+
https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-config/
184+
185+
Creating a kubeadm config really seems to be the only way to configure all options needed to have a
186+
running cluster.
187+
188+
Working with kubeadm config:
189+
```bash
190+
# Print out the current config
191+
sudo kubeadm config view
192+
193+
# Print out the default config
194+
sudo kubeadm config print-default
195+
```
196+
181197
### Networking Validation <a name="networking-validation"/></a>
182198
https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/
183199

@@ -235,7 +251,7 @@ kubectl -n kube-system exec coredns-78fcdf6894-mkdck -- nslookup kubernetes.defa
235251
From host deploy BusyBox Daemonset:
236252
```bash
237253
# Deploy BusyBox daemon set
238-
kubectl apply -f debug/busybox.yaml
254+
kubectl apply -f config/busybox.yaml
239255

240256
# Check /etc/resolv.conf contents
241257
kubectl exec busybox-m2t8q -- cat /etc/resolv.conf
@@ -292,6 +308,15 @@ Research:
292308
pod non of the existing documentation works. You actually need to modify the manifest of the pod
293309
and restart it.
294310
* suggested running https://scanner.heptio.com/
311+
* https://scanner.heptio.com/ee168a38ae9833e522af2db4f7b5887e/
312+
* kubeadm init --pod-network-cidr= should apparently be setting the --cluster-cidr for kube-proxy
313+
* Set Flannl arguments --iface and --ip-masq
314+
* Tried setting in /etc/default/flanneld but since its a pod not reading that file
315+
* Validate results
316+
```bash
317+
kubectl -n kube-system get ds kube-flannel-ds -o json | jq '.spec.template.spec.containers[0].command'
318+
```
319+
* Use UDP instead of VXLAN for flannel?
295320

296321
* https://github.com/kubernetes/kubernetes/issues/45459
297322

File renamed without changes.

kubinator

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class Kubinator
117117
vars = OpenStruct.new
118118
vars.box = @box
119119
vars.nodes = specs.map{|x| ' ' + x.to_s} * ",\n"
120-
FileUtils.cp('vagrant.tpl', 'Vagrantfile')
120+
FileUtils.cp('templates/vagrant.tpl', 'Vagrantfile')
121121
FileUtils.resolve('Vagrantfile', vars)
122122

123123
# Choose a vagrant box to use and update registry if needed
@@ -175,6 +175,7 @@ class Kubinator
175175
ips = getnodes.map{|x| x.ip}
176176
all = cmd.include?('all')
177177
init = cmd.include?('init')
178+
config = cmd.include?('config')
178179
dashboard = cmd.include?('dashboard')
179180
helm = cmd.include?('helm')
180181
weave = cmd.include?('weave')
@@ -233,39 +234,14 @@ class Kubinator
233234
# Configure kubelet for each node
234235
kubelet = '/etc/default/kubelet'
235236
if not ssh.exec!("cat #{kubelet}").include?(ip)
236-
extra_args = [
237-
238-
# Configure ip address for node
239-
"--node-ip=#{ip}",
240-
241-
# Note this is the default
242-
# Configure cluster dns to use
243-
# Specific address in the kubeadm --service-cidr arg
244-
#"--cluster-dns=10.96.0.10",
245-
#"--cluster-domain=cluster.local",
246-
247-
# Cgroup driver
248-
# --cgroup-driver=systemd
249-
250-
# Seems to cause joins to fail
251-
#"--hostname-override=#{ip}"
252-
] * ' '
253-
ssh.exec!("sudo sed -i -e 's/\\(KUBELET_EXTRA_ARGS=\\)\\(.*$\\)/\\1#{extra_args} \\2/' #{kubelet}")
237+
args = ["--node-ip=#{ip}"] * ' '
238+
ssh.exec!("sudo sed -i -e 's/\\(KUBELET_EXTRA_ARGS=\\)\\(.*$\\)/\\1#{args} \\2/' #{kubelet}")
254239
ssh.exec!("sudo systemctl restart kubelet")
255240
puts("#{ip}: Configured Kubelet private network ip...done".colorize(:cyan))
256241
else
257242
puts("#{ip}: Configure Kubelet private network ip...skipped".colorize(:cyan))
258243
end
259244

260-
# # Configure flannel ip masquerade
261-
# flanneld = '/etc/default/flanneld'
262-
# if not ssh.exec!("cat #{flanneld}").include?("ip-masq")
263-
# ssh.exec!("echo 'FLANNELD_OPTS=--ip-masq=true' | sudo tee #{flanneld}")
264-
# puts("#{ip}: Configured flanneld defaults...done".colorize(:cyan))
265-
# else
266-
# puts("#{ip}: Configure flanneld defaults...skipped".colorize(:cyan))
267-
# end
268-
269245
# Configure kernel for Elasticsearch
270246
sysctl_conf = '/etc/sysctl.d/10-cyberlinux.conf'
271247
if not ssh.exec!("cat #{sysctl_conf}").include?('max_map_count')
@@ -316,41 +292,52 @@ class Kubinator
316292
# ==========================================================================
317293
# https://kubernetes.io/docs/getting-started-guides/kubeadm
318294
# https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/
295+
# https://kubernetes.io/docs/reference/setup-tools/kubeadm/kubeadm-init/#config-file
319296
# --------------------------------------------------------------------------
320297
join = nil
321298
if all or init
322299
Net::SSH.start(ips.first, @user, password:@pass, verify_host_key: :never){|ssh|
323300
if not ssh.exec!("docker ps").include?("apiserver")
324301
puts(":: Initialize master node '#{ips.first}'".colorize(:cyan))
325-
326-
# Initialize cluster via kubeadm
327-
# --------------------------------------------------------------------
328-
cmd = "sudo kubeadm init --kubernetes-version=v#{@k8sver} "
329-
330-
# Define api's location on our host-only network
331-
cmd += "--apiserver-advertise-address=#{ips.first} "
302+
ssh.exec!("mkdir -p ~/.config")
332303

333304
# Cluster cidr is required for flannel and some other pod networks.
305+
# https://github.com/coreos/flannel/blob/master/Documentation/kubernetes.md
334306
# It is the same cidr range that gets assigned to --cluster-cidr if you check with
335307
# 'kubectl cluster-info dump | grep cidr' and thus the same value that should be used for
336308
# the kube-proxy --cluster-cidr argument as well.
337309
cluster_cidr = "10.32.0.0/12" if weave
338310
cluster_cidr = "10.244.0.0/16" if flannel
339311

340-
# Note this is the default
341-
# Range of IPs to use for service VIPs
342-
# Must match range called out in kubelet --cluster-dns arg
343-
#cmd += "--service-cidr=10.96.0.0/16 "
344-
345-
# Flannel requires this to work
346-
# Range of IP addresses for the pod network
347-
# https://github.com/coreos/flannel/blob/master/Documentation/kubernetes.md
348-
cmd += " --pod-network-cidr=#{cluster_cidr}" if flannel
349-
312+
# Execute kubeadm with config template
313+
if config
314+
FileUtils.cp('templates/kubeadm.tpl', 'config/kubeadm.conf')
315+
FileUtils.resolve('config/kubeadm.conf', {
316+
advertise_address: ips.first,
317+
kubernetes_version: @k8sver,
318+
kube_proxy_mode: "iptables",
319+
cgroup_driver: "cgroupfs", # kubeadm default: cgroupfs
320+
cluster_domain: "cluster.local", # kubeadm default: cluster.local
321+
cluster_dns: "10.96.0.10", # kubeadm default: 10.96.0.10
322+
service_cidr: "10.96.0.0/12", # kubeadm default: 10.96.0.0/12
323+
cluster_cidr: cluster_cidr # cidr for pod networking
324+
})
325+
Net::SCP.upload!(ips.first, @user, 'config/kubeadm.conf', '.config/kubeadm.conf',
326+
ssh:{verify_host_key: :never, password: @pass})
327+
cmd = "sudo kubeadm init --config .config/kubeadm.conf"
328+
329+
# Execute without config
330+
else
331+
cmd = "sudo kubeadm init --kubernetes-version=v#{@k8sver} "
332+
cmd += "--apiserver-advertise-address=#{ips.first} "
333+
cmd += "--pod-network-cidr=#{cluster_cidr}"
334+
end
335+
336+
# Capture join for worker nodes
337+
# e.g. kubeadm join 192.168.56.10:6443 --token u6wor2.6kinrlvcbtxcoqo4 --discovery-token-ca-cert-hash
338+
# sha256:1112aafe50e27d54bccfd45d956f658a18b05e8b0ccf90c264ec17b026d01a8f
350339
ssh.exec!(cmd){|c,s,o|
351340
puts(o)
352-
# e.g. kubeadm join 192.168.56.10:6443 --token u6wor2.6kinrlvcbtxcoqo4 --discovery-token-ca-cert-hash
353-
# sha256:1112aafe50e27d54bccfd45d956f658a18b05e8b0ccf90c264ec17b026d01a8f
354341
join = o.split("\n").find{|x| x.include?("kubeadm join")}.strip if o.include?("kubeadm join")
355342
}
356343

@@ -399,9 +386,9 @@ class Kubinator
399386

400387
# If using iptables, SNAT all traffice sent via Service cluser IPs (not commonly needed)
401388
#mod_kube_proxy += " | jq '.spec.template.spec.containers[0].command |= .+ [\"--masquerade-all=false\"]'"
402-
set_kube_proxy = "#{get_kube_proxy} #{mod_kube_proxy} | kubectl apply -f -"
403389

404390
# Update kube-proxy deployment configuration and restart the service
391+
set_kube_proxy = "#{get_kube_proxy} #{mod_kube_proxy} | kubectl apply -f -"
405392
puts("exec: #{set_kube_proxy}")
406393
ssh.exec!(set_kube_proxy){|c,s,o|puts(o)}
407394
ssh.exec!("kubectl -n kube-system delete po -l 'k8s-app=kube-proxy'"){|c,s,o|puts(o)}
@@ -410,9 +397,20 @@ class Kubinator
410397
# CoreDNS will be in a pending state until pod networking is deployed
411398
# CoreDNS must be running before joining any worker nodes to the cluster
412399
# https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/#pod-network
400+
# validate results: kubectl -n kube-system get ds kube-flannel-ds -o json | '.spec.template.spec.containers[0].args'"
413401
puts("Installing pod networking".colorize(:cyan))
414402
podnet = "https://cloud.weave.works/k8s/net?k8s-version=#{@k8sver}" if weave
415-
podnet = "https://raw.githubusercontent.com/coreos/flannel/v0.10.0/Documentation/kube-flannel.yml" if flannel
403+
if flannel
404+
FileUtils.cp('templates/flannel.tpl', 'config/flannel.conf')
405+
FileUtils.resolve('config/flannel.conf', {
406+
iface: "enp0s8", # the interface to use for inter-host communication
407+
backend_type: "vxlan", # default: vxlan - backend type
408+
cluster_cidr: cluster_cidr # default: 10.244.0.0/16 - cidr for pod networking
409+
})
410+
Net::SCP.upload!(ips.first, @user, 'config/flannel.conf', '~/.config/flannel.conf',
411+
ssh:{verify_host_key: :never, password: @pass})
412+
podnet = ".config/flannel.yml"
413+
end
416414
ssh.exec!("#{proxy_export}; kubectl apply -f #{podnet}"){|c,s,o|puts(o)}
417415
podready!('coredns', ssh:ssh)
418416
end
@@ -600,6 +598,7 @@ if __FILE__ == $0
600598
Option.new(nil, 'Cluster command', required:true, type:Array, allowed:{
601599
all: 'Init cluster and deploy extras',
602600
init: 'Initialize the Kubernetes cluster',
601+
config: 'Use the kubeadm config template',
603602
weave: 'Use the weave pod network',
604603
flannel: 'Use the flannel pod network',
605604
dashboard: 'Deploy K8s dashboard to cluster',

0 commit comments

Comments
 (0)